I downloaded AT89C51ED2 UART source code from ATMEL web. when I connected from PC COM1 to AT89C51ED2 and sended a byte data, it sended a wrong byte data back. Have some solutions about this @@?
I use C51 UART Mode1 Timer1 (24 KB, updated 06/04) 9600bps what are the SFRs (SCON, TCON, TMOD, TH1, TL1, IE set to) Erik
hi erik the same with the source code. SCON = 0x50; /* uart in mode 1 (8 bit), REN=1 */ TMOD = TMOD | 0x20 ; /* Timer 1 in mode 2 */ TH1 = 0xFD; /* 9600 Bds at 11.059MHz */ TL1 = 0xFD; /* 9600 Bds at 11.059MHz */ ES = 1; /* Enable serial interrupt */ EA = 1; /* Enable global interrupt */ TR1 = 1; /* Timer 1 run */ I didn't modify it. Regard, Yuhung
PCON? what are you using in the other end
PCON? It is not setting in source code. Should I set it a value? the other end.... I use PC COM1 with Windows hyperTerminal (C:\Program Files\Windows NT\hypertrm.exe) the setting is 9600 / 8 / N / 1 / N(flow control?) PS. I use the windowsXP which is Non-English version. so, I am not sure it is "flow control". Regasrd.
I am try to send data with Hyper Ternimal 9600/8/n/1/n Send->"abcdefghijklmnopqrestuvwxyz" Receive->"yz{|}~hijklmnoxyz}{|}~xyz"
"I am try to send data with Hyper Ternimal 9600/8/n/1/n Send->"abcdefghijklmnopqrestuvwxyz" Receive->"yz{|}~hijklmnoxyz}{|}~xyz"z"" Looks like your baudrate is slightly out. Are you using a 12MHz crystal? The reload value in the code you are using is for an 11.0592MHz crystal. There is a baudrate calculator on this website that will let you calculate the correct values. Alternatively, why don't you use the internal baudrate generator on the ED2?
hi Stefan Duncanson I'm using 11.0592MHz crystal. and ATMEL's web have following codes. 1.C51 UART Mode1 Internal Baud Rate Generator (23 KB, updated 06/04) 2.C51 UART Mode1 Timer1 (24 KB, updated 06/04) 3.C51 UART Mode1 Timer2 (22 KB, updated 06/04) they can't send data back correctly. >_< I tried it, but cant work.
here has some talk about this question. http://www.grote.net/bascom/frm22321.html but im not sure how to make it success in hyper terminal.
"I'm using 11.0592MHz crystal" Maybe hyperterminal is your problem - try using a different terminal emulator such as TeraTerm. "they can't send data back correctly." Do you get the same result with all three programs? Are you typing the characters one by one into hyperterminal, and if not, what happens if you do?
i download TeraTerm and test it. the 3 examples are same result. send=>"1234567890" receive=>"9:;<=>?898" PS. using 115200 in "3.C51 UART Mode1 Timer2" software setting it that send a byte one by one. (HyperTerminal and TeraTerm) I dont know where the problem is.....>_< PC COM1<-->HIN232<-->AT89C51ED2 Source code => from ATMEL
I use C51 UART Mode1 Timer1 (24 KB, updated 06/04) 9600bps later PS. using 115200 in "3.C51 UART Mode1 Timer2" which is it? software setting it that send a byte one by one. thus you have changed something. if you are running 115k you need be careful that the processing is not too slow Erik
because the example (3.C51 UART Mode1 Timer2) says: RCAP2H=0xFF; /* reload value, 115200 Bds at 11.059MHz */ RCAP2L=0xFD; /* reload value, 115200 Bds at 11.059MHz */ so, i changed my baudrate in this case. but have the same result....>_<
1) show by cut and paste the exact code you use 2) are you sure your crystal is fundamental? 3) do you have (access to) a scope? erik
1) actually, i didnt modify source code that download from ATMEL's website. #include "reg_c51.h" char uart_data; void main (void) { SCON = 0x50; /* uart in mode 1 (8 bit), REN=1 */ TMOD = TMOD | 0x20 ; /* Timer 1 in mode 2 */ TH1 = 0xFD; /* 9600 Bds at 11.059MHz */ TL1 = 0xFD; /* 9600 Bds at 11.059MHz */ ES = 1; /* Enable serial interrupt */ EA = 1; /* Enable global interrupt */ TR1 = 1; /* Timer 1 run */ while(1); /* endless */ } void serial_IT(void) interrupt 4 { if (RI == 1) { /* if reception occur */ RI = 0; /* clear reception flag for next reception */ uart_data = SBUF; /* Read receive data */ SBUF = uart_data; /* Send back same data on uart*/ } else TI = 0; /* if emission occur */ /* clear emission flag for next emission*/ } 2) there are a 11.0592MHz mark on the crystal. I can programming with ISP in this development kit board. So, I think the crystal is fine. 3) scope? you mean the oscilloscope figure? if this is, i dont have one. (i have no money to buy one...sorry) Regard.
hmm.... is 11.059MHz same with 11.0592MHz?
"is 11.059MHz same with 11.0592MHz?" The reload value shown is correct for 11.0592MHz. Are you absolutaly certain you aren't using a 12MHz crystal?