AnsweredAssumed Answered

STM32L151R usart rx trouble

Question asked by shubin.vitaly on Jul 31, 2015
Latest reply on Jul 31, 2015 by Clive One
Hello, everyone! I'm use usart to receive packets with different size. I'm use next code to do this. Also it's fine, but i going inside ISR twice. And it's trouble for me. Please, anyone get help me, that i'm doing wrong?

void usart3_config(void){
     GPIO_InitTypeDef gpio_init;
     USART_InitTypeDef usart_init;
     NVIC_InitTypeDef     NVIC_usart3;
     
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
     

     gpio_init.GPIO_Mode          =     GPIO_Mode_AF;
     gpio_init.GPIO_Pin          = GPIO_Pin_11;
     gpio_init.GPIO_PuPd          =     GPIO_PuPd_NOPULL;
     gpio_init.GPIO_Speed     =     GPIO_Speed_40MHz;
     //gpio_init.GPIO_OType     = GPIO_OType_PP;
     GPIO_Init( GPIOC, &gpio_init);
     
     gpio_init.GPIO_Mode          =     GPIO_Mode_AF;
     gpio_init.GPIO_Pin          = GPIO_Pin_10;
     gpio_init.GPIO_PuPd          =     GPIO_PuPd_UP;
     gpio_init.GPIO_Speed     =     GPIO_Speed_40MHz;
     gpio_init.GPIO_OType     = GPIO_OType_PP;
     GPIO_Init( GPIOC, &gpio_init);
     
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);
     


     usart_init.USART_BaudRate                    =     9600;
     usart_init.USART_HardwareFlowControl     =USART_HardwareFlowControl_None;
     usart_init.USART_Mode =     USART_Mode_Rx|USART_Mode_Tx;
     usart_init.USART_Parity=     USART_Parity_No;
     usart_init.USART_StopBits     =     USART_StopBits_1;
     usart_init.USART_WordLength     =     USART_WordLength_8b;
     USART_Init ( USART3, &usart_init);
     USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
     USART_Cmd(USART3, ENABLE);
     
     NVIC_usart3.NVIC_IRQChannel = USART3_IRQn;
     NVIC_usart3.NVIC_IRQChannelCmd = ENABLE;
     NVIC_usart3.NVIC_IRQChannelPreemptionPriority = 1;
     NVIC_usart3.NVIC_IRQChannelSubPriority = 1;
     NVIC_Init(&NVIC_usart3);
}

void getHC(void)
{
     uint16_t stop = 0, i = 0;
     uint16_t count = 0;

     while(!stop)
     {
          
          if(!CheckHCBuffer()){stop=1;     }
          else {if (count <= HCBUFFERSIZE) 
               HCBuffer[count]= USART_ReceiveData(USART3);
               count++;
          }
          //USART_ClearITPendingBit(USART3, USART_IT_RXNE);               
     }
}

}
char CheckHCBuffer(void)
{
long i=0,j=0;
     
     
     while(!USART_GetFlagStatus(USART3, USART_FLAG_RXNE)&&(i<1800))//
     {     
     i++;}
     return USART_GetFlagStatus(USART3, USART_FLAG_RXNE);
}

Outcomes