0から1までのクワッドローターUAVの実現(14)UAVMCUドライバー→UART

著者:妖精の妻謝が店主です
日付:2021/2/18

今年は、機能設計→マインドマップ→回路図設計→PCBレイアウト→溶接PCB→プログラミングコード→機械全体のデバッグから、一連の小さな4軸ドローンが更新され、独自の成長プロセスが記録されます。
この小さな4軸ドローンは大学時代に作られたもので、今では仕事や勉強に組み込まれていることをより深く理解しているので、小さな4軸を再編成して、大きな4軸の飛行制御設計を実現したいと思います。これに基づいて軸。、これらはすべて作業後に行われます!

//小四轴无人机设计,串口与接收机进行通讯
#include "uart.h"

/*******************************************************************************
 * fuction	uart1_init    
 * brief	串口1的配置初始化
 * param	无
 * return	无
 *******************************************************************************/  
void uart1_init(void)
{
    
    
	/*结构体变量定义*/
	GPIO_InitTypeDef  GPIO_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;					//中断嵌套控制函数	
	USART_InitTypeDef	USART_InitStructure;				//串口配置函数		
	/*开启引脚时钟*/
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);//开的是IO口的时钟
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);//开的是uart的时钟
	/*开启引脚复用功能PA9/PA10*/
 	GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7);
	GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7);
	/*引脚的配置PA9/PA10*/
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9|GPIO_Pin_10;
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
	GPIO_Init(GPIOA,&GPIO_InitStructure);		
	/*串口的配置*/
	USART_InitStructure.USART_BaudRate            = 115200;
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; 
	USART_InitStructure.USART_Mode 								= USART_Mode_Rx|USART_Mode_Tx;
	USART_InitStructure.USART_Parity 							= USART_Parity_No;
	USART_InitStructure.USART_StopBits 						= USART_StopBits_1;
	USART_InitStructure.USART_WordLength 					= USART_WordLength_8b;
	USART_Init(USART1,&USART_InitStructure);
	/*串口的中断配置*/
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	NVIC_InitStructure.NVIC_IRQChannel 									 = USART1_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority 			 = 1;
	NVIC_InitStructure.NVIC_IRQChannelCmd 							 = ENABLE;
	NVIC_Init(&NVIC_InitStructure);
  	/*串口的接收中断使能*/
  	USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  	/*串口的使能*/
  	USART_Cmd(USART1,  ENABLE);
}
//中断服务程序     中断标志位需要软件清零
/*******************************************************************************
 * fuction	USART1_IRQHandler   
 * brief	串口1中断服务函数
 * param	无
 * return	无
 *******************************************************************************/  
void USART1_IRQHandler(void)
{
    
    
	static uint8_t i = 0;                          //静态变量
	/*判断中断标志位  */
	if(USART_GetITStatus(USART1,USART_IT_RXNE)==SET )
	{
    
    		
		USART_ClearITPendingBit(USART1,USART_IT_RXNE);       //中断标志位  清零
	 	RF_DATA[i]  = USART_ReceiveData(USART1);                                          // 0  1... 13
		bind_count ++;		
		if(RF_DATA[0]==0x66)
		{
    
    			
			i++;
			if(i==13)
			{
    
    
				RF_DATA_SUCCES = true;
				i = 0;
			}			
		}
		if((bind_flag==true)||(two_point_four_bind_flag == false))
		{
    
    
			bind_flag=false;
			if(RF_DATA[0]==0xAA)
			{
    
    			
				two_point_four_bind_flag = true;				
			}		
	  	}
	}
}




#ifndef _UART_H__
#define _UART_H__

#include "board_define.h"
#include "var_global.h"

void uart1_init(void);

#endif


おすすめ

転載: blog.csdn.net/FutureStudio1994/article/details/113854177