Bluetooth module-Data reading (USART)

The tutorial combines the Bluetooth module to demonstrate multi-serial communication.

Hardware connection

image-20240825211611726

Install the Bluetooth module to the corresponding interface:

Bluetooth moduleDevelopment board
VCCVCC
TXDRXD5
RXDTXD5
GNDGND

Control principle

The mobile phone is paired with the Bluetooth module (slave) on the balance car through the built-in Bluetooth (host). The Bluetooth module receives the data of the balance car APP and sends it to the development board for analysis.

Master-slave mode

The host is responsible for managing the communication process and controlling data transmission, while the slave performs corresponding operations according to the host's instructions.

Host mode

The controller in Bluetooth communication is responsible for initiating connection requests and controlling the entire communication process.

Slave mode

Passively wait for the host's connection request and accept the host's control.

Software configuration

Pin definition

Main control chipPinMain function (after reset)Default multiplexing functionRedefine function
STM32F103RCT6PD2PD2TIM3_ETR/USART5_RX/SDIO_CMD 
STM32F103RCT6PC12PC12USART5_TX/SDIO_CKUSART3_CK

Software code

Since the default function of the pin is the ordinary IO pin function, we need to use the default multiplexing function.

Control function

The tutorial only briefly introduces the code, and you can open the project source code to read it in detail.

uart_init

USART1_Send_U8

USART1_Send_ArrayU8

USART1_IRQHandler

bluetooth_init

UART5_Send_U8

UART5_Send_ArrayU8

UART5_IRQHandler

Experimental phenomenon

The Bluetooth.hex file generated by the project compilation is located in the OBJ folder of the Bluetooth project. Find the Bluetooth.hex file corresponding to the project and use the FlyMcu software to download the program into the development board.

After the program is successfully downloaded: the LED will flash. After connecting to Bluetooth using the APP, click the control button in the APP, and the development board serial port will print the corresponding command information.