About usart in stm32?
I coded for usart communication in stm32f103r8.In this i'm getting the garbage value as output.
given below is my program,kindly help me to correct my program.
****
#include "stm32f10x.h"
#include "stm32f10x_usart.h"
void usartSetup (void);
int SendChar ();
int GetChar (void);
void main()
{
usartSetup();
SendChar();
GetChar();
}
void usartSetup (void) {
// make sure the relevant pins are appropriately set up.
RCC->APB2ENR |= 0x00000004; // enable clock for GPIOA
GPIOA->CRH |= (0x0BUL << 4); // Tx (PA9) alt. out push-pull
GPIOA->CRH |= (0x04UL << 8); // Rx (PA10) in floating
RCC->APB2ENR |= 0x00004000; // enable clock for USART1
USART1->BRR = 72000000L/9600L;/*115200L;*/ // set baudrate
USART1->CR1 |= 0x00000008 | 0x00000004; // TX enable,Rx enable
USART1->CR1 |= 0x00002000; // USART enable
}
int SendChar () {
while (!(USART1->SR & 0x00000080));
USART1->DR = 1;
}
int GetChar (void) {
while (!(USART1->SR & 0x00000020));
return ((int)(USART1->DR));
}
