新手入门
- 积分
- 16
- 金钱
- 16
- 注册时间
- 2020-8-3
- 在线时间
- 5 小时
|
1金钱
简单介绍下我把原子哥的视频例程写入开发板,串口可以使用所以排除硬件问题,
然后仔细对照例程看各个函数的初始化配置好像有没有什么错误,
只是在开发板中向32发送数据得不到回显,然后单独使用senddata函数对串口发送数据能够得到数据,
然后利用仿真看到RXNE标志位有置1,但好像不执行中断函数,求解///
//串口初始化,GPIO,NVIC等配置
void Usart_Config(void )
{
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE );
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStruct);
USART_InitStruct.USART_BaudRate =115200 ;
USART_InitStruct.USART_HardwareFlowControl =USART_HardwareFlowControl_None ;
USART_InitStruct.USART_Mode =USART_Mode_Rx|USART_Mode_Tx;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_StopBits =USART_StopBits_1;
USART_InitStruct.USART_WordLength =USART_WordLength_8b ;
USART_Init(USART1,&USART_InitStruct);
USART_Cmd(USART1,ENABLE);
USART_ITConfig( USART1,USART_IT_RXNE,ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&NVIC_InitStructure);
}
//中断函数
void USART1_IRQnHandler(void)
{
uint8_t res;
if(USART_GetITStatus(USART1,USART_IT_RXNE)){
res=USART_ReceiveData(USART1);
USART_SendData(USART1,res);
}
}
//主函数
int main(void)
{
Usart_Config();
while(1)
{
}
}
|
|