查看: 561|回复: 0

[经验] CC2541 迷你开发套件使用心得分享+ my love

[复制链接]

该用户从未签到

发表于 2021-1-11 17:15:07 | 显示全部楼层 |阅读模式
分享到:

一个SimpleBLEPeripheral项目。用到了UART,蓝牙通信不是用的串口,CC2541实现蓝牙通信可以不用串口。


  1. <p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">attWriteReq_t req;</span></p><p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">req.pValue = GATT_bm_alloc( simpleBLEConnHandle, ATT_WRITE_REQ, 1, NULL );
  2. if ( req.pValue != NULL )
  3. {
  4. req.handle = simpleBLECharHdl;
  5. req.len = 1;
  6. req.pValue[0] = simpleBLECharVal;
  7. req.sig = 0;
  8. req.cmd = 0;
  9. status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );</span></p>
复制代码


蓝牙主模块、CC2541连接成功。

CC2541往蓝牙主模块发送数据,蓝牙主模块是可以接收到的。

发送代码:

  1. <p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">if(BL_Flag==9)</span></p><p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">{</span></p><p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">BL_Flag=0;</span></p><p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">HAL_UART_Transmit (&huart1 ,(uint8_t *)(START),1,1500);</span></p><p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">flag=1;</span></p><p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">}</span></p><p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">if(BL_Flag==1)</span></p><p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">{</span></p><p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">BL_Flag=0;</span></p><p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">HAL_UART_Transmit (&huart1 ,(uint8_t *)(STO),1,1500);</span></p><p style="line-height: 28px; color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""><span style="font-size: 16px;">}</span></p>
复制代码

接收代码:

  1. attWriteReq_t req;

  2. req.pValue = GATT_bm_alloc( simpleBLEConnHandle, ATT_WRITE_REQ, 1, NULL );
  3. if ( req.pValue != NULL )
  4. {
  5. req.handle = simpleBLECharHdl;
  6. req.len = 1;
  7. req.pValue[0] = simpleBLECharVal;
  8. req.sig = 0;
  9. req.cmd = 0;
  10. status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /4 下一条



手机版|小黑屋|与非网

GMT+8, 2024-11-23 15:34 , Processed in 0.102759 second(s), 15 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.