I am trying to do UART communication between atmega128 and arduino UNO. Both are running at 9600 baud rate( checked both by doing serial communication with laptop using xbee radios from zigbee),but i am not receiving data properly. The data is following some pattern but i am not able to understand the relation.The lower four bits are always correct but upper four bits follow some weird pattern.
should receive---------actual received
1------------------------9
2------------------------A or 8
3------------------------B or 9
4------------------------8 or A
5------------------------9 or B
my atmega128 and arduino code are as follow: arduino sends one value and atmega128 displays the recieved value on array of 8leds on PORTA.
yes ground is common, 33 is decimal value... for 31 it gives 8E, 32 ---8F, 33 ---91 for 1 it gives 81, 2--- 82, 25 ---99, 26--9A, code is same have just changed value in serial.write.
yes ground is common, 33 is decimal value... for 31 it gives 8E, 32 ---8F, 33 ---91 for 1 it gives 81, 2--- 82, 25 ---99, 26--9A, code is same have just changed value in serial.write.
So, the lower four bits are not always correct.. You seem to have the MSB always 1 at the receiving end.. that makes me suspect a baudrate mismatch.
.. although the first two pairs you listed tells otherwise.
yes the problem is with baud rate only as in case sending 33 in a loop it gives 81 sometimes and 91 sometimes.
I have checked default fuse bit settings for arduino**broken link removed**. so it is set for 16mhz external crystal only.
For 128 i have used the fuse bits as: lfuse:FF, hfuse:99 (settings for 16mhz external crystal)
for register settings of 128 i have posted my code above.
What else i should be checking to make my baud rate correct?
Can you check the data with an oscilloscope? That should get those problems sovled in about ten minutes.
Also as misterT asked, how are the two micros physically connected? How long is the wire?
Could you do one test.. send these 8 messages from the arduino to the atmega128 and post what is received. And do it many times in a loop with a delay between transmissions... I do not like the fact that you are sending one message after reset and then nothing. Make a loop that sends the same character over and over again, with 200 ms delay between sends.
hey.. my code is working now....
i tried my code with internal clock of atmega128 and it is working fine, it means the problem was with my extrnal crystal.. do crystals start work slowly after some time.. i ran a code for led blinking in 10s using _delay_ms function in loop and measured the time using stop watch it was coming more than 11s...was my external crystal the actual problem ??...i cannot just accept the idea of crystal running slow after sometime....
hey.. my code is working now....
i tried my code with internal clock of atmega128 and it is working fine, it means the problem was with my extrnal crystal.. do crystals start work slowly after some time.. i ran a code for led blinking in 10s using _delay_ms function in loop and measured the time using stop watch it was coming more than 11s...was my external crystal the actual problem ??...i cannot just accept the idea of crystal running slow after sometime....
Possible, if you don't have the correct load caps connected to it, and/or it's been abused (eg. dropped, frozen, burned, twisted, shanked, pounded, beaten, stuffed, licked, kicked, verbally rebuked, etc)
my fuse bit settings for external crystal were lfuse:FF, hfuse:99 , calculated from here and cross checked... i can draw the exact ckt diagram as i am using a development board bought online(here) and crystal arrangement is below the small PCB of atmega.
You didn't happen to notice that the ATMega128 board is using a 14.7456 Mhz crystal did ya?
And your code is set up for a 16Mhz oscillator frequency...