Hi everybody!!!
I'm new and i need some help!!!
Nice to meet you!!!
I'm trying to connect my Aduc836 (8051 architecture) with a 4d systems display by Serial TTL.
What i want to do for this moment it's simply send a char by the display and turn on one led on my boards.... the problem I have is that I can not read properly the character sending by the display.
Below the code on my MCU:
#include <reg52.h> sbit P3_4 = P3^4; sbit P3_5 = P3^5; bit flag = 0; idata unsigned char rx; void UART_intialization(void) { SCON = 0x50; // 8 bit, variable baud rate + REN = 1; TMOD &= ~0xF0; // timer1 bit set to 0 TMOD |= 0x20; // timer 1, autoreload TL1 = 252; // baud rate 9600 TH1 = 252; ES = 1; // interrupt serial enable EA = 1; // all interrupt souce enabled; TR1 = 1; // start timer1 } void int_Serial(void) interrupt 4 { if(RI != 0 ) { RI = 0; rx = SBUF; flag = 1; } } void main(void) { UART_initialization(); while(1) { if( flag ) { if( rx == 'a' ) P3_4 = 0; // if i read the correct value ( i send by display the char 'a') // i turn on one led else P3_5 = 0; // else if the value that i read it's wrong i turn on another led } flag = 0; } }
the code send by the display it's a simple instruction serout('a') , that works correctly.
Any advice?
Hi Erik!!!
I solved yesterday!!
The problem was due to the baud rate that was different by 9600..... i set in the wrong way the TH1 register with the timer1.......the timer1 works to 9600 baud always with 12.58 MHz frequency clock and not to 1.57 MHz.......for this reason i change the baud rate source and i use the timer2 in autoreload mode with 1.57 MHz and the problem was solved.
1) did you understand the SBUF issue 2) make a device output a stream of 'U' (0x55) anda scope will show a square wave with a frequency of 1/2 the baudrete
Erik
Thank you Erik, but i know the bible!
I think that i have a baudrate problem between the two devices
I have read the content of SBUF.... i have always the 0xFF value........no matter what i send.....but the SBUF content it's 0xFF that is OK
bible time, read about SBUF here and read the rest too
www.danlhenry.com/.../80C51_FAM_ARCH_1.pdf www.danlhenry.com/.../80C51_FAM_HARDWARE_1.pdf www.danlhenry.com/.../80C51_FAM_PROG_GUIDE_1.pdf
If i try to use the serial debug of uvision, i have with XTAL = 12.58 MHz and TH1 = 0xFD a baud rate of 58132 and not 9600.....how it's possibile?
Advice?
Don't assume that the contents of SBUF should care about what you send. SBUF is two registers sharing the same address. One write-only register for sending. And one read-only register for receiving. What you send by writing to the write-only SBUF register will not affect the read-only SBUF register.
The above behavior is common for quite a lot of devices and isn't specific to 8051 or to UARTs.
I have read the content of SBUF.... i have always the 0xFF value........no matter what i send.....but the SBUF content it's 0xFF
View all questions in Keil forum