不能正确接收数据(RDR里面能接收数据,但不正确),我PC端发送3,RDR显示是0x0FE,波特率都是115200啊;发送的时候,TDR里能够显示正确的发送数据,但是IO口那收不到任何数据,IO口配置应该没什么问题啊,要不然怎么能够对PC端发送的数据有反映呢,请大家帮忙,谢谢了! void tiaoshi(void) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStruct; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_6 | GPIO_Pin_7); //USART2对应的RX,TX引脚 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //复用模式 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽输出 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); //配置复用功能 GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_7); GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_7); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); USART_InitStructure.USART_BaudRate = 115200; 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_DeInit(USART1); USART_Init(USART1, &USART_InitStructure); //USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//使能中断 USART_ClearFlag (USART1,USART_FLAG_TC); USART_Cmd(USART1, ENABLE); //打开串口 while(1) { USART_SendData(USART1,4); // USART in mode Tramitter ------------------------------------------------ if (USART_GetITStatus(USART1, USART_IT_TXE) == SET) { USART_SendData(USART1, Receive); //Disable the USARTx transmit data register empty interrupt USART_ITConfig(USART1, USART_IT_TXE, DISABLE); } //* USART in mode Receiver -------------------------------------------------- if ((USART_GetITStatus(USART1, USART_IT_RXNE) == SET)||(USART_GetITStatus(USART1, USART_IT_ORE) == SET)) { //Receive = USART_ReceiveData(USART1); //USART_SendData(USART1, Receive); USART_SendData(USART1,USART_ReceiveData(USART1)); while (!USART_GetFlagStatus(USART1,USART_FLAG_TC)); } } } |
C:\Users\TUOLAJI\Desktop\QQ截图20150904123725.png硬件是直接连接的,PC端用的是USB转ttl的电路
这单片机是M4的,似乎IO不用特意配置成输入,而且,现在对我发的不同数据,单片机也能有不同的响应,只是不是正确的数据。
这个但是没有注意过,下次用303试试看。
这是调试用的,中断处理函数里面就是这个while循环里的东西,我临时把中断使能关闭了
那就不知道了