2018-05-28 05:31 AM
Hi, am using STM32F103C8T6, I wrote code with keil for uart1 for the tx pin PA9 and rx
pin PA10, am just sending a character repeatedly, but I didn't receive the character what I am sending, I am using CP2102 device between my controller and my PC. I will show my code, and my output , so kindly suggest me the solution.
#include <stm32f10x.h>
void SendChar (unsigned char ch);
static __IO uint32_t TimingDelay;
void Delay_Us(uint32_t nTime);
void Delay_Ms(uint32_t ms);
void SysTick_Handler(void);
void DelayInit(void);
void main()
{ int i=0; SystemInit(); DelayInit(); RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; GPIOA->CRH = (0x0AUL << 4); GPIOA->CRH |= (0x04UL << 8); RCC->APB2ENR |= RCC_APB2ENR_USART1EN; USART1->BRR = 8000000L/9600L; USART1->CR1 |= (USART_CR1_RE | USART_CR1_TE); USART1->CR1 |= USART_CR1_UE; while(1) { SendChar('A'); Delay_Ms(250); }}
void SendChar (unsigned char ch) {
while (!(USART1->SR & USART_SR_TXE)); USART1->DR = ch ;}void Delay_Us(uint32_t nTime){
TimingDelay = nTime; while(TimingDelay != 0); }void Delay_Ms(uint32_t ms)
{ while (ms--) { Delay_Us(1000); }}void SysTick_Handler(void){
if (TimingDelay != 0x00) TimingDelay --;}
void DelayInit(void)
{ // Update SystemCoreClock value SystemCoreClockUpdate(); // Configure the SysTick timer to overflow every 1 us SysTick_Config(SystemCoreClock / 1000000);OUTPUT:
}2018-05-28 05:40 AM
// Configure the SysTick timer to overflow every 1 us
SysTick_Config(SystemCoreClock / 1000000);Honestly ?
Think about the implications.
Especially in the light of this:
USART1->BRR = 8000000L/9600L;
Are you sure ?
2018-05-28 05:52 AM
Is APB2 running at 8 MHz? Check what is happening in SystemInit()
Output a 'U' character continuously, and scope the USART1_TX pin and confirm the bit timing.
Use a debugger and inspect the RCC, GPIO and USART register settings