cancel
Showing results for 
Search instead for 
Did you mean: 

UART Framing Error on STM32F1

tonyblake9
Associate II
Posted on May 19, 2017 at 14:32

Hi,

I have an STM32F1 and am running the UART printf example from the standard peripheral library. I've modified the code to allow me to use USART3 (I'm using a custom pcba and only USART3 is wired to a connector mounted on the board). I've connected USART3 to a serial terminal on my computer (RealTerm) using an FTDI USB-UART converter. I am successfully receiving data from the UART but the data is incorrect and the terminal complains of a framing error. I am transmitting a single character 'T' but am receiving unknown data:

0690X00000603aRQAQ.jpg

I am convinced that there is a problem in my code, most likely in how I have configured USART3, but am not sure where. I have checked that my baud rate etc is good in both the code, cable and terminal.

Can anyone help me with this? What is the most likely reason I am not receiving the correct data?

Cheers,

Tony

#stm32-f1 #framing-error #usart
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on May 22, 2017 at 14:18

USART3 is not on APB2

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

View solution in original post

4 REPLIES 4
Posted on May 19, 2017 at 20:13

Baud rate wrong (bad assumption about clock sources and speeds)

Wrong levels. Device outputs CMOS level, not RS232 level, which are higher and inverted.

Use 2-stop bits, creates a larger inter-symbol gap, if synchronization is an issue.

Try outputting a stream of 'U' characters and measuring bit timing on a scope.

Make sure to test for TXE before outputting to data register.

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, 2017 at 14:12

Hi Clive,

As I said, I'm convinced that the problem in my code. Can you see anything wrong here:

void USART3_Config(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

NVIC_InitTypeDef NVIC_InitStructure;

USART_InitTypeDef USART_InitStruct;

// 1) Clock Config

RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

// 2) GPIO Config

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10; // USART3 TX

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOB, &GPIO_InitStruct);

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11; // USART3 RX

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOB, &GPIO_InitStruct);

// 3) NVIC Config

NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

// 4) USART Struct Config

USART_InitStruct.USART_BaudRate = 115200;

USART_InitStruct.USART_StopBits = USART_StopBits_1;

USART_InitStruct.USART_WordLength = USART_WordLength_8b;

USART_InitStruct.USART_Parity = USART_Parity_No;

USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_Init(USART3, &USART_InitStruct);

USART_Cmd(USART3, ENABLE);

}
Posted on May 22, 2017 at 14:18

USART3 is not on APB2

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, 2017 at 15:29

Yep that was the problem, should have been on APB1.

Thank you!