cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L151R usart rx trouble

shubinvitaly
Associate
Posted on July 31, 2015 at 08:40

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

}

#isr #usart #stm32l
1 REPLY 1
Posted on July 31, 2015 at 17:30

What ISR? It would help if the specific thing you ask about is actually provided.

The point of the ISR would be to take a byte at a time for the USART. Sitting in loops and unnecessarily delaying for multiple bytes is NOT the way to do this.

Other USART IRQ examples have been posted to the forum, and are within the peripheral library examples for the L1 parts.

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