zigbee和stm32f103之间的串口通信keil5代码
时间: 2023-02-18 15:21:51 浏览: 144
我们可以参考以下示例代码来实现zigbee和stm32f103之间的串口通信:
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "zigbee.h"
/* Private variables ---------------------------------------------------------*/
USART_InitTypeDef USART_InitStructure;
/* Private function prototypes -----------------------------------------------*/
void USART_Config(void);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/* USART configuration */
USART_Config();
/* Initialize the Zigbee module */
Zigbee_Init();
while (1)
{
/* Check if any data received from Zigbee module */
Zigbee_ReceiveData();
}
}
/**
* @brief Configure the USART.
* @param None
* @retval None
*/
void USART_Config(void)
{
/* USART resources configuration (Clock, GPIO pins and USART registers) ----*/
/* USART configured as follow:
- BaudRate = 9600 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 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;
/* Configure the USART */
USART_Init(USART1, &USART_InitStructure);
/* Enable the USART */
USART_Cmd(USART1, ENABLE);
}