Issue with UART on STM32F303RE – Incorrect HEX Data Reception (F8F8 instead of Expected Characters)
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))
{
}
}
