I was trying to use USART to communicate between 2 Atmega32 Microcontrollers, But i'm facing some problems like whenever i use 16 mhz crystal it shows excessive CPU usage, and when i use lower internal clock it slow down the transmitting speed . Apart from this i was sending data to another microcontroller and receiving it using timers like every some millisecond but it creates some problem like "UDR read without transmitting" and My main loop function of 2nd microcontroller aint working it stucks at some point. I am so confused whats happening. I just want to know if there is any way possible like whenever i press button data transmits and received without delay and without disturbing main loop cycle.

Setting up comm's between two micros can be tricky if using unproven comm's functions, you don't know if the problem is not correctly sending or not correctly receiving.

So, separate the two and work on proving one, then the other. How? Use known good h/w + s/w, i.e. your PC, use a terminal program (hyperterm, teraterm, putty or others) and a USB to serial TTL (TTL is important, not rs232) and connect it to one micros usart TX/RX pins (note: PC TX connects to micro RX, micro TX connects to PC rx)

and then begin testing your putchar() function by sending a "U" char over and over again. If you can see this on your PC, then the baud rate init is working correctly.

Then test the getchar() function by doing the reverse sending "U" from the PC to the micro.

Once that is working, you now have a base of working h/w + s/w to begin working on the second micro, duplicate the same tests on it.

Good luck with your project, and for more help, post your code using the "<>" icon above.

It looks like you wrote the code before you designed the system. I seem to recall suggesting you use the timer CTC mode rather than interrupting on overflow and reloading the timer. You would do this on an 8051 cpu because there was no other choice. The AVR has a better and simpler solution -CTC mode.
Why would you wait for a rx character in an isr? The usual solution would be to use a rx interrupt - that's why they put it there. Your reading of the button is effectively useless. The usual method is to have debounce code in the isr.
Did you read the manual on the delay functions? They say something about the delay value being constant. You broke that rule.
I can't make much sense of of the code - there's few comments and i can't understand what you were trying to achieve. Design the system first then write the code.

first thing is i m not in school second thing i m doing this for my own . there is no school , no office, no college kind of thing involved. and last but not the least i really wanna do something in it thats y i am working on it but not wasting my time.

Hello friends i did try using CTC mode but due to less information and examples i am unable to understand that without using any particular pin like OCP1 and OC1A ....i want to use any pin as input (as i have numbers of pin as an input. ) But in CTC mode i onlu understand that whenever interrupts occur on these pin OCP1 and OC1A/B it will genrate interrupt but i want if i press button on any pin like PORTA=1<<PINA1 then interrupt occur and receive data by another microcontroller.

May I ask why you decide to use CTC for your button?
Your proteus schematics showed you use buttons, traffic leds and LCD. Have you succeded to integrate all that task but having trouble with the buttons or you don't know what you're doing at all?
.
When someone try to help you he should know how far you understand about the problem you're facing.
Please tell us your progress so far. Messing with code you found on the net won't suddenly solve your problem.
If you want to learn then learn it in the right way.
.
MG

hey friends i acheived what i wanted. Now i want to explain you what i've got and how it works.....i will make attach an document here and show you with schemtic diagram what did i acheive please let me know if i can improve more on that.

You've not told us how you want the system to operate. You seem to think we can read your mind and know exactly what you want. Once we understand how you want the system to operate, then we can begin to assist with the code. At the moment, your code is defective and looks like you wrote it before considering what you want the system to do.

1. Describe the system - you have pushbuttons and lights. What do they do? How do they operate? Draw a state diagram how you want the traffic lights to work. At this stage, do not think about implementation- ie coding. All you should describe is buttons,lights and sequences.

2. decompose the problem - what are the major operations you need to perform? Button debouncing, outputs to lights, timing etc.

3. abstraction - view the system as boxes. what do these boxes do and how do they interact? For each of your traffic lights - what do you want them to do? red,amber,green,flash? all off? Then you might have a box the controls the logic - this has inputs and outputs. define these and describe the operations.

Just to note that you may not be the first person in the world (with access to the internet) who has wanted to simulate a four way junction with traffic lights (and presumably "user present" buttons?) so you can probably google and find 10+ working solutions for this stuff to compare against.

Just to note that you may not be the first person in the world (with access to the internet) who has wanted to simulate a four way junction with traffic lights (and presumably "user present" buttons?) ...

I've lost track a bit here in the thread. The original question(s) were USART and timers -- how to work with AVR peripheral subsystems.

Later in the thread, it seems to be more of the application. In this case, traffic control.

Over 40 years ago, traffic signal control was always [ ;) at least IME] used for learning state machines. If the more formal class, "Automata Theory". It is a good exercise as the student can relate to the application. And we didn't have any new-fangled "vehicle present" sensors back then, so I suppose it was easier. ;)

Another typical/classic is passenger elevator operation.

