//源文件 void UartGpioConfig() { RCC->AHB1ENR |= (1<<3); //使能GPIOD RCC->APB1ENR |= (1<<18); //使能USART3 RCC->APB2ENR |= //PD8 TXD GPIOD->MODER |= (2<<16); ...
//源文件 void UartGpioConfig() { RCC->AHB1ENR |= (1<<3); //使能GPIOD RCC->APB1ENR |= (1<<18); //使能USART3 RCC->APB2ENR |= //PD8 TXD GPIOD->MODER |= (2<<16); //復用模式 GPIOD->OSPEEDR |= (2<<16); //High speed GPIOD->AFR[1] |= (7<<0); //AF7 GPIOD->PUPDR |= (1<<8*2); //PD9 RXD GPIOD->MODER |= (2<<18); //復用模式 GPIOD->OSPEEDR |= (2<<18); //High speed GPIOD->AFR[0] |= (7<<4); //AF7 GPIOD->PUPDR |= (1<<9*2); } void UartCoreConfig(uint32_t bound) { USART3->BRR |= (54*1000000+bound/2)/bound; USART3->CR1 = 0; USART3->CR1 |= 0<<28; //設置 M1=0 USART3->CR1 |= 0<<12; //設置 M0=0&M1=0,選擇 8 位字長 USART3->CR1 |= 0<<15; //設置 OVER8=0,16 倍過採樣 USART3->CR1 |= 1<<3; //串口發送使能 USART3->CR1 |= 1<<0; //串口使能 } void UartPhyConfig() { UartGpioConfig(); UartCoreConfig(UartBaud); } void UartPhySendByte(uint8_t byte) { USART3->TDR = byte; while((USART3->ISR &(1<<6)) == 0); } void UartPhySendString(uint8_t *str) { while(*str) { UartPhySendByte(*str); str++; } } //頭文件 /*****************************Uart*************************************/ #define UartBaud 115200 void UartPhyConfig(void); void UartPhySendByte(uint8_t byte); void UartPhySendString(uint8_t *str); /**********************************************************************/