typedef struct { __IO uint32_t SR; /*!< USART 状态寄存器, Address offset: 0x00 */ __IO uint32_t DR; /*!< USART 数据寄存器, Address offset: 0x04 */ __IO uint32_t BRR; /*!< USART 波特率寄存器, Address offset: 0x08 */ __IO uint32_t CR1; /*!< USART 控制寄存器 1, Address offset: 0x0C */ __IO uint32_t CR2; /*!< USART 控制寄存器 2, Address offset: 0x10 */ __IO uint32_t CR3; /*!< USART 控制寄存器 3, Address offset: 0x14 */ __IO uint32_t GTPR; /*!< USART 分频寄存器, Address offset: 0x18 */ } USART_TypeDef; UART->SR[7]: TXE 发送数据寄存器为空时置1,写DR时清零 UART->SR[5]: RXNE 读取数据寄存器为非空时置1,读DR时清零 UART->DR: 读写都是这个寄存器,低8位有效 uart写buf: while (length--) { while (!(UART->SR == 1 << 7)) { ; } UART->DR = *data++; } uart读buf: while (length--) { while (!(UART->SR == 1 << 5)) { ; /* 注意死循环 */ } *data++ = UART->DR; }