2012-07-24 08:32 AM
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
2012-07-24 08:49 AM
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
2013-06-21 04:53 AM
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: . I want to redirect the debug prints to serial terminal.Thanks,Ram.2013-06-21 05:35 AM
For Keil the retargeting is relatively straight forward, others I think you just have to replace putchar(), would check your tool documentation.
2013-06-23 11:32 PM
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.2013-06-24 05:48 AM
Can you not adapt the pin assignments? Or do I have to go look them up?
2013-06-24 09:34 AM
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);
}