AnsweredAssumed Answered

STM32L152 USART_FLAG_RXNE not being set

Question asked by PaulLeicester on Jul 24, 2012
Latest reply on Jun 24, 2013 by Clive One
Hey all,

Got a small problem when interfacing with a UART based oLED display.
The display returns 0x06 or 0x15 after it has received a command, I can see this happening on my O-Scope and I have confirmed this with a Bus Pirate on a separate circuit. How ever the USART_FLAG_RXNE is not being set.

This could well be me doing something not plainly obvious, I am pretty new to the STM32.

Below is some code and I am wondering if anyone would be able to push me in the right direction?

void INIT_Screen (void)
{
    USART_InitTypeDef USART_InitStructure2;
    GPIO_InitTypeDef   GPIO_InitStructure2;
 
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 , ENABLE);
 
    GPIO_InitStructure2.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure2.GPIO_Speed = GPIO_Speed_40MHz;
    GPIO_InitStructure2.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure2.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStructure2.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
    GPIO_Init(GPIOA, &GPIO_InitStructure2);
 
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);
 
    USART_InitStructure2.USART_BaudRate = 9600;//115200;
    USART_InitStructure2.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure2.USART_StopBits = USART_StopBits_1;
    USART_InitStructure2.USART_Parity = USART_Parity_No;
    USART_InitStructure2.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure2.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    USART_Init(USART2, &USART_InitStructure2);
 
    USART_Cmd(USART2, ENABLE);
 
     
    USART_SendData(USART2, 0x55);//Tell screen to Auto Baud
    while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
    while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
    SCREEN_DataRecvd(USART_ReceiveData(USART2)); //DEBUG - Process data received, Possibly send error to radio
     
    USART_SendData(USART2, 0x45);//Tell screen to clear
    while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
    while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
    SCREEN_DataRecvd(USART_ReceiveData(USART2)); //DEBUG - Process data received, Possibly send error to radio
}


The main thing I would like to know, Have I done everything in order to allow the RXNE register to be set and am I checking its status in the correct way? Is there anything else I should be aware of.

Many Thanks

Paul

Outcomes