Skip to main content
Visitor II
September 6, 2018
Question

UART Transmitting problem

  • September 6, 2018
  • 4 replies
  • 1233 views

Hello,

I am using the stm8l151... mcu and I am trying to send different strings via Uart1 to HTerminal. I have three different strings to send. The first two strings are transmitted completely but when the third one is being sent, it is truncated and it starts to send the first and second string again and repeatedly.

I have attached the output from Hterm (uart_com) for better understanding and also some parts of my code(uart transmit and uart_init)

Just for better understanding of the attached output, the strings(cmd 1, 2 and 3) are at+nrb, at+cfun=1, and at+cops=1,2,"26201"

Please Any suggestions will be greatly appreciated.:smiling_face_with_smiling_eyes:

void nbiot_buf_transmit(void){
 PAL_UART1_RX_DISABLE();
 PAL_UART1_TX_ENABLE();
 
 for(int i=0 ; i < sizeof(cmd1);i++){
 
 
 USART_SendData8(USART1,((uint8_t)cmd1[i]));
 while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
 
 }
 
 
 for(int i=0 ; i < sizeof(cmd2);i++){
 
 
 USART_SendData8(USART1,((uint8_t)cmd2[i]));
 while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
 
 }
 
 
 for(int i=0 ; i < sizeof(cmd3);i++){
 
 
 USART_SendData8(USART1,((uint8_t)cmd3[i]));
 while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
 
 }
 
}
void uart_init(void){
 /* init Tx and Rx Pins */
 GPIO_Init(GPIOC, GPIO_Pin_3, GPIO_Mode_Out_PP_High_Fast); //tx pin output
 GPIO_Init(GPIOC, GPIO_Pin_2, GPIO_Mode_In_FL_No_IT); //rx pin input
 /* enable usart1 clk */
 PAL_SWITCH_USART1_CLK_ON();
 /* config for GPIO mode */
 PAL_SWITCH_COMP_CLK_ON();
 PAL_UART1_CONFIG_RI();
 PAL_UART1_SET_RI_GPIO();
 PAL_SWITCH_COMP_CLK_OFF();
 /* init usart peripheral */
 USART_Init(USART1,
 (PAL_dwCLK_FREQ_VALUE/9600),
 USART_WordLength_8b,
 USART_StopBits_1,
 USART_Parity_No,
 USART_Mode_Rx); //Tx enable
 ITC->ISPR8 &= 0xFC; // Set USART1_RX_IRQn on ITC_PriorityLevel_2
 ITC->ISPR7 &= 0x3F; // Set USART1_TX_IRQn on ITC_PriorityLevel_2
 /* configure usart interrupts */
 //enable transmit interrupt
//USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
 //USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
 /* enable usart1 peripheral */
 USART_Cmd(USART1,ENABLE);
 
}

    This topic has been closed for replies.

    4 replies

    Explorer II
    September 17, 2018

    Hi,

    did you try ti check the TC bit instead of the TX bit ?

    Visitor II
    September 18, 2018

    Thanks for your reply.

    Yes i did. Still the same.

    Am still on it and no solution:tired_face:

    Any other suggestions and Please do you know another forum where i can ask such questions?

    Graduate II
    September 23, 2018

    Stack Exchange?

    Perhaps you have local support groups or others with familiarity with STM8 parts.

    You might have to break out a debugger/scope to understand what's happening. I think some of the libraries have working examples, start with those.

    I'd probably front test TXE.

    If you have repetitive code consider using subroutines, and remember strlen() doesn't count the NUL whereas sizeof() does.

    Visitor II
    October 1, 2018

    Solved it. It was the stupid watchdog timer:face_with_tears_of_joy: