最近在调试一块板子,STM32和SIM模块通信
现象:当波特率设置为9600单片机收到32个字节后面的数据就会不正确,当设为19200可以收到64个字节
经过反复调试排除软件和硬件问题,查找到原因是SIM模块发送出来的波形比正常波特率空闲间隔小,正常是70-75us左右,而SIM模块的空闲间隔只有52us,这也就是说SIM模块的波特率偏高一点点,请问在这种情况下该如何微调单片机的波特率呢?
USART_InitStructure.USART_BaudRate = 19200;
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_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
USART_ClearFlag(USART1,USART_FLAG_TC);
|