#include "bsp_usart.h" #include "system.h" #include "sht3x.h" ////传感器数据定义 //SensorDataTypeDef sensorData; ////PM2.5命令 //const uint8_t cmd_pm25_duqu[7] = {0x42,0x4D,0xE2,0x00,0x00,0x01,0x71};//主动读取数据 //const uint8_t cmd_pm25_beidong[7] = {0x42,0x4D,0xE1,0x00,0x00,0x01,0x70};//设置传感器为应答模式 //const uint8_t cmd_pm25_zhudong[7] = {0x42,0x4D,0xE1,0x00,0x01,0x01,0x71};//设置传感器为主动上传模式 //const uint8_t cmd_pm25_daiji[7] = {0x42,0x4D,0xE4,0x00,0x00,0x01,0x73};//设置传感器进入待机模式 //const uint8_t cmd_pm25_zhengchang[7] = {0x42,0x4D,0xE4,0x00,0x01,0x01,0x74};//设置传感器进入正常模式 // ////CO2命令 //const uint8_t cmd_co2_duqu[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};//主动读取数据 //const uint8_t cmd_co2_liangcheng2[9] = {0xFF,0x01,0x99,0x00,0x00,0x00,0x07,0xD0,0x8F};//设置二氧化碳量程为0-2000ppm //const uint8_t cmd_co2_liangcheng5[9] = {0xFF,0x01,0x99,0x00,0x00,0x00,0x13,0x88,0xCB};//设置二氧化碳量程为0-5000ppm //const uint8_t cmd_co2_liangcheng10[9] = {0xFF,0x01,0x99,0x00,0x00,0x00,0x27,0x10,0x2F};//设置二氧化碳量程为0-10000ppm ////NH3/H2S命令 //const uint8_t cmd_nh3_h2s_duqu[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};//主动读取数据 //const uint8_t cmd_nh3_h2s_beidong[9] = {0xFF,0x01,0x78,0x04,0x00,0x00,0x00,0x00,0x83};//设置传感器为应答模式 //const uint8_t cmd_nh3_h2s_zhudong[9] = {0xFF,0x01,0x86,0x03,0x00,0x00,0x00,0x00,0x84};//设置传感器为主动上传模式 ////CH2O命令 //const uint8_t cmd_CH2O_duqu[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};//主动读取数据 //const uint8_t cmd_CH2O_beidong[9] = {0xFF,0x01,0x78,0x41,0x00,0x00,0x00,0x00,0x46};//设置传感器为应答模式 //const uint8_t cmd_CH2O_zhudong[9] = {0xFF,0x01,0x78,0x40,0x00,0x00,0x00,0x00,0x47};//设置传感器为主动上传模式 //uint8_t NH3_Buffer[NH3_BUF_LEN]; //NH3接收Buffer //uint8_t CH2O_Buffer[CH2O_BUF_LEN]; //CH2O接收Buffer //uint8_t PM25_Buffer[PM25_BUF_LEN]; //PM25接收Buffer //uint8_t H2S_Buffer[H2S_BUF_LEN]; //H2S接收Buffer //uint8_t CO2_Buffer[CO2_BUF_LEN]; //CO2接收Buffer //uint8_t SP3485_Buffer[64]; //SP3485接收Buffer //uint8_t loraNode_Buffer[LoraNode_BUF_LEN]; //LORA接收Buffer /** * @brief Configures the different system clocks. * @param None * @retval None */ void USART_RCC_Configuration(void) { /* Enable GPIO clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOC|RCC_AHBPeriph_GPIOD|RCC_AHBPeriph_GPIOF, ENABLE); /* Enable 8xUSARTs Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB1Periph_USART3|RCC_APB1Periph_USART4|RCC_APB1Periph_USART5, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6|RCC_APB2Periph_USART7|RCC_APB2Periph_USART8|RCC_APB2Periph_USART1|RCC_APB2Periph_SYSCFG,ENABLE); } /** * @brief Configures the different GPIO ports. * @param None * @retval None */ void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; //DEBUG_USART1 引脚初始化 //连接到外设 GPIO_PinAFConfig(DEBUG_USART_RX_GPIO_PORT,DEBUG_USART_RX_SOURCE,DEBUG_USART_RX_AF); GPIO_PinAFConfig(DEBUG_USART_TX_GPIO_PORT,DEBUG_USART_TX_SOURCE,DEBUG_USART_TX_AF); //将引脚配置为AF pushpull GPIO_InitStructure.GPIO_Pin = DEBUG_USART_RX_PIN | DEBUG_USART_TX_PIN; 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(DEBUG_USART_RX_GPIO_PORT,&GPIO_InitStructure); //NH3_USART2 引脚初始化 //连接到外设 GPIO_PinAFConfig(NH3_USART_RX_GPIO_PORT,NH3_USART_RX_SOURCE,NH3_USART_RX_AF); GPIO_PinAFConfig(NH3_USART_TX_GPIO_PORT,NH3_USART_TX_SOURCE,NH3_USART_TX_AF); //将引脚配置为AF pushpull GPIO_InitStructure.GPIO_Pin = NH3_USART_RX_PIN | NH3_USART_TX_PIN; 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(NH3_USART_RX_GPIO_PORT,&GPIO_InitStructure); //CH2O_USART3 引脚初始化 //连接到外设 GPIO_PinAFConfig(CH2O_USART_RX_GPIO_PORT,CH2O_USART_RX_SOURCE,CH2O_USART_RX_AF); GPIO_PinAFConfig(CH2O_USART_TX_GPIO_PORT,CH2O_USART_TX_SOURCE,CH2O_USART_TX_AF); //将引脚配置为AF pushpull GPIO_InitStructure.GPIO_Pin = CH2O_USART_RX_PIN | CH2O_USART_TX_PIN; 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(CH2O_USART_RX_GPIO_PORT,&GPIO_InitStructure); //PM25_USART4 引脚初始化 //连接到外设 GPIO_PinAFConfig(PM25_USART_RX_GPIO_PORT,PM25_USART_RX_SOURCE,PM25_USART_RX_AF); GPIO_PinAFConfig(PM25_USART_TX_GPIO_PORT,PM25_USART_TX_SOURCE,PM25_USART_TX_AF); //将引脚配置为AF pushpull GPIO_InitStructure.GPIO_Pin = PM25_USART_RX_PIN | PM25_USART_TX_PIN; 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(PM25_USART_RX_GPIO_PORT,&GPIO_InitStructure); //H2S_USART5 引脚初始化 //连接到外设 GPIO_PinAFConfig(H2S_USART_RX_GPIO_PORT,H2S_USART_RX_SOURCE,H2S_USART_RX_AF); GPIO_PinAFConfig(H2S_USART_TX_GPIO_PORT,H2S_USART_TX_SOURCE,H2S_USART_TX_AF); //将引脚配置为AF pushpull GPIO_InitStructure.GPIO_Pin = H2S_USART_RX_PIN; 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(H2S_USART_RX_GPIO_PORT,&GPIO_InitStructure); //将引脚配置为AF GPIO_InitStructure.GPIO_Pin = H2S_USART_TX_PIN; 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(H2S_USART_TX_GPIO_PORT,&GPIO_InitStructure); //CO2_USART6 引脚初始化 //连接到外设 GPIO_PinAFConfig(CO2_USART_RX_GPIO_PORT,CO2_USART_RX_SOURCE,CO2_USART_RX_AF); GPIO_PinAFConfig(CO2_USART_TX_GPIO_PORT,CO2_USART_TX_SOURCE,CO2_USART_TX_AF); //将引脚配置为AF pushpull GPIO_InitStructure.GPIO_Pin = CO2_USART_RX_PIN | CO2_USART_TX_PIN; 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(CO2_USART_RX_GPIO_PORT,&GPIO_InitStructure); //SP3485_USART7 引脚初始化 //连接到外设 GPIO_PinAFConfig(WIFI_USART_RX_GPIO_PORT,WIFI_USART_RX_SOURCE,WIFI_USART_RX_AF); GPIO_PinAFConfig(WIFI_USART_TX_GPIO_PORT,WIFI_USART_TX_SOURCE,WIFI_USART_TX_AF); //将引脚配置为AF pushpull GPIO_InitStructure.GPIO_Pin = WIFI_USART_RX_PIN | WIFI_USART_TX_PIN; 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(WIFI_USART_RX_GPIO_PORT,&GPIO_InitStructure); //LORA_USART8 引脚初始化 //连接到外设 GPIO_PinAFConfig(LORA_USART_RX_GPIO_PORT,LORA_USART_RX_SOURCE,LORA_USART_RX_AF); GPIO_PinAFConfig(LORA_USART_TX_GPIO_PORT,LORA_USART_TX_SOURCE,LORA_USART_TX_AF); //将引脚配置为AF pushpull GPIO_InitStructure.GPIO_Pin = LORA_USART_RX_PIN | LORA_USART_TX_PIN; 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(LORA_USART_RX_GPIO_PORT,&GPIO_InitStructure); //TVOC引脚配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB,&GPIO_InitStructure); //LORA_RST引脚配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOA,&GPIO_InitStructure); //PM25_RST引脚配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOC,&GPIO_InitStructure); GPIO_SetBits(GPIOC,GPIO_Pin_2); GPIO_SetBits(GPIOC,GPIO_Pin_3); //WIFI_RST引脚配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_SetBits(GPIOB,GPIO_Pin_15); } /** * @brief Configures USART1-8 * @param None * @retval None */ void USART_Configuration(void) { USART_InitTypeDef USART_InitStructure; /* DEBUG_USART configuration */ USART_InitStructure.USART_BaudRate = DEBUG_USART_BAUDRATE; 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(DEBUG_USART,&USART_InitStructure); /* Disable DEBUG_USART Receive interrupts */ USART_ITConfig(DEBUG_USART,USART_IT_RXNE,DISABLE); /* Enable the DEBUG_USART */ USART_Cmd(DEBUG_USART,ENABLE); /* NH3_USART configuration */ USART_InitStructure.USART_BaudRate = NH3_USART_BAUDRATE; 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(NH3_USART,&USART_InitStructure); /* Enable NH3_USART Receive interrupts */ USART_ITConfig(NH3_USART,USART_IT_RXNE,DISABLE); /* Enable the NH3_USART */ USART_Cmd(NH3_USART,ENABLE); /* CH2O_USART configuration */ USART_InitStructure.USART_BaudRate = CH2O_USART_BAUDRATE; 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(CH2O_USART,&USART_InitStructure); /* Enable CH2O_USART Receive interrupts */ USART_ITConfig(CH2O_USART,USART_IT_RXNE,DISABLE); /* Enable the CH2O_USART */ USART_Cmd(CH2O_USART,ENABLE); /* PM25_USART configuration */ USART_InitStructure.USART_BaudRate = PM25_USART_BAUDRATE; 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(PM25_USART,&USART_InitStructure); /* Enable PM25_USART Receive interrupts */ USART_ITConfig(PM25_USART,USART_IT_RXNE,DISABLE); /* Enable the PM25_USART */ USART_Cmd(PM25_USART,ENABLE); /* H2S_USART configuration */ USART_InitStructure.USART_BaudRate = H2S_USART_BAUDRATE; 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(H2S_USART,&USART_InitStructure); /* Enable H2S_USART Receive interrupts */ USART_ITConfig(H2S_USART,USART_IT_RXNE,DISABLE); /* Enable the H2S_USART */ USART_Cmd(H2S_USART,ENABLE); /* CO2_USART configuration */ USART_InitStructure.USART_BaudRate = CO2_USART_BAUDRATE; 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(CO2_USART,&USART_InitStructure); /* Enable CO2_USART Receive interrupts */ USART_ITConfig(CO2_USART,USART_IT_RXNE,ENABLE); /* Enable the CO2_USART */ USART_Cmd(CO2_USART,ENABLE); /* WIFI_USART configuration */ USART_InitStructure.USART_BaudRate = WIFI_USART_BAUDRATE; 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(WIFI_USART,&USART_InitStructure); /* Enable WIFI_USART Receive interrupts */ USART_ITConfig(WIFI_USART,USART_IT_RXNE,ENABLE); /* Enable the WIFI_USART */ USART_Cmd(WIFI_USART,DISABLE); /* LORA_USART configuration */ USART_InitStructure.USART_BaudRate = LORA_USART_BAUDRATE; 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(LORA_USART,&USART_InitStructure); /* Enable LORA_USART Receive interrupts */ USART_ITConfig(LORA_USART,USART_IT_RXNE,DISABLE); /* Enable the LORA_USART */ USART_Cmd(LORA_USART,ENABLE); } /** * @brief Configures the nested vectored interrupt controller. * @param None * @retval None */ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; /* DEBUG_USART IRQ Channel configuration */ NVIC_InitStructure.NVIC_IRQChannel = DEBUG_USART_IRQ; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* NH3_USART IRQ Channel configuration */ NVIC_InitStructure.NVIC_IRQChannel = NH3_USART_IRQ; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* CH2O_USART IRQ Channel configuration */ NVIC_InitStructure.NVIC_IRQChannel = CH2O_USART_IRQ; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* PM25_USART IRQ Channel configuration */ NVIC_InitStructure.NVIC_IRQChannel = PM25_USART_IRQ; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* H2S_USART IRQ Channel configuration */ NVIC_InitStructure.NVIC_IRQChannel = H2S_USART_IRQ; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* CO2_USART IRQ Channel configuration */ NVIC_InitStructure.NVIC_IRQChannel = CO2_USART_IRQ; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* SP3485_USART IRQ Channel configuration */ NVIC_InitStructure.NVIC_IRQChannel = WIFI_USART_IRQ; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* LORA_USART IRQ Channel configuration */ NVIC_InitStructure.NVIC_IRQChannel = LORA_USART_IRQ; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void EXTI_Button_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; //按键引脚配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB,&GPIO_InitStructure); //EXTI配置 EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB,EXTI_PinSource0); /* Button0 IRQ Channel configuration */ NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } /******************************************************************************* **函数名称:UsartxSendDataByte(USART_TypeDef* USARTx,uint16_t Data) **功能描述:串口发送一个字节 **入口参数:USART_TypeDef* USARTx 串口句柄 uint16_t Data 要发送的数据 **输出:无 *******************************************************************************/ void UsartxSendDataByte(USART_TypeDef* USARTx,uint16_t Data) { USART_SendData(USARTx,Data); while(USART_GetFlagStatus(USARTx,USART_FLAG_TXE)==RESET); } /******************************************************************************* **函数名称:UsartxSendDataStr(USART_TypeDef* USARTx,const uint8_t *Data,uint32_t len) **功能描述:串口发送字符串 **入口参数:USART_TypeDef* USARTx 串口句柄 uint8_t *Data 要发送的数据 uint32_t len 数据长度 **输出:无 *******************************************************************************/ void UsartxSendDataStr(USART_TypeDef* USARTx,const uint8_t *Data,uint32_t len) { while(len--) { USART_SendData(USARTx,*(Data++)); while(USART_GetFlagStatus(USARTx,USART_FLAG_TXE)==RESET); } }