cancel
Showing results for 
Search instead for 
Did you mean: 

USART synchronization issue when transmitting a bitmap – incorrect byte reception

FilipF303RE
Associate III

I'm trying to transmit a bitmap via USART. The bitmap transmits correctly in HAL. My project is register-based, written from scratch. The issue is that my USART has a speed synchronization problem—meaning:

  • When my C# terminal is set to 57600 BAUD, it reads one byte correctly, but an additional zero byte is received and written to the buffer index.

  • At equal speeds (115200 BAUD) for both the MCU and the terminal, it incorrectly reads the bitmap byte, and still receives an extra empty byte in the buffer.

I can't figure out what's wrong. I suspect it might be a misconfigured clock system. My board is Nucleo-F303RE (STM32F3xE). I’d appreciate your help!

void USART2_EXTI26_IRQHandler (void)
{

	if(USART2->ISR & USART_ISR_RXNE)
	{
		dl_znak[ind++] = USART2->RDR;
		memcpy(dl_znak+ind,temp,1);
		if(++ind >=20) ind=0;
		//USART2->RQR |= USART_RQR_RXFRQ;
		if (USART2->ISR & USART_ISR_ORE)
		{
		    USART2->ICR |= USART_ICR_ORECF;
		}
		if (USART2->ISR & USART_ISR_FE)
		{
			USART2->ICR |= USART_ICR_FECF;
		}
		if (USART2->ISR & USART_ISR_NE)
				{
					USART2->ICR |= USART_ICR_NCF;
				}
	}

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


	//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;
	USART2-> CR1 |=  USART_CR1_RXNEIE;

	NVIC_SetPriority(USART2_IRQn, 0);
	NVIC_EnableIRQ(USART2_IRQn);

}

uint8_t data;
uint8_t dl_znak [20];
uint8_t temp[2];

 

10 REPLIES 10
FilipF303RE
Associate III

@TDK Yes, You are right. Everythings work corretly when I change for 18 Mhz. I was just corious becasue IOC shows me in clock configuration that I have 36Mhz, but when I left not divided prescaler or divided by 2 I still have to set it for 18Mhz... It have pushed me to that I might had something wrong in my code ...

Clockconfig.png