使用F429开发板。使用USART6,RX选PG9 TX选PC6. 程序测试过程中发现串口数据发送正常,数据接收时,能进入串口中断。但接收到的数据都是0.
是串口初始化时,不能PG6和PC6,只能PC6,PC7或者PG9,PG14吗?
这是串口初始化代码
void usart6_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOG,ENABLE); //ê1?üGPIOC.GPIOGê±?ó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);//ê1?üUSART6ê±?ó
//′??ú6??ó|òy???′ó?ó3é?
GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_USART6); //GPIOC6?′ó??aUSART6
GPIO_PinAFConfig(GPIOG,GPIO_PinSource9,GPIO_AF_USART6); //GPIOG9?′ó??aUSART6
//USART6???ú????
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //GPIOC6ó?GPIOG9
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//?′ó?1|?ü
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //?ù?è50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //í?íì?′ó?ê?3?
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //é?à-
GPIO_Init(GPIOC,&GPIO_InitStructure); //3?ê??ˉ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//?′ó?1|?ü
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //?ù?è50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //í?íì?′ó?ê?3?
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //é?à-
GPIO_Init(GPIOG,&GPIO_InitStructure);
//USART2 3?ê??ˉéè??
USART_InitStructure.USART_BaudRate = bound;//2¨ì??êéè??
USART_InitStructure.USART_WordLength = USART_WordLength_9b;//×?3¤?a8??êy?Y??ê?
USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò???í£?1??
USART_InitStructure.USART_Parity = USART_Parity_Even;//?T????D£?é??
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//?Tó2?têy?Yá÷????
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //ê?·¢?£ê?
USART_Init(USART6, &USART_InitStructure); //3?ê??ˉ′??ú1
USART_Cmd(USART6, ENABLE); //ê1?ü′??ú1
//USART_ClearFlag(USART6, USART_FLAG_TC);
USART_ITConfig(USART6, USART_IT_RXNE, ENABLE); //′ò?a′??ú?óê??D??
USART_ITConfig(USART6,USART_IT_IDLE,ENABLE); //′ò?a′??ú???D?D??
//USART6 NVIC ????
NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;//′??ú1?D??í¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//?à??ó??è??3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =3; //×óó??è??3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μàê1?ü
NVIC_Init(&NVIC_InitStructure); //?ù?Y???¨μ?2?êy3?ê??ˉVIC??′??÷? //ê1?ü′??ú
}
void USART6_Send_Byte(u8 Data) //·¢?íò???×??ú
{
USART_SendData(USART6,Data);
while( USART_GetFlagStatus(USART6, USART_FLAG_TC) == RESET );
}
void USART6_IRQHandler(void) //′??ú1?D??·t??3ìDò
{
u8 Clear = Clear;
if(USART_GetITStatus(USART6, USART_IT_RXNE) != RESET) //?óê??D??(?óê?μ?μ?êy?Y±?D?ê?0x0d 0x0a?á?2)
{
USART6_RX_BUF[len_count6++] =USART_ReceiveData(USART6);//(USART1->DR); //?áè??óê?μ?μ?êy?Y
}
if(USART_GetITStatus(USART6, USART_IT_IDLE) != RESET) //êy?Y?óê?íê3é
{
Clear = USART6->SR; //?áSR??′??÷
Clear = USART6->DR; //?áDR??′??÷£¨?è?áSR?ù?áDR£??íê??aá???3yIDLE?D??£?
len_count6 = 0; //±ê???óê?μ?á?1??êy?Y
state_machine6 = 1;
send_ready6 = 1;
USART6_RX_STA|=0x8000;
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
把LCD的代码注释掉,就正常了。但是LCD没用到这两个IO口,一直没找到原因
一周热门 更多>