STM32微控制器参考手册 2009年2月 英文版
P613页
校验位说明:
Table 155. Frame formats
M bit PCE bit USART frame
0 0 | SB | 8 bit data | STB |
0 1 | SB | 7-bit data | PB | STB |
1 0 | SB | 9-bit data | STB |
1 1 | SB | 8-bit data PB | STB
配置方式:STM32标准库 V3.01
#ifdef USART1_ON
//允许USART1的时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
USART_InitStructure.USART_BaudRate = BAUD1;
USART_InitStructure.USART_WordLength = USART_WordLength_9b; //此处在有奇偶校验时需要9个数据位,无奇偶校验时8个数据位
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_Even;//偶校验
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1,&USART_InitStructure);
/* 允许USART1 DMA */
#ifdef USART1_DMA_ON
USART_DMACmd(USART1,USART_DMAReq_Rx | USART_DMAReq_Tx, ENABLE);
#endif
/*允许USART1 */
USART_Cmd(USART1,ENABLE);
#endif
用户422754 2015-7-28 14:38