STM32串口使用偶校驗(yàn)時初始化
USART 1 配置
如果需要使用奇數(shù)校驗(yàn)或者偶數(shù)校驗(yàn),需要把數(shù)據(jù)長度定位9bit
*/
USART_InitStructure.USART_BaudRate = COM1BAUD;
USART_InitStructure.USART_WordLength =USART_WordLength_9b;
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;
STM_EVAL_COMInit(COM1, &USART_InitStructure);
/*使能USART1的接收中斷*/
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
看了數(shù)據(jù)手冊,還是不太明白為啥要把數(shù)據(jù)長度定位9,
難道 奇偶校驗(yàn)位也是數(shù)據(jù)的一部分,無就是 0 +8 = 8,
而有校驗(yàn)就是1+8 = 9
或許只能這樣理解了。
評論