Data corruption on UART - reg
#include <stdint.h>
#include <stdio.h>
#include "bspapi.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "stm32f4xx.h"
TaskHandle_t Task3Handle = NULL;
static char key = 'Q';
extern int state = 0;
xQueueSetHandle xQueue;
void init_UsartConfiguration( void )
{
/* BRR = Systemclock / ((Over2 - 0) * Baudrate)
BRR in Decimal fraction is 0d546.875 == 0x222 (0d546 <--> 0x222) & (0.875*16 == 14) (0d14 <--> 0xE)
Thus BRR --> 0x222E*/
//USART1->BRR = 0x222E;
USART1-> BRR = SystemCoreClock/9600;
USART1->CR1 &= ~USART_CR1_OVER8; // Oversampling mode = 16
USART1->CR1 &= ~USART_CR1_M; // Word length = 8 bits
USART1->CR1 &= ~USART_CR1_PCE; // No parity
USART1->CR1 |= USART_CR1_TE; // Transmitter enable
USART1->CR1 |= USART_CR1_RE; // Receiver enable
USART1->CR1 |= USART_CR1_UE; // USART enable
USART1->CR1 |= USART_CR1_RXNEIE;
//USART1->CR1 |= USART_CR1_TXEIE;
USART1->CR2 &= ~(1<<12|1<<13); // STOP[1:0] = 00 thus one stop bits
USART1 -> SR = 0;
}
void init_gpioClock()
{
//Setting up RCC Register
RCC -> AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
RCC ->APB2ENR |= RCC_APB2ENR_USART1EN; //PA9 Serial_1 TX & PA10 Serial_1 RX
GPIOA->MODER |= GPIO_MODER_MODER5_0;
GPIOA->OSPEEDR = GPIO_OSPEEDER_OSPEEDR5_0;
GPIOA->OTYPER = ((GPIO_OTYPER_OT_5) & (~GPIO_OTYPER_OT_5));
GPIOA->PUPDR = GPIO_PUPDR_PUPDR5_0;
/* GPIO Configurations for PA9 and PA10 which is the pins for USART1 */
GPIOA ->MODER |= GPIO_MODER_MODER9_1| GPIO_MODER_MODER10_1;// PA9 Serial_1 TX //1<<19;
GPIOA ->OTYPER|= 512;//;// 1<<9
GPIOA ->OSPEEDR |= 512;//GPIO_OSPEEDER_OSPEEDR9_0; // 1<<9
GPIOA ->PUPDR |= GPIO_PUPDR_PUPDR9_0 ; //1<<19
GPIOA->AFR[1] |= 0x0770; // PA0 AFR value is AF07 so AFR[1] = 0x0770
}
char __uartSend()
{
char value = 'k';
while(1)
{
USART1->DR = value & 0xFF;
}
return 0;
}
int main(void)
{
/* Configure the system clock */
SystemInit();
SystemCoreClockUpdate();
init_gpioClock();
init_UsartConfiguration();
//xTimerCreate( "AutoReload",1000 ,pdTRUE, 0,prvTimerCallback );
xQueue = xQueueCreate( 5, sizeof(uint8_t) );
xTaskCreate(__uartSend, "send", 200, (void*)0, tskIDLE_PRIORITY, &Task3Handle);
vTaskStartScheduler();
return 0;
}Hii,
I am new to freeRTOS and STM controllers. I am working on Nucleo-64 (STM32F411-re) development board. I was trying to send data through Uart. I was watching the data for correctness in Serial window. I've sent 'K' but in window I am recieving '0xf0' .
