
stm32F427发送,用232转usb接到电脑上,用串口调试助手接收,发送6个字节是{3F,01,03,04,00,校验和},电脑接收的6个字节是{60 7F 7E DF 71 00},求助了。 程序代码如下: void Uart_init(void) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //RX GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //TX GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3); 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_Tx | USART_Mode_Rx; USART_Init(USART3, &USART_InitStructure); USART_Cmd(USART3, ENABLE); } void Usart3_SendData(USART_TypeDef* USARTx, unsigned char TempData) { while(!(USARTx->SR&0x80)); //while(!(USARTx->SR&0x40)){}; //while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET){} USARTx->DR = (TempData & (uint16_t)0x01FF); //while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET){} //while((USARTx->SR&0x40)==0); } void usart3_send_data(unsigned char Send_number,unsigned char *Send_data) { unsigned char i; for(i=0;i<Send_number;i++) { Usart3_SendData(USART3, Send_data); //delay_ms(2); } } void Sensor_Data_Generate_Send(void) { unsigned char i=0; Data_Buffer[0]=0x3F; Data_Buffer[1]=0x01; Data_Buffer[2]=0x03; Data_Buffer[3]=0x04; for(i=4;i<5;i++) { Data_Buffer=0x00; } CHK_SUM=0; for(i=0;i<5;i++) CHK_SUM+=Data_Buffer; Data_Buffer[5]=CHK_SUM % 255; usart3_send_data(6, Data_Buffer); } |
另外,硬件上也确认下。
评分
查看全部评分
评分
查看全部评分