本篇文章来自极术社区与兆易创新组织的GD32F427开发板评测活动,更多开发板试用活动请关注极术社区网站。作者:卢阿涛
一、硬件介绍
分享一款便宜的蓝牙模块,ECB02H2,淘宝售价为两块多。这里值得注意的是,此蓝牙模块不支持中文。
如下所示:
二、引脚定义
引脚定义如下:
RXD: 接单片机的TXD
TXD:接单片机的RXD
三、软件配置
1.串口配置
/**
* @name:
* @function: 引脚配置
* @return {*}
* @author: lengyuefeng
* @Date: 2022-11-24 20:33:41
*/
void bsp_usart3_gpioConfig(void)
{
/* enable GPIO clock */
rcu_periph_clock_enable(BSP_USART3_GPIO_RCU);
/* configure the USART0 TX pin and USART0 RX pin */
gpio_af_set(BSP_USART3_TX_PORT, GPIO_AF_7, BSP_USART3_TX_PIN);
gpio_af_set(BSP_USART3_RX_PORT, GPIO_AF_7, BSP_USART3_RX_PIN);
/* configure USART0 TX as alternate function push-pull */
gpio_mode_set(BSP_USART3_TX_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, BSP_USART3_TX_PIN);
gpio_output_options_set(BSP_USART3_TX_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, BSP_USART3_TX_PIN);
/* configure USART0 RX as alternate function push-pull */
gpio_mode_set(BSP_USART3_RX_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, BSP_USART3_RX_PIN);
gpio_output_options_set(BSP_USART3_RX_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, BSP_USART3_RX_PIN);
}
/**
* @name:
* @function: 串口配置
* @param {uint32_t} bound:波特率
* @return {*}
* @author: lengyuefeng
* @Date: 2022-11-24 20:36:50
*/
void bsp_usart3_usartConfig(uint32_t bound)
{
/* enable USART clock */
rcu_periph_clock_enable(BSP_USART3_RCU);
/* USART configure */
usart_deinit(BSP_USART3_USART);
usart_baudrate_set(BSP_USART3_USART, bound);
usart_receive_config(BSP_USART3_USART, USART_RECEIVE_ENABLE);
usart_transmit_config(BSP_USART3_USART, USART_TRANSMIT_ENABLE);
usart_enable(BSP_USART3_USART);
}
四、效果
默认上电后,单片机会每隔1s时间发送一次Evaluation of Jishu Community Development Board