cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with UART on STM32F303RE – Incorrect HEX Data Reception (F8F8 instead of Expected Characters)

FilipF303RE
Associate II

Hi everyone,

I'm working on UART communication with an STM32F303RE, and I'm experiencing an issue with data reception. I'm sending the character 'A', but I'm receiving incorrect values (F8F8 instead of 0x41).I tried changing the APB1 prescaler, but the received data remains incorrect. Its sets exactly, how the IOC in IDE cube shows the prescaler with frequency. I dont have osciloscope.

 

#include "stm32f303xe.h"
#include "stdint.h"
#include "stm32f3xx.h"
#include <stdio.h>
#define UART2_TIMER 500
#define LD4_ON GPIOA -> BSRR |= GPIO_BSRR_BS_5;
#define LD4_OF GPIOA -> BSRR |= GPIO_BSRR_BR_5;
volatile uint32_t Tick=0;

#include "stm32f303xe.h"
#include "stdint.h"
#include "stm32f3xx.h"
#include <stdio.h>
#define UART2_TIMER 500
volatile uint32_t Tick=0;




void config_UART(void)
{
	RCC -> AHBENR |= RCC_AHBENR_GPIOAEN;
	RCC -> CFGR |= RCC_CFGR_PPRE1_2;

	//PA2_TXAF7
	GPIOA -> MODER &= ~(GPIO_MODER_MODER2_0);
    GPIOA->MODER |= GPIO_MODER_MODER2_1;
    GPIOA->AFR[0] &= ~((0xF << GPIO_AFRL_AFRL2_Pos));
	GPIOA->AFR[0] |= (0x7 << GPIO_AFRL_AFRL2_Pos);

	//PA3_RXAF7
	GPIOA -> MODER &= ~(GPIO_MODER_MODER3_0);
	GPIOA->MODER |= GPIO_MODER_MODER3_1;
	GPIOA->AFR[0] &= ~((0xF << GPIO_AFRL_AFRL3_Pos));
	GPIOA->AFR[0] |= (0x7 << GPIO_AFRL_AFRL3_Pos);




	//GPIOA -> OTYPER |= GPIO_OTYPER_OT_3;
	//GPIOA->PUPDR |= GPIO_PUPDR_PUPDR3_0;
	RCC -> APB1ENR |= RCC_APB1ENR_USART2EN;

	//RCC -> CFGR |= RCC_CFGR_PPRE1_2;

	USART2->BRR = 36000000/115200;

	USART2-> CR1 |= USART_CR1_UE | USART_CR1_TE | USART_CR1_RE;

}
void UART2_Config(void);
uint32_t GetSystemTick(void);
uint32_t Timer_UART2;
void SysTick_Handler(void);
int main(void)
{
	SysTick_Config((72000000/ 1000));
	config_UART();

	//UART2 transmit

	//Timer_UART2 = GetSystemTick();
	//1s = 72 000 000
	// 0,001 = x
    /* Loop forever */


	while (1)
{


		if ((GetSystemTick() - Timer_UART2) > 500)
		{
						USART2->TDR = 'A';
						while (!(USART2->ISR & USART_ISR_TXE)) { } // Czekaj na opróżnienie bufora
							while (!(USART2->ISR & USART_ISR_TC)) { }  // Czekaj na zakończenie transmisji
						//	Timer_UART2 = GetSystemTick();
				                // Czekanie
		}


}
uint32_t GetSystemTick()
{
	return Tick;
}
void SysTick_Handler(void)
{
	Tick++;
}
void Delay(uint32_t Delay_ms)
{
	uint32_t StartTime = Tick;
	while(Tick < (StartTime + Delay_ms))
	{

	}
}

 

 

2 REPLIES 2
Imen.D
ST Employee

Hello @FilipF303RE ,

This could be related to a known limitation where data corruption can occur due to a noisy receive line.

This limitation is described as follows:

ImenD_0-1738957189591.png

As mentioned in the limitation description, the issue happens when the glitch to zero has a duration less than a half bit duration and arrives during the second half of the stop bit.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Where's the code bringing up the HSE and PLL? Is this based on the SPL code? Is the configuration in SystemInit() ?

 

>>I don't have oscilloscope.

If you have a terminal application, and USB-to-CMOS Serial type adapter, you could check with the F303 starting off it's 8 MHz HSI, rather than the PLL

Is this a NUCLEO board?

Perhaps output 'U' characters continuously, and check different baud rates?

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