cancel
Showing results for 
Search instead for 
Did you mean: 

STM8 USART one time receive only two bytes

David.Cheng
Associate II

0690X00000AQsoMQAT.png

INTERRUPT_HANDLER(USART1_RX_TIM5_CC_IRQHandler,28)
{
    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
    
    //uint8_t temp = USART1->SR;
    
    
    if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == SET)
    {
        
        uint8_t temp = USART_ReceiveData8(USART1);
        if(pos < 20)
        {
            //pos = 0;
            RX_buf[pos] = temp;
            pos++;
        }
    
    
    }
    
    
    
    
    //USART_ClearITPendingBit(USART1, USART_IT_RXNE);
    
    
}
void usart_setup(void)
{
    GPIO_ExternalPullUpConfig(GPIOC, GPIO_Pin_3, ENABLE);
    GPIO_ExternalPullUpConfig(GPIOC, GPIO_Pin_2, ENABLE);
 
    CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
    USART_DeInit(USART1);
    USART_Init(USART1, (uint32_t)9600, USART_WordLength_8b, USART_StopBits_1,
                   USART_Parity_No, (USART_Mode_TypeDef)(USART_Mode_Tx | USART_Mode_Rx));
                   
                   
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
    USART_Cmd(USART1, ENABLE);
 
}

i dont know why one time only receive two bytes

2 REPLIES 2
Cristian Gyorgy
Senior III

Hello Cheng!

I personally don't understand much from your post.

If you search some help, try to post something so that we can understand your problem.

Good luck!

a rx to common interrupt effect me