2011-12-14 01:47 PM
Hello, I have problem with initialization UART2 in my project(STM8S105). Below you can see part of my code, what am i doing wrong?
I'm trying to send sign to LCD display. ...void UART2_Cmd(FunctionalState ENABLE);
void UART2_InitGPS() { UART2_DeInit(); UART2_Init( (u32)9600, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO, UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE); } void UART2_SendData8(u8 Data); u8 UART2_ReceiveData8(void); void main(void) { char tmp; LCD5110_init();//function which initialize LCD
LCD5110_set_XY(0,0);//function which set rows and columns in LCD
UART2_SendData8(36); UART2_ReceiveData8(); tmp = UART2_ReceiveData8(); LCD5110_write_char(tmp); //function which send characters to LCD }I have to mention that i have no errors after compiling code and if I use function like this everything works fine(but I need UART to racive data from GPS and send it to LCD) :
void main(void)
{ char tmp=33; //33 -> ''!'' sign in my matrix(table or haw to name it) LCD5110_init();//function which initialize LCD
LCD5110_set_XY(0,0);//function which set rows and columns in LCD
LCD5110_write_char(tmp); //function which send characters to LCD }BR,
KonradP.S. If somebody wants to see whole code let me know :)
2012-04-08 10:11 AM
When you are using UART*_ReceiveData() functions you should probably wait until UART2_FLAG_RXNE flag is set by using UART*_GetFlagStatus(). A better method than doing that would be to use the UART interrupt UART2_IT_RXNE_OR and push the data to the screen whenever the interrupt triggers, that way you're main code isn't stuck in a loop wasting cpu time.