stm32f407单片机底层应用程序_usart6

  1. usart6.c

    #include "usart6.h"

    void My_USART6_Init(USART_TypeDef* USARTx,u32 bound)
    {
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;

    复制代码
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);
     	
     //GPIO
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);
     	
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7; 
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
     GPIO_Init(GPIOC,&GPIO_InitStructure);
     		
     //USART
     USART_InitStructure.USART_BaudRate = bound;
     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(USARTx,&USART_InitStructure);
     
    
     
     //NVIC
     NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;
     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_InitStructure);
     
     	
     USART_DMACmd(USARTx, USART_DMAReq_Rx, ENABLE);	
     USART_DMACmd(USARTx, USART_DMAReq_Tx, ENABLE);	
     USART_ITConfig(USARTx, USART_IT_IDLE, ENABLE); 
     
     USART_Cmd(USARTx,ENABLE);	

    }

2.usart6.h

复制代码
#ifndef  __USART6_H
#define  __USART6_H
#include "sys.h"


void My_USART6_Init(USART_TypeDef* USARTx,u32 bound);


#endif
相关推荐
巴巴媛66623 分钟前
【Debug1】程序死机,while(1)循环,怎么办?
c语言·笔记·stm32·嵌入式硬件·bug
Lxx_Zw24 分钟前
PID 用顺了,然后呢:增强手术与前馈
c语言·stm32·单片机·嵌入式硬件
张怀民31640 分钟前
PFC_CCM_NCP1654详讲
单片机·嵌入式硬件·硬件工程·pfc
linweidong1 小时前
RTC 走偏、时间跳变?嵌入式时间管理的工程避坑
嵌入式硬件·面试·实时音视频·rtc·嵌入式面经·嵌入式ntp·嵌入式对时
Yiran_G1 小时前
ZigBee单播、广播与组播详解:从寻址机制到批量控制设计
嵌入式硬件·物联网·智能家居
youcans_2 小时前
【STM32C5教程】(9)DAC 模拟量信号输出实验
stm32·单片机·嵌入式硬件·stm32c5·cubemx2
智购科技自动售货机工厂2 小时前
省电40%的底层逻辑:冷热双温售货机基于SaaS的智能温控算法~YH
单片机·嵌入式硬件·百度·架构·emacs
深圳市恒锐丰科技杨生2 小时前
SS6203D 200V 单路半桥栅极驱动芯片|LeadPower 率能半导体
嵌入式硬件·硬件工程
深圳老胡2 小时前
STM32C5 系列 MCU 的 FreeRTOS 软件架构搭建指南:外设配置与应用实践
笔记·stm32·单片机·代码规范
霖霖7143 小时前
【ESP32笔记】I2S的音频录制与播放
笔记·单片机·mcu·音视频