Skip to main content
Visitor II
August 2, 2016
Question

STM8S UART Receive problem

  • August 2, 2016
  • 2 replies
  • 1948 views
Posted on August 02, 2016 at 13:24

I have a weird condition in which the STM8S003 does not read the entire packet I'm sending using a PC serial port. For example I have sent 256 bytes using a PC software but at the end I have only read 214 bytes instead of 256 bytes in the controller. (RX ISR happened 214 times instead of 256 times)

What could be possibly wrong? It's said a read to the Data Register is enough to clear the flags.

I'm going crazy here because it's not supposed to be this hard getting a simple RX interrupt to work. 

#stm8s-uart
    This topic has been closed for replies.

    2 replies

    Visitor II
    November 17, 2018

    I wonder if you were able to solve this problem? I'm currently having the same issue with a stm8s207

    Visitor II
    May 10, 2019

    HI!

    I do it!

    //////////////////////////////////////////////////////////////////////////////////////

    #include "stm8s.h"

    #include "stm8s_uart1.h"

    #include "stm8s_clk.h"

    uint8_t RxBuffer1[5];

    __IO uint8_t RxCounter1 = 0x00;

    static void UART_Config(void);

    void main(void)

    {

     /* CLK configuration -----------------------------------------*/

     CLK_Config();

    static void UART_Config(void)

    {

     // Deinitializes the UART1 peripheral //

      UART1_DeInit();

      /* UART1 configuration -------------------------------------------------*/

      /* UART1 configured as follow:

         - BaudRate = 9600 baud  

         - Word Length = 8 Bits

         - One Stop Bit

         - No parity

         - Receive and transmit enabled

         - UART1 Clock disabled

       */

       

      /* Configure the UART1 */  

      UART1_Init((uint32_t)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO,

            UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_RX_ENABLE);

       

      /* Enable UART1 Transmit interrupt*/

    //  UART1_ITConfig(UART1_IT_TXE, ENABLE);

       

      /* Enable UART1 Receive interrupt */

      UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);

      /* Enable general interrupts */

      enableInterrupts();  

    }

    INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18) 

    {

     /* Read one byte from the receive data register */

      

     uint8_t dados[1] = {0x00};

     dados[0] = UART1_ReceiveData8();

      

     if(RxCounter1 <= 3)

     {

      RxBuffer1[RxCounter1] = dados[0];

      IncrementVar_RxCounter1();

     }

     else

     {

        

      RxBuffer1[RxCounter1] = dados[0];

      RxCounter1 = 0;

     }

    uint8_t GetVar_RxCounter1(void)

    {

    return RxCounter1;

    }

    uint8_t IncrementVar_RxCounter1(void)

    {

    return RxCounter1++;

    }

    static void CLK_Config(void)

    {

      /* Initialization of the clock */

      /* Clock divider to HSI/1 */

      CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    }