【瑞萨BLE/WIFI模块测评】+ 蓝牙模块收发测试
测试DA14531蓝牙模块收发通信。一、硬件资料
蓝牙模块直接插入PMOD1接口。
1.1、DA14531蓝牙模块接口部分
1.2、开发板PMOD1接口
二、软件配置
2.1、串口配置
蓝牙模块使用串口4。
三、程序部分
3.1、fun_uart.c
#include "hal_data.h"
#include "uart/fun_uart.h"
volatile bool uart9_send_complete_flag = false;
volatile bool uart4_send_complete_flag = false;
volatile bool uart0_send_complete_flag = false;
void init_uart(void)
{
R_SCI_UART_Open (&g_uart9_ctrl, &g_uart9_cfg);
R_SCI_UART_Open (&g_uart4_ctrl, &g_uart4_cfg);
R_SCI_UART_Open (&g_uart0_ctrl, &g_uart0_cfg);
}
void g_uart9_callback(uart_callback_args_t *p_args)
{
switch(p_args->event)
{
case UART_EVENT_RX_CHAR:
R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)&(p_args->data),1);
break;
case UART_EVENT_TX_COMPLETE:
uart9_send_complete_flag=true;
break;
default:
break;
}
}
void g_uart4_callback(uart_callback_args_t *p_args)
{
switch(p_args->event)
{
case UART_EVENT_RX_CHAR:
R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)&(p_args->data),1);
break;
case UART_EVENT_TX_COMPLETE:
uart4_send_complete_flag=true;
break;
default:
break;
}
}
void g_uart0_callback(uart_callback_args_t *p_args)
{
switch(p_args->event)
{
case UART_EVENT_RX_CHAR:
R_SCI_UART_Write(&g_uart0_ctrl, (uint8_t *)&(p_args->data),1);
break;
case UART_EVENT_TX_COMPLETE:
uart0_send_complete_flag=true;
break;
default:
break;
}
}
void uart4_sendbyte(uint8_t dt)
{
R_SCI_UART_Write(&g_uart4_ctrl, &dt, 1);
while(uart4_send_complete_flag == false);
uart4_send_complete_flag = false;
}
int fputc(int ch, FILE *f)
{
(void)f;
R_SCI_UART_Write(&g_uart9_ctrl, (uint8_t *)&ch, 1);
while(uart9_send_complete_flag == false);
uart9_send_complete_flag = false;
return ch;
}
void init_da14531(void)
{
da14531_lpr_h();
}
3.2、hal_entry.c
#include "hal_data.h"
#include "led/fun_led.h"
#include "uart/fun_uart.h"
#include "oled/fun_oled.h"
#if (1 == BSP_MULTICORE_PROJECT) && BSP_TZ_SECURE_BUILD
bsp_ipc_semaphore_handle_t g_core_start_semaphore =
{
.semaphore_num = 0
};
#endif
/*******************************************************************************************************************//**
* main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used.This function
* is called by main() when no RTOS is used.
**********************************************************************************************************************/
void hal_entry(void)
{
init_uart();
init_led();
init_da14531();
OLED_Init();
oled_test();
while(1)
{
R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);
led1_off();
led2_on();
led3_off();
R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS);
led1_off();
led2_off();
led3_on();
//printf("RA-eco-RA6M4 uart test!\r\n");
uart4_sendbyte(0x2a);
}
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
}
四、运行结果
4.1、蓝牙模块发送数据
开发板上电后,间隔通过串口4发送字节0x2A数据。
4.2、蓝牙模块接收数据
蓝牙调试助手发送0x55数据,通过串口9输出。
页:
[1]