当前位置:网站首页>STM32 drives hc05 Bluetooth serial port communication module
STM32 drives hc05 Bluetooth serial port communication module
2022-07-26 12:18:00 【W_ oilpicture】
Preface
Don't stumble on time , Tao cannot be empty .
Today, I would like to share what I learned recently HC05 Bluetooth module , By using Mobile phone Bluetooth control STM32 Single chip microcomputer Conduct Lighting 、 To transmit data 、 Display waveform And so on .
One 、 Introduce
HC05 Module is a high-performance master-slave Bluetooth serial port module , To put it bluntly , It's just a Bluetooth to serial device , You only need to know how to program the serial port , That's all right. , Realize the so-called transparent transmission .
preparation
- STM32H750VBT6
- IDE:Keil5
- STM32CubeMX
- VOFA+ Serial debugging
Two 、 Mobile phone Bluetooth control STM32 Single chip microcomputer
- Mobile phone via Bluetooth , towards
STM32SCM sends messages ,STM32After receiving the message, return it to the mobile phone intact , It can also be modified to , Mobile phones send specific messages , then ,STM32The single chip microcomputer makes the corresponding action . such as : Lighten up LED、 Start the motor 、 Display waveform wait .
Connection instructions :

Packet format :

3、 ... and 、STM32 Control procedures
/* USER CODE BEGIN Includes */
#include "stdio.h"
#include "math.h"
#include "stdarg.h"
#define CONSOLEBUF_SIZE 256
/* USER CODE END Includes */
/* USER CODE BEGIN PTD */
static char Uart_buf[CONSOLEBUF_SIZE];
void PrintfDebugUart(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
int length = vsnprintf(Uart_buf, sizeof(Uart_buf) - 1, fmt, args);
va_end(args);
HAL_UART_Transmit(&huart1, (uint8_t *)&Uart_buf, length, 0xffff);
}
/* USER CODE END PTD */
/* USER CODE BEGIN PD */
uint8_t RxBuffer[4]; // Variables that receive packets
uint8_t TxBuffer[4]; // Variables that send packets
uint8_t wave[100] = {
0};
/* USER CODE END PD */
/* USER CODE BEGIN 2 */
PrintfDebugUart("wang_Test.\r\n");
for(int i=0; i<100; i++)
{
wave[i] = (sin(2 * 3.1415926 * i / 100) + 1) * 100 / 2; // Virtual data
}
HAL_UART_Receive_IT(&huart1, RxBuffer, 4); // Cycle enable , Keep accepting
/* USER CODE END 2 */
/* USER CODE BEGIN 4 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) // Interrupt service function
{
if(huart == &huart1)
{
switch(RxBuffer[1])
{
case 1:
{
HAL_GPIO_WritePin(LED_GPIO_Port,LED_Pin,GPIO_PIN_RESET);
PrintfDebugUart("LED IS OFF.\r\n");
}break;
case 2:
{
HAL_GPIO_WritePin(LED_GPIO_Port,LED_Pin,GPIO_PIN_SET);
for(uint16_t i=0; i<100; i++)
{
TxBuffer[0] = 0xA5;
TxBuffer[1] = wave[i];
TxBuffer[2] = TxBuffer[1];
TxBuffer[3] = 0x5A;
HAL_UART_Transmit(&huart1,TxBuffer,4,0xffff);
}
PrintfDebugUart("LED IS OPEN.\r\n");
}break;
case 3:
{
PrintfDebugUart("Over.\r\n");
}
default:
{
;
}
}
HAL_UART_Receive_IT(&huart1, RxBuffer, 4); // Cycle enable , In order to continuously receive
}
}
/* USER CODE END 4 */
experimental result
Display waveform on mobile phone , And you can control the light on and off by pressing the key :

边栏推荐
- 剑指 Offer 24. 反转链表
- 干货|语义网、Web3.0、Web3、元宇宙这些概念还傻傻分不清楚?(中)
- 使用fastJson中的JSONObject对象简化POST请求传参
- Here blog: running a large language model in a production environment - overview of the reasoning framework
- pytest接口自动化测试框架 | 通过标记表达式执行用例
- 面试官:如何处理高并发?
- uniapp h5、app引用外部在线js
- Pytoch deep learning quick start tutorial -- mound tutorial notes (II)
- 需不需要上线MES系统,你在纠结什么?
- Digital intelligence transformation, management first | jnpf strives to build a "full life cycle management" platform
猜你喜欢

海外APP推送(下篇):海外厂商通道集成指南

字节流习题遇到的问题及解决方法

How do children's playgrounds operate?

FPGA入门学习(二) - 二选一的选择器

Ds-112 time relay

【2243】module_param.m

CVPR 2022 new SOTA for monocular depth estimation new CRFs: neural window fullyconnected CRFs

羽毛球馆的两个基础设施你了解多少?

Introduction to FPGA (I) - the first FPGA project

Ds-24c/dc220v time relay
随机推荐
Dry goods semantic web, Web3.0, Web3, metauniverse, these concepts are still confused? (medium)
uniapp h5、app引用外部在线js
2022 年要了解的新兴安全供应商
pytest接口自动化测试框架 | pytest配置文件
详解勒让德变换与共轭函数
Understand the string class
Industry case | how does the index help the sustainable development of Inclusive Finance in the banking industry
[MySQL constraint]
FPGA入门学习(三)- 38译码器
Detailed explanation of Legendre transformation and conjugate function
Use the jsonobject object in fastjason to simplify post request parameter passing
按位与怎么写SQL
大佬们,cdc oracle 怎么设置从指定scn号开始读取,或是怎么设置只读全量的归档,不去读取快
2022就业季!Adobe助力创意产业工作者,突破技能桎梏,回归能力本源
Pytoch deep learning quick start tutorial -- mound tutorial notes (II)
向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输
Ubenwa, a start-up under Mila, received an investment of US $2.5 million to study the AI diagnosis of infant health
.eslintrc.js configuration description
Hou Peixin, chairman of the openharmony Working Committee of the open atom open source foundation, sent a message to the openatom openharmony sub forum
了解string类