cancel
Showing results for 
Search instead for 
Did you mean: 

Help with STM32F051 USART2

klcoleman2304
Associate
Posted on May 22, 2014 at 03:48

STM32F051 Discovery USART2 problem

I wanted to know if someone can help me with a problem I am having with the STM32F051 USART.

I’m using the STM32F0DISCOVERY kit and have added a few additional LED’s for testing which are working.  However, I am trying to send a character to the terminal using USART2 in the while loop in main.c which is not working.  The USART initialization is done in a separate file stm32f0_discovery.c.  These are the same files provided by Atollic which I have modified.  I am also using the Adafruit USB to UART cable to connect directly to the USART pins on the discovery board, and TeraTerm for terminal emulation.  I only have tx and rx wires hooked to the board since it is powered from the computers USB port.  There are two issues that I cannot resolve.

First, in TeraTerm I am not seeing the character I am sending.  Instead, I am seeing what appears to be ASCII code 152 (a lower case letter y with two dots on top).

Second, I sometimes get the following message in the TrueStudio debug window “Target is not responding, retrying...'' in which case I see no characters sent to the terminal.

I’ve attached the two source files above to this post.

Thanks...
5 REPLIES 5
Posted on May 22, 2014 at 04:02

while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // <<< NEED A SEMI-COLON HERE TO LOOP WAITING
USART_SendData(USART2, 'x');

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
klcoleman2304
Associate
Posted on May 22, 2014 at 06:37

Clive,

Thank you for the quick response to my inquiry. I’ve added the missing semicolon; however, I am still seeing ASCII code 152 on the terminal. I do however believe I found the source of the target not responding. I initiated another debug session from within the TrueStudio C/C++ perspective without terminating the current running one. This appears to have corrupted the project causing the problem. When I create a new project and copy the source files into it the problem goes away.

I suspect there is a BAUD rate problem causing the character problem so I am going through the other source files to try to figure it out. Also, I believe there was a mistake in line 205 of stm32f0_discovery.c

The USART_InitStructure.USART_BaudRate = 192000; should be 19200 although changing it made no difference. I’ve uploaded the system_stm32f0xx.c file which sets up the configuration registers for selecting the clocks in case you have time to review it.

Thanks again

________________

Attachments :

system_stm32f0xx.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hzeh&d=%2Fa%2F0X0000000bS5%2F3hSl7mbdlTKRpjt3DYYa7smyyWAmuK3gfyyc5.YtIJw&asPdf=false
frankmeyer9
Associate II
Posted on May 22, 2014 at 11:04

You might have stumbled over the notorious HSE_VALUE problem.

The header stm32f0xx.h conditionally defines this value, which describes the external clock source frequency (i.e. quartz). This value might be not correct for your board.

To cite the header file (a few lines above this definition):

   Tip: To avoid modifying this file each time you need to use different HSE, you

 

        can define the HSE value in your toolchain compiler preprocessor.

 

But generally, it is good to have a scope at hand, and check the actual baudrate and events on the bus.

Posted on May 22, 2014 at 15:38

I suspect there is a BAUD rate problem causing the character problem so I am going through the other source files to try to figure it out. Also, I believe there was a mistake in line 205 of stm32f0_discovery.c

The USART_InitStructure.USART_BaudRate = 192000; should be 19200 although changing it made no difference. I’ve uploaded the system_stm32f0xx.c file which sets up the

Or that the code had 9600 baud, and the discovery file has been heavily modified.

/* USART2 PA.2 Tx, PA.3 Rx STM32F0-Discovery sourcer32@gmail.com */
#include ''stm32f0xx.h''
#include ''stm32f0_discovery.h''
int main(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
/* Configure USART2 pins: Rx and Tx ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
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_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2,ENABLE);
while(1)
{
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, 'X');
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 22, 2014 at 15:43

PA14 will break the debug interface, which is using it as SWCLK!!

/* USART2 PA.14 Tx, PA.15 Rx STM32F0-Discovery sourcer32@gmail.com */
/* !! Using PA.14 SWCLK will break the debugger SWD interface !! Use BOOT0 = High to recover */
#include ''stm32f0xx.h''
int main(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource14, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource15, GPIO_AF_1);
/* Configure USART2 pins: Rx and Tx ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
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_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2,ENABLE);
while(1)
{
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, 'X');
}
}

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