Right Now I am working with the STM32F103C8 blue pill board, I am working with UART protocol here I am able to send data to putty it's working but send data from putty to microcontroller (unable to receive data from the putty). what is the problem I can't understand everything is okay but I can't receive data?
Code:
#include "stm32f10x.h" // Device header
volatile char data;
int main(void){
//configure HSI SYSTEM clock .
RCC->CR = RCC_CR_HSION;
RCC->CFGR = RCC_CFGR_SW_HSI;
//Enable Alternate function clock, PORTA and USART1.
RCC->APB2ENR = RCC_APB2ENR_AFIOEN|RCC_APB2ENR_USART1EN|RCC_APB2ENR_IOPAEN;
//Alternate function mode PA9
GPIOA->CRH = GPIO_CRH_MODE9_1|GPIO_CRH_CNF9_1;
//ALternate function mode PA10.
GPIOA->CRH |= GPIO_CRH_MODE10_1|GPIO_CRH_CNF10_1;
//USART1 Enable.
USART1->CR1 = USART_CR1_UE;
//8-bit word length.
USART1->CR1 |= ~(USART_CR1_M);
//baudrate 8MHz,9600 baudrate.
USART1->BRR = 0x341;
//Enable TE,RE bits
USART1->CR1 |= USART_CR1_RE|USART_CR1_TE;
while(1){
//wait for receive data
while((USART1->SR &USART_SR_RXNE )==0){}
data = USART1->DR;
while((USART1->SR & USART_SR_TXE)== 0){}
USART1->DR = data;
while((USART1->SR &USART_SR_TC) == 0){}
}
this code receives data from the PC and sends data to the PC.
question from:
https://stackoverflow.com/questions/66061575/stm32f103c8-not-receiving-uart-data-from-pc 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…