STM32F7xx外设驱动5-uart(寄存器)
//源文件 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); /**********************************************************************/