void usart_int()
{
USART_DeInit(USART1);
USART_Init(USART1,(uint32_t)2400, USART_WordLength_8b, USART_StopBits_1,USART_Parity_No , USART_Mode_TXRX);
USART_ClockInit(USART1,USART_Clock_Disable,USART_CPOL_Low,USART_CPHA_2Edge,USART_LastBit_Disable);
USART_ITConfig(USART1, USART_IT_RXNE,ENABLE );
USART_Cmd(USART1,ENABLE);
} 这是串口初始化程序。
GPIO_Init(GPIOE,GPIO_Pin_2,GPIO_Mode_In_FL_No_IT);
GPIO_Init(GPIOE,GPIO_Pin_3,GPIO_Mode_Out_PP_Low_Fast);
CLK_PeripheralClockConfig(CLK_Peripheral_USART1,ENABLE);这是引脚初始化。及串口时钟。
INTERRUPT_HANDLER(USART1_RX_IRQHandler,28)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
if(USART_GetITStatus( USART1,USART_IT_RXNE )!= RESET)
{while(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET);
Buf=USART_ReceiveData8(USART1);
h++;
bu[h]= Buf;
}
这是接收程序。现在问题是 发送01的时候收到的数据是7f 发送02收到的7E。而且用板子向电脑发数收到的也是这样。 |