[原创] f769uart寄存器版本

star_66666   2016-12-10 00:06 楼主
书接上回的寄存器配置io口的输出,今天开始寄存器版本的uart配置。 首先看datasheet2.25关于usart的说明 page42 The USART peripheral supports: • Full-duplex asynchronous communications • Configurable oversampling method by 16 or 8 to give flexibility between speed and clock tolerance • Dual clock domain allowing convenient baud rate programming independent from the PCLK reprogramming • A common programmable transmit and receive baud rate of up to 27 Mbit/s when the USART clock source is system clock frequency (max is 216 MHz) and oversampling by 8 is used. • Auto baud rate detection • Programmable data word length (7 or 8 or 9 bits) word length • Programmable data order with MSB-first or LSB-first shifting • Progarmmable parity (odd, even, no parity) • Configurable stop bits (1 or 1.5 or 2 stop bits) • Synchronous mode and clock output for synchronous communications • Single-wire half-duplex communications • Separate signal polarity control for transmission and reception • Swappable Tx/Rx pin configuration • Hardware flow control for modem and RS-485 transceiver • Multiprocessor communications • LIN master synchronous break send capability and LIN slave break detection capability • IrDA SIR encoder decoder supporting 3/16 bit duration for normal mode • Smartcard mode ( T=0 and T=1 asynchronous protocols for Smartcards as defined in the ISO/IEC 7816-3 standard ) • Support for Modbus communication 目前几乎所有的uart应用都不涉及flow控制,所以本次评测也不做这方面的工作。 从原理图可知,discovery的板子上最容易配置的是usart6,于是我们就配置usart6的功能。 捕获.PNG 有图可知,占用PC6,PC7这2个IO口。 首先要设置IO的功能。 RCC->AHB1ENR |= 0x04; GPIOC->AFR[0] = 0; GPIOC->AFR[0] = 0x88000000; GPIOC->MODER &= ~((3 << 6) | (3 << 7)); GPIOC->MODER |= (2 << 6) | (2 << 7); GPIOC->OSPEEDR &= ~((3 << 6) | (3 << 7)); GPIOC->OSPEEDR |= (3 << 6) | (3 << 7); GPIOC->OTYPER = ~((1 << 6) | (1 << 7)); GPIOC->PUPDR &= ~((3 << 6) | (3 << 7)); GPIOC->PUPDR |= (1 << 6) | (1 << 7); 然后开始配置uart的功能 RCC->APB2ENR |= 0x20; //reset usart6 RCC->APB2RSTR |= (RCC_APB2RSTR_USART6RST); RCC->APB2RSTR &= ~(RCC_APB2RSTR_USART6RST); USART6->CR1 &= ~USART_CR1_UE;//Disable UART USART6->CR1 = 0x0U; USART6->CR2 = 0x0U; USART6->CR3 = 0x0U; USART6->CR1 |= (0 << 28) | (0 << 12); USART6->BRR=0x3aa; //115200 USART6->CR1 |= 0x0d << 0; 增加一个发送函数 void usart6_send(uint8_t data) { USART6->TDR=data; while((USART6->ISR&0X40)==0);//等待发送结束 } 点击此处,查看STM32F769I开发板官方资源。 本帖最后由 star_66666 于 2016-12-11 23:51 编辑

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复