Hi, I tried communication between two uC. Steps are 1) uC1 sends a request (1 byte) to uC2. 2) On receiving this byte, uC2 sends three bytes of data to uC1. 3) uC1 waits for completion of the data reception and stores the data in an array.
All the three steps works ( I am able to display the received bytes correctly using LEDs) But the problem is I need to add about 1sec delay before every time request is sent from uC1.
(I set a flag to low before sending the request, this flag (global bit) is set to one by the UART ISR when 3 bytes are received. After sending the request, the main program waits for this bit to become high, and then proceeds.Without the additional delay, this bit does not seem to change.)
Is there anything wrong in my method? Why this delay becomes necessary?
Now the counting of received bytes works. I also provided a time out of 1 second. It is noticed that sometimes it has to time out. Does it mean that counting of bytes do not work always? If so, what could be the reason?
You could have a transfer problem.
Or you could have a problem with your delay.
How do you implement your delay? If the delay is handled by a timer with one-second granularity, then that delay can result in a zero delay if you call the delay function just before the timer ticks. So have you made sure that your design guarantees a minimum delay time of 1000ms?
It could mean that either the counting doesn't work, or bytes are being lost - or, possibly, both!
"If so, what could be the reason?"
It's your system and your code - so you need to debug it to find the reason!
Nobody else has your code or your system - so nobody else can do this for you!
Here are some debugging tips for you:
www.8052.com/.../120313
www.techonlineindia.com/.../Developing_a_good_bedside_manner.aspx
And of course - your code could fail to react to the ISR fast enough, resulting in a character being lost.
Thank you.