cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F100 RXNE Problem

modus
Associate
Posted on October 01, 2011 at 18:45

Hi everyone!

I have some problem with USART interrupt while receiving. RXNE bit clearing automatically by entering the interrupt without any actions, therefore software cannot detect character received event. I use STM32VL Discovery board, pins PB11 and PA9 is interconnected.

// USART RXNE TEST

#include ''stm32f10x.h''

vu8  n;

u16 *ptr;

u16 Buf[100];

void USART3_IRQHandler (void)

{

if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)

{

  *ptr++ = USART_ReceiveData (USART3); // Never get here!!!

}

}

void usart1_out (u16 data)

{

while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET) {;}

USART_SendData(USART1, (u16)data);

}

int main(void)

{

USART_InitTypeDef      USART_InitStructure;

NVIC_InitTypeDef        NVIC_InitStructure;

ErrorStatus            HSEStartUpStatus;

GPIO_InitTypeDef      GPIO_InitStructure;

u8 i;

n=1;

ptr=&Buf[0];

RCC_DeInit();

RCC_HCLKConfig(RCC_SYSCLK_Div1);

RCC_PCLK2Config(RCC_HCLK_Div1);

RCC_PCLK1Config(RCC_HCLK_Div1)

RCC_HSEConfig(RCC_HSE_ON);

HSEStartUpStatus = RCC_WaitForHSEStartUp()

if (HSEStartUpStatus == SUCCESS)

{

  RCC_PREDIV1Config(RCC_PREDIV1_Source_HSE, RCC_PREDIV1_Div1);/* PLLCLK = (8MHz_ext/1) * 3 = 24 MHz */

  RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_3);            

}else{while(1){;}}

RCC_PLLCmd(ENABLE);

while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {;}

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

while (RCC_GetSYSCLKSource() != 0x08) {;}

NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

GPIO_DeInit (GPIOA);

GPIO_DeInit (GPIOB);

RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA, ENABLE);

RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB, ENABLE);

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;

GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;                   /* Tx */

GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_11;               /* Rx */

GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOB, &GPIO_InitStructure);

RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1, ENABLE);          /* Configuring USART */

RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART3, ENABLE);

USART_InitStructure.USART_BaudRate = 9600;               

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Tx;

USART_Init(USART1, &USART_InitStructure);

USART_Cmd(USART1, ENABLE);

USART_InitStructure.USART_Mode = USART_Mode_Rx;

USART_Init(USART3, &USART_InitStructure);

USART_Cmd(USART3, ENABLE);

USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);

while(1)

{

  for (i=0; i<255; i++)

  {

   while (n==0){;}

   n=0;

   usart1_out (i);

  }

}

}

This code doesn`t work on two different STM32VL discovery boards.
0 REPLIES 0