I don't know how a post here, even extensive, can outline the content of a semester course in automata theory. There are different ways of laying out the states, and formal and informal methods for optimization.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

It seems he is trying to wire together 5 micros to operate these lights. Each set being operated by a separate micro and then they all "talk" on some kind of "network" (which may be MPCM) to let each other know what they are doing or be commanded what to do.

The skill of engineering is surely to analyse and simplify the thing whereas this seems to be a case of over-engineering to see just how complex I can make something that is actually trivially easy.

Try to put some common sense. let me help you, if you saw that diagram you understand that there are 8 traffic signals which means i am doing that for 2 four way crossings i.e. 4 for 1 crossing.

4 traffic signals controlling 1 crossing and 4 for another crossing. 4 traffic signals controlled by 1 microcontroller which means I have the only option to control them is using 5 microcontrollers for 5 crossings.

And its really important for me to communicate with every microcontroller or you can say crossing to know the traffic status to control according to the current condition.

I don't think you act right, they just tried to help you and look what you said to them...

I am so pissed, i need their help thats why i am here. I am so new with this stuff , may be i am not familiar with those technical terms and my communication skills are not that good but i am trying my best to explain them atleast try to understand my problem.

the OP is a total noob in electronics and is self learning, so the internet is most likely the only source of education here.

He has found a freeware version of protheus somewhere that he is using for self education.

to the OP....

your schematic was copy past form 1 'block of lights+lcd' to the second. keep that in mind while writing the FW you want.

I personally think you have bit way more of than you can chew. So you need to take a massive step back and start with the basics.

That is not fun and will not give you a "show off" project in the short term, but you are already frustrated, and if you continue in this direction that will only grow and most likely beyond what you can handle to keep going.

start with the basics......

get 1 led to be on / off and flashing in the speed you want it to.

then extend that to a full trafic light, make that do what you want it to do ( get a flashing pattern on it for instance)

that will give you IO knowledge and can help you in getting timer knowledge.

Note that the LEDs can be used as debug source also once you got them going.

Then you might choose to get the LCD up and running to show some stuff there for indication

Then perhaps start doing a traffic situation were no buttons are required. So a Dump crossing, were there is a certian time a direction can drive.

Then make it smart by adding the buttons.

and last but not least start worring about how to have 2 intersections communicate with eachother.

Yep, when dealing with this stuff, you need to ve a little crazy. I'm quite sure most of us fully understand how traffic lights work, but it seems like you struggle as you've not adequately explained how you want your system to work. If we were standing next to you, we would get a pencil and paper to sketch out the operation then decompose and abstract the problem. Then we'd start with some code. We's start with one micro and get that working first before tackling multiple processors. Whilst the task appears simple, you're having trouble solving it, so that suggests it might not be as simple as it seems. The human brain has trouble solving multiple problems at once, so we need to divide the problem. That's why we have a design phase. Even with experience you go through a design phase even though it may not be on paper.

4. then i tried to do these things together. light blinks, lcd display while button press, with button number(i.e. which button is pressed if 1st button pressed then counta++,if 2nd button pressed countb++) .

5. then i tried controlling 4 traffic signals at once and implemented it with above progress.

6. then i used timers so i can receive button inputs in every ms so there is no interrupt in traffic signal cycle.

7.then i tried using uart to communicate between 2 micros.

8. after that i used it in above progress.

9. then my whole system works as i expected.

10. but now i want 5 micros to communicate but unfortunately something unexpected happens.(5th micro is communicating with 4 micros (i.e. transmiting and receiving) but 4 micros can't transmit data to that 5th micro but they are receiving ......so you can say i almost acheived what i want, except this thing. just a single step behind my goal.

just watch this video and please reply....i made this video to show you how it works.

thanks

Please don't get me wrong but seriously i need your help.....thats why i m troubling you ....i kindly apologise if any inconvinience caused by me.....and kartman i really didn't meant to spam you in private i don't know the rules of here...i was just trying to communicate with someone who can help.

...now i want 5 micros to communicate but unfortunately something unexpected happens.(5th micro is communicating with 4 micros (i.e. transmiting and receiving) but 4 micros can't transmit data to that 5th micro but they are receiving...

Have we seen how you are connecting your 5 micros together?

"This forum helps those that help themselves."

"If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

The point with forums is that it is an open discussion where anyone interested can join the talk, and future readers can learn from the past experience of others,

Asking for one-on-one help via mail or similar will only make you come through as wanting special attention (or just looking spoiled). If you want that kind of help then then find someone who does that for a monetary return (i.e. you pay for it).

What's wrong with the forums?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here.

No guarantees, but if we don't report problems they won't get much of a chance to be fixed! Details/discussions at link given just above.

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here.

No guarantees, but if we don't report problems they won't get much of a chance to be fixed! Details/discussions at link given just above.

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]