我用了一个GY25模块,两个串口,stm32f10的板子,想把串口1接收的数据发送到串口2,但是数据没能发送到串口2

[复制链接]
查看11 | 回复1 | 2021-1-27 05:06:11 | 显示全部楼层 |阅读模式
这是串口设置的.c文件
u8USART_RX_BUF[64];
u8USART_RX_STA=0;
voiduart_init(u32bound){
GPIO_InitTypeDefGPIO_InitStructure;
USART_InitTypeDefUSART_InitStructure;
NVIC_InitTypeDefNVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
//USART1_TXPA.9
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
//USART1_RXPA.10
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStructure);
//Usart1NVIC
NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=2;//
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);//USART1
//USART
USART_DeInit(USART1);
USART_InitStructure.USART_BaudRate=bound;//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_Cmd(USART1,ENABLE);
}
voiduart2_init(u32bound)
{
GPIO_InitTypeDefGPIO_InitStructure;
USART_InitTypeDefUSART_InitStructure;
NVIC_InitTypeDefNVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
//ConfigureUSART2Tx(PB2)
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);//
//ConfigureUSART2Rx(PB3)
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStructure);//
USART_DeInit(USART2);
USART_InitStructure.USART_BaudRate=bound;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
USART_InitStructure.USART_Parity=USART_Parity_No;
USART_InitStructure.USART_StopBits=USART_StopBits_1;
USART_InitStructure.USART_WordLength=USART_WordLength_8b;
USART_Init(USART2,&USART_InitStructure);//

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_Cmd(USART2,ENABLE);//
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);//
}
int16_tYAW=0,PITCH=0,ROLL=0;
uint8_tflag=0;
voidUSART1_IRQHandler(void)//
{
staticuint8_tk=0,rebuf[8]={0};
if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET)
{
rebuf[k++]=USART_ReceiveData(USART1);//
if(!(rebuf[0]==0xaa))//
{
k=0;
rebuf[0]=0;
}
if(k==8)//
{
if(rebuf[7]==0x55)//
{
YAW=(rebuf[1]
}
delay_ms(10);
//if(times==0)
//{
//times=1;//
//USART_SendData(USART1,0xa5);
//USART_SendData(USART1,0x52);//
//}
if(flag==1)
{
flag=0;
USART_SendData(USART2,'#');
USART_SendData(USART2,'Y');
USART_SendData(USART2,'P');
USART_SendData(USART2,'R');
USART_SendData(USART2,'=');
dis_play(YAW,1);
dis_play(PITCH,0);
dis_play(ROLL,0);
USART_SendData(USART2,0X0d);
USART_SendData(USART2,0X0a);
}
}
}
有大佬能帮忙看看嘛


分 -->
回复

使用道具 举报

千问 | 2021-1-27 05:06:11 | 显示全部楼层
老哥你解决了吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行