各位我用查询方式接收串口数据,结果接收不到:期待高人指点。 串口配置如下: /* USART1 config 9600 8-N-1 */ USART_InitTypeDef USART_InitStructure; /* config USART1 clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE); /* USART1 GPIO config */ /* Configure USART1 Rx PA10 input floating */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART1 Tx (PA9) as alternate push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* USART1 mode config */ 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_Rx | USART_Mode_Tx; USART_Init(USART1, &USART_InitStructure); USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); // USART_ITConfig(USART1,USART_IT_TXE,ENABLE); USART_Cmd(USART1, ENABLE); 代码如下: void Commun_232_Receive(void) { static uint16_t Data_Rec[4]={0,0,0,0}; static uint16_t FrameHead=0; static uint16_t Data_Num=0; static uint16_t i=0,j=0,k=0; uint16_t crc=0,crc1=0; //=============================== // Receive_Status= USART_GetITStatus(USART1, USART_IT_RXNE); Receive_Status= USART_GetFlagStatus(USART1, USART_FLAG_RXNE); // if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) = 1) if(Receive_Status==1)//有数据 { Data_receive = USART_ReceiveData(USART1);//接收数据 Data_receive&=0xFF; // USART_ClearFlag(USART1,USART_FLAG_RXNE);//清除接收非空标志位 if(FrameHead==0&&Data_receive==0x35)//找帧头 { FrameHead=1; //找到帧头 } else if(FrameHead==1) { Data_Rec[Data_Num]=Data_receive; Data_Num++; if(Data_Num>4) { Data_Num=0; FrameHead=0; Data_Rec[2] = Data_Rec[2] BSRR = 0x00000008; /* Set PA3 */ Switch_Status.bit.TA0=1; } else if(Data_Rec[1]==1) { GPIOA->BRR = 0x00000008; /* Reset PA3 */ Switch_Status.bit.TA1=1; } break; } case 2: { if(Data_Rec[1]==0) { GPIOA->BSRR = 0x00000010; /* Set PA4 */ Switch_Status.bit.TA2=1; } else if(Data_Rec[1]==1) { GPIOA->BRR = 0x00000010; /* Reset PA4 */ Switch_Status.bit.TA3=1; } break; } case 3: { if(Data_Rec[1]==0) { GPIOA->BSRR = 0x00000020; /* Set PA5 */ Switch_Status.bit.TA4=1; } else if(Data_Rec[1]==1) { GPIOA->BRR = 0x00000020; /* Reset PA5 */ Switch_Status.bit.TA5=1; } break; } case 4: { if(Data_Rec[1]==0) { GPIOA->BSRR = 0x00000040; /* Set PA6 */ Switch_Status.bit.TA6=1; } else if(Data_Rec[1]==1) { GPIOA->BRR = 0x00000040; /* Reset PA6 */ Switch_Status.bit.TA7=1; } break; } case 5: { if(Data_Rec[1]==0) { GPIOA->BSRR = 0x00000080; /* Set PA7 */ Switch_Status.bit.TA8=1; } else if(Data_Rec[1]==1) { GPIOA->BRR = 0x00000080; /* Reset PA7 */ Switch_Status.bit.TA9=1; } break; } } } } } |
【MCU实战经验】基于STM32F103C8T6的hart总线调试器设计
求教STM32F103进入STOP模式后用外部中断唤醒的问题
基于STM32F103RCT6的无源蜂鸣器音乐播放(生日快乐歌)
STM32F103c8t6有没有DAC 功能?
STM32F103x中文数据手册
新手求教,为何在我电脑上找不到STM32F1Xx.h文件
金龙107例程汇总(STM32F107)
万利STM32F107VC 原理图
STM32F103 ADC多通道检测必须要DMA吗?
【官方例程】STM32F107以太网官方例程
RE:请教关于STM32F103USART串口接收的问题,附代码
RE:请教关于STM32F103USART串口接收的问题,附代码
改为下拉输入模式就好了。