2011-12-18 07:29 AM
UART2 RX TX initialization-how to use?
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. [code]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 } [/code]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) :
[code]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 } [/code]BR,
KonradP.S. If somebody wants to see whole code let me know :)
2011-12-18 04:11 PM
This isn't an STM8 forum.
Consider if the GPS is using 9600 8N1, a lot use 4800 8N1 Consider sending data in a loop, GPS sentences are often 80-100 characters in length, so you forward more than one character. In embedded you typically don't want to exit the main() subroutine.2011-12-19 02:46 PM
Yes I know but I've had no answers on STM8 so I tried here. Thanks for answer, Stm8 are using 9600, I have it from examples. I'll try to send more data and let you know.
2011-12-21 11:04 AM
GPS is not connected now, i'm trying to send data in loop -> from PD5(UART2 Tx pin) to PD6
(UART2 Rx pin), trap is set in ''
LCD5110_write_char(gp);
'' line and i see that 'gp' variable is empty...
void UART2_Init(); void UART2_Cmd(); void GPIO_Init(); void UART2_SendData8(u8 Data); u8 UART2_ReceiveData8(void); void main(void) { char gp; char i; u8 Data='k'; LCD5110_init(); LCD5110_set_XY(1,1); UART2_Init( (u32)9600, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO, UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE); UART2_Cmd(ENABLE); GPIO_Init(GPIOD, GPIO_PIN_5, GPIO_MODE_OUT_PP_HIGH_FAST ); GPIO_Init(GPIOD, GPIO_PIN_6, GPIO_MODE_IN_FL_NO_IT ); UART2_SendData8(Data); UART2_ReceiveData8(); gp = UART2_ReceiveData8(); LCD5110_write_char(gp); }2011-12-21 11:38 AM
Aren't you supposed to wait for the status to indicate a character is ready before reading it from the data register.
Receive: while(UART2_GetFlagStatus(UART2_FLAG_RXNE) == RESET); data = UART2_ReceiveData8(); Transmit: UART2_SendData8(byte); while(UART2_GetFlagStatus(UART2_FLAG_TXE) == RESET); BTW ST I really hate this stupid Word(tm) editor2011-12-21 12:10 PM
I don't get it, where should I put those functions in this code?
2011-12-21 12:15 PM
AAAAA! I love you man! :) thanks :) It seems to be working now. Ok i will try to do some more things ... just to be sure
void UART2_Init(); void UART2_Cmd(); void GPIO_Init(); void UART2_SendData8(u8 Data); u8 UART2_ReceiveData8(void); void main(void) { int gp; u8 data; u8 byte=66; LCD5110_init(); //inicjalizacja LCD LCD5110_set_XY(1,1); //ustawienie R i C UART2_Init( (u32)9600, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO, UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE); //Inicjalizacja UART2 UART2_Cmd(ENABLE); // Warunek konieczny do send i recieve GPIO_Init(GPIOD, GPIO_PIN_5, GPIO_MODE_OUT_PP_HIGH_FAST );// przypisanie pinow GPIO_Init(GPIOD, GPIO_PIN_6, GPIO_MODE_IN_FL_NO_IT ); //UART2_SendData8(data); UART2_SendData8(byte); while(UART2_GetFlagStatus(UART2_FLAG_TXE) == RESET); //UART2_ReceiveData8(); while(UART2_GetFlagStatus(UART2_FLAG_RXNE) == RESET); data = UART2_ReceiveData8(); gp = UART2_ReceiveData8(); LCD5110_LCD_write_byte(gp, 1); }