初级会员

- 积分
- 83
- 金钱
- 83
- 注册时间
- 2012-3-18
- 在线时间
- 0 小时
|
我以9600的波特率循环发送 40 23 00 00 00 到STM32的USART上。结果却接收到 23 00 40 23 00 40 23 00 40 23这样的序列。
中断函数里的处理。
void USART2_IRQHandler(void)
{
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
serial_buf[serial_count] = (u8)USART2->DR;
serial_count++;
if(serial_count == SERIAL_LEN)
{
serial_count = 0;
flag = 1;
}
//溢出-如果发生溢出需要先读SR,再读DR寄存器 则可清除不断入中断的问题
if(USART_GetFlagStatus(USART2,USART_FLAG_ORE)==SET)
{
USART_ClearFlag(USART2,USART_FLAG_ORE); //读 SR
USART_ReceiveData(USART2); //读 DR
}
}
usart配置:
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
可见,相应地,USART我也设置为9600。
实在不知道是什么问题,求指导。
thanks~~ |
|