cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152 USART_FLAG_RXNE not being set

paulcowper
Associate II
Posted on July 24, 2012 at 17:32

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 STM 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 #uart-usart-stm32l
6 REPLIES 6
Posted on July 24, 2012 at 17:49

I'd front load the TXE check, if you want to wait for the last bit to leave then use TC.

PA3 (USART2 RX) is not 5V tolerant. Expecting ~3V CMOS serial signalling, not RS232 voltages. Otherwise nothing is immediately jumping out as odd.

while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, 0x55);//Tell screen to Auto Baud
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
SCREEN_DataRecvd(USART_ReceiveData(USART2)); //DEBUG - Process data received, Possibly send error to radio
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, 0x45);//Tell screen to clear
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
SCREEN_DataRecvd(USART_ReceiveData(USART2)); //DEBUG - Process data received, Possibly send error to radio

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
microeval
Associate II
Posted on June 21, 2013 at 13:53

Hi clive1,

I have STM32L152VB(medium density board 128KB flash, 16KB ram), is there any example code for the STM32L152VB USART?. I tried IAR workbench example, but it didn't work.

STM32L:

https://www.olimex.com/Products/ARM/ST/STM32-P152/

 . I want to redirect the debug prints to serial terminal.

Thanks,

Ram.
Posted on June 21, 2013 at 14:35

For Keil the retargeting is relatively straight forward, others I think you just have to replace putchar(), would check your tool documentation.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32L15x%20UART%20Configuration%20and%20use%20problem&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
microeval
Associate II
Posted on June 24, 2013 at 08:32

Hi Clive1,

Thanks for your reply.

This link is configured UART for the STM32L152-EVAL board, but my board is STM32L152( olimex STM32L-P152) development board. This board has exposes USART2(GPIOD pins) and that example is not suitable for this board. I tried this example by changing of  RTS, CTS pins to STM32L development board, but still nothing is displaying on the serial terminal.

Thanks,

Ram.

Posted on June 24, 2013 at 14:48

Can you not adapt the pin assignments? Or do I have to go look them up?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 24, 2013 at 18:34

A blind build

// sourcer32@gmail.com - STM32L15x USART2 (PD5 Tx, PD6 Rx) Demo 9600 8N1
#include ''stm32l1xx.h''
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Assumes CMSIS and SystemInit() set up clocks before calling main() */
/* Enable GPIO D clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);
/* Enable USART2 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* Configure USART Tx & Rx as alternate function */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Configure USART CTS & RTS as alternate function */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Mux out USART2 Tx, Rx, CTS and RTS */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2); // PD5 USART2_TX
GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2); // PD6 USART2_RX
GPIO_PinAFConfig(GPIOD, GPIO_PinSource3, GPIO_AF_USART2); // PD3 USART2_CTS
GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_USART2); // PD4 USART2_RTS
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_Rx | USART_Mode_Tx;
/* USART configuration */
USART_Init(USART2, &USART_InitStructure);
/* Enable USART */
USART_Cmd(USART2, ENABLE);
while(1)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); /* Wait while TX full */
USART_SendData(USART2, 0x55);
}
return(1);
}

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