2016-07-14 05:09 AM
Hi I am prashant. I am using stm8s microcontroller with uart2 . First thing is that when i am using uart explicitly without configure the clock to 16Mhz ( HSI clock), uart throwing the garbage values. Secondly when i configure the clock to HSI(16Mhz) , program gets blocked to wait for the TXE bit (UART2_FLAG_TXE) to set forever. It happens only when i configure the system clock to HSI otherwise throw the garbage value.
I am posting my code below.&sharpinclude ''stm8s_uart2.h''&sharpinclude ''stm8s_clk.h''void clk_config(){ //CLK_DeInit(); //CLK_HSICmd(ENABLE); CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);}void uart_config(){ UART2_DeInit(); UART2_Init(9600, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO, UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE); UART2_Cmd(ENABLE);}int main( void ){ //clk_config(); uart_config(); while(1) { UART2_SendData8('P'); //sending some garbage value rather character 'P' when HSI clock isn't configured. while(UART2_GetFlagStatus(UART2_FLAG_TXE) == RESET); //program remains blocked here if i uncomment the clock_config() } return 0;} #hsi #stm8s #uart #stm8