Home > other >  I use a GY25 module, two serial ports, stm32f10 board, want to send a serial port 1 received data to
I use a GY25 module, two serial ports, stm32f10 board, want to send a serial port 1 received data to

Time:09-16

This is a serial port Settings. C file

U8 USART_RX_BUF [64].

U8 USART_RX_STA=0;

Void uart_init (u32 bound) {

GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
//USART1_TX PA. 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, & amp; GPIO_InitStructure);

//USART1_RX PA. 10
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

//Usart1 NVIC

NVIC_InitStructure. NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=2;//

NVIC_InitStructure. NVIC_IRQChannelCmd=ENABLE;
NVIC_Init (& amp; 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, & amp; USART_InitStructure);


USART_ITConfig (USART1, USART_IT_RXNE, ENABLE);//

USART_Cmd (USART1, ENABLE);

}
Void uart2_init (u32 bound)
{

GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART2, ENABLE);
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
//Configure USART2 Tx (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, & amp; GPIO_InitStructure);//
//Configure USART2 Rx (PB3)
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_3;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init (GPIOA, & amp; 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, & amp; 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 (& amp; NVIC_InitStructure);

USART_Cmd (USART2, ENABLE);//
USART_ITConfig (USART2, USART_IT_RXNE, ENABLE);//
}
Int16_t YAW=0, PITCH=0, ROLL=0;
Uint8_t flag=0;
Void USART1_IRQHandler (void)//
{
The static uint8_t k=0, rebuf [8]={0};
If (USART_GetITStatus (USART1, USART_IT_RXNE)!=RESET)
{
Rebuf [k++]=USART_ReceiveData (USART1);//
if(! (rebuf [0]==0 xaa))//
{
K=0;
Rebuf [0]=0;
}
If (k==8)//
{
If (rebuf [7]==0 x55)//
{
YAW=(rebuf [1] <8 | rebuf [2]);//
PITCH=(rebuf [3] <8 | rebuf [4]);
ROLL=(rebuf [5] <8 | rebuf [6]);
flag=1;
}
K=0;//
}


}
}
Void USART2_IRQHandler (void)
{
The static uint8_t I=0, reuf [8]={0};
Reuf [i++]=USART_ReceiveData (USART2);
USART_SendData (USART1, reuf [0]);
USART_SendData (USART1, reuf [1]);
USART_SendData (USART1, reuf [2]);
USART_SendData (USART1, reuf [3]);
USART_SendData (USART1, reuf [4]);
USART_SendData (USART1, reuf [5]);
USART_SendData (USART1, reuf [6]);
USART_SendData (USART1, reuf [7]);

}


The main function

Void dis_play (int16_t num, u8 n)
{
If (num<0)
{
Num=- num;
USART_SendData (USART1, '-');
}
The else
USART_SendData (USART1, '+');
//if (n)
USART_SendData (USART1, 0 x30 | (num/10000));
USART_SendData (USART1, 0 x30 | (num % 10000/1000));
USART_SendData (USART1, 0 x30 | (num % 1000/100));
USART_SendData (USART1, 0 x2e);
USART_SendData (USART1, 0 x30 | (num % 100/10));
USART_SendData (USART1, 0 x30 | (num % 10));
USART_SendData (USART1, ', ');
}
Int main (void)
{

U8 t;
U8 len.
The static u8 times=0;
SystemInit ();//
Delay_init (72);//
NVIC_Configuration ();//
Uart_init (115200);//115200
Uart2_init (9600);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related