为什么mini板和F4串口通信,mini板可以接收到F4板的数据,但是F4却收不到mini板的数据,在线调试仿真时发现F4根本没进入中断接收函数,有什么问题呢????下边是Mini板的发送程序#include "sys.h"#include "stm32f10x.h"
#include "led.h"
#include "delay.h"
#include "usart.h"
u8 message=25;
void My_usart_init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_DeInit( GPIOA);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_2;
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_3;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);
USART_DeInit(USART2);
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(USART2, &USART_InitStruct);
USART_Cmd(USART2,ENABLE);
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
NVIC_InitStruct.NVIC_IRQChannel=USART2_IRQn;
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=2;
NVIC_Init(&NVIC_InitStruct);
}
void USART2_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(USART2,USART_IT_RXNE)==1)
{
res=USART_ReceiveData(USART2);
printf("message=%d/n",res);
LED1=!LED1;
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
}
}
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
My_usart_init();
uart_init(115200);
LED_Init();
delay_init();
while(1)
{
USART_SendData(USART2,message);
LED0=!LED0;
delay_ms(500);
}
}
一周热门 更多>