Bluetooth communication porting
1. Introduction
In the previous evaluation, I used the official AT32 IDE of Artly for testing. However, considering that the amount of engineering work on Bluetooth communication is quite large and the stability of transplantation is not guaranteed, after studying for a few days, I think it is better to use MDK5 used by the official Bluetooth routines for testing the code for Bluetooth communication.
2. Introduction to Bluetooth Engineering
We can find the official Bluetooth routines in the official documents of Arteli, the first one is the Bluetooth development manual written by Arteli, and the second attachment is the Bluetooth routines we need. The Bluetooth module of WB415 is integrated in the MCU, so when testing the Bluetooth function, we need two projects to write the Bluetooth function of WB415 and the MCU function respectively, where Bluetooth and MCU communicate through the internal serial port.
By checking the manual, we know that the project for programming Bluetooth function is ARM9 project. We can download the corresponding ARM9 expansion package from KEIL's official website, so that we can open the project. The next step is the installation process of ARM9. There are no pitfalls as a whole, and basically follow the default.
The above picture is the official Bluetooth routine. After compilation, the corresponding bin file will be generated. Later, we need to download the bin file to the development board through the ICP tool.
Similarly, we open the MCU part of the project. After compilation, the corresponding hex file will be generated, which can be found in the objects folder under the project directory.
3. Download and run
The corresponding ICP download tool can be downloaded from the Yatli official website
After opening the ICP tool, you first need to connect to AT-Link. If the AT-Link version is too low, the tool will remind you to update it automatically. Then select the corresponding file to download.
When downloading the Bluetooth bin file, you need to change the starting address of the download to 00000000, otherwise it will conflict with the hex file address of the MCU later, resulting in failure to download.
After making your selection, you can click to download. Two prompts will pop up before the first download. Just ignore them and continue downloading.
After downloading, open the LightBlue software on your phone (you can download it by searching Baidu on your phone), and then select the Bluetooth of WB415 to connect (I tried several times and it always took me several seconds to power off and restart the phone after downloading before the phone could search for Bluetooth. I don’t know if it was a problem with my operation). After the connection is successful, click the session window with the prefix 0000c101
Send 01, the red light on the development board lights up accordingly, and 00 turns off.
Send 02
After pressing the button on the development board, the yellow light turns on.
4. Code Analysis
The control aspect is mainly controlled by the at_cmd_handler function in the MCU project. The corresponding control function should also be written in the corresponding control logic.
void at_cmd_handler(void)
{
uint8_t msg_id = SIZEOFMSG-1, i;
if(recv_cmp_flag == SET)
{
for(i = 0; i <= SIZEOFMSG; i++)
{
if(memcmp(recv_data, at_cmd_list[i].at_cmd_string, strlen(recv_data)) == 0)
{
printf("%s", recv_data);
msg_id = i;
break;
}
}
switch(at_cmd_list[msg_id].msg_id)
{
case AT_CMD_IOSET0:
{
at32_led_off(LED2);
at_cmd_send(AT_RESULT_OK0);
break;
}
case AT_CMD_IOSET1:
{
at32_led_on(LED2);
at_cmd_send(AT_RESULT_OK1);
break;
}
case AT_CMD_IOGET:
{
if(gpio_output_data_bit_read(GPIOB, GPIO_PINS_7))
{
at_cmd_send(AT_RESULT_OK1);
}
else
{
at_cmd_send(AT_RESULT_OK0);
}
break;
}
default:
{
at_cmd_send(AT_RSP_ERROR);
break;
}
}
recv_cmp_flag = RESET;
memset(recv_data, 0, strlen(recv_data));
}
}