cancel
Showing results for 
Search instead for 
Did you mean: 

UART Transmitting problem

sanctified
Associate II

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.😊

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);
 
}

4 REPLIES 4
mwalt.3
Associate II

Hi,

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

sanctified
Associate II

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?

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.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
sanctified
Associate II

Solved it. It was the stupid watchdog timer😂