[蓝牙芯片] CH582F+AHT30 软件i2c实现蓝牙notify温湿度数据

[复制链接]
 楼主| xiaoqi976633690 发表于 2023-12-6 19:20 | 显示全部楼层 |阅读模式
本帖最后由 xiaoqi976633690 于 2023-12-6 19:55 编辑

一、项目描述
1、项目介绍
  沁恒的蓝牙mcu还是很有性价比的,自己买了个芯片CH582F

01.png
00.png
嘉立创做了个小板子来学习蓝牙通信。并记录下来。
2、设计思路
本次设计思路比较的简单
a.通信部分是蓝牙ble5.0通信协议
b.TMOS 系统的任务和事件的创建
c.I2C读写实现(硬件搞半天没成功,直接用软件I2C)
d.温度传感器AHT30
通过tmos将这些模块组合起来使用
3、硬件
CH582F最小系统开发板+AHT30

二、软件流程图及各功能对应的主要代码片段及说明
介绍
1、流程图

02.png

2、代码片段说明
软件i2c实现
  1. #include "I2C.h"


  2. //模拟IIC初始化
  3. void I2CInit(void)
  4. {
  5.     SCL_out;
  6.     SDA_out;
  7. }


  8. void I2C_delay(void)
  9. {
  10.    mDelayuS(100);
  11. }

  12. int I2C_Start(void)
  13. {
  14.     SDA_H;
  15.     SDA_out;
  16.     SCL_H;
  17.     I2C_delay();
  18.     if(!SDA_read)return 0;    //SDA线为低电平则总线忙,退出
  19.     SDA_L;
  20.     I2C_delay();
  21.     if(SDA_read) return 0;    //SDA线为高电平则总线出错,退出
  22.     SDA_L;
  23.     I2C_delay();
  24.     return 1;
  25. }

  26. void I2C_Stop(void)
  27. {
  28.     SCL_L;
  29.     I2C_delay();
  30.     SDA_L;
  31.     SDA_out;
  32.     I2C_delay();
  33.     SCL_H;
  34.     I2C_delay();
  35.     SDA_H;
  36.     I2C_delay();
  37. }

  38. void I2C_Ack(void)
  39. {
  40.     SCL_L;
  41.     I2C_delay();
  42.     SDA_L;
  43.     SDA_out;
  44.     I2C_delay();
  45.     SCL_H;
  46.     I2C_delay();
  47.     I2C_delay();
  48.     SCL_L;
  49.     I2C_delay();
  50. }   

  51. void I2C_NoAck(void)
  52. {
  53.     SCL_L;
  54.     I2C_delay();
  55.     SDA_H;
  56.     SDA_out;
  57.     I2C_delay();
  58.     SCL_H;
  59.     I2C_delay();
  60.     SCL_L;
  61.     I2C_delay();
  62. }

  63. int I2C_WaitAck(void)      //返回为:=1有ACK,=0无ACK
  64. {
  65.     SCL_L;
  66.     I2C_delay();
  67.     I2C_delay();
  68.     SDA_in;
  69.     SCL_H;
  70.     I2C_delay();
  71.     I2C_delay();
  72.     if(SDA_read)
  73.     {
  74.         SCL_L;
  75.         return 0;
  76.     }
  77.     SCL_L;
  78.     return 1;
  79. }

  80. void I2C_SendByte(u8 SendByte) //数据从高位到低位//
  81. {
  82.     u8 i=8;
  83.     SDA_out;
  84.     while(i--)
  85.     {
  86.         SCL_L;
  87.         I2C_delay();
  88.         if(SendByte&0x80)
  89.             SDA_H;
  90.         else
  91.             SDA_L;
  92.         SendByte<<=1;
  93.         I2C_delay();
  94.         SCL_H;
  95.         I2C_delay();
  96.         I2C_delay();
  97.     }
  98.     SCL_L;
  99. }  

  100. u8 I2C_ReadByte(void)  //数据从高位到低位//
  101. {
  102.     u8 i=8;
  103.     u8 ReceiveByte=0;

  104.     SDA_H;
  105.     SDA_out;
  106.     while(i--)
  107.     {
  108.         ReceiveByte<<=1;
  109.         SCL_L;
  110.         I2C_delay();
  111.         I2C_delay();
  112.         SCL_H;
  113.         SDA_in;
  114.         I2C_delay();
  115.         I2C_delay();
  116.         if(SDA_read)
  117.         {
  118.             ReceiveByte|=0x01;
  119.         }
  120.     }
  121.     SCL_L;
  122.     return ReceiveByte;
  123. }

  124. //7bit地址单字节写入*******************************************
  125. int I2C_7bit_Single_Write(u8 SlaveAddress, u8 REG_data)
  126. {
  127.     if(!I2C_Start())return 0;
  128.     I2C_SendByte(SlaveAddress);   //发送设备地址+写信号//I2C_SendByte(((REG_Address & 0x0700) >>7) | SlaveAddress & 0xFFFE);//设置高起始地址+器件地址
  129.     if(!I2C_WaitAck()){I2C_Stop(); return 0;}
  130.     I2C_SendByte(REG_data);
  131.     I2C_WaitAck();    I2C_Stop();
  132.     return 1;
  133. }

  134. //7bit地址单字节读取*****************************************
  135. u8 I2C_7bit_Single_Read(u8 SlaveAddress)
  136. {   
  137.     unsigned char REG_data;
  138.     if(!I2C_Start())return 0;
  139.     I2C_SendByte(SlaveAddress); //I2C_SendByte(((REG_Address & 0x0700) >>7) | REG_Address & 0xFFFE);//设置高起始地址+器件地址
  140.     if(!I2C_WaitAck())
  141.     {
  142.         I2C_Stop();
  143.         return 0;
  144.     }
  145.     I2C_Start();
  146.     I2C_SendByte(SlaveAddress+1);
  147.     I2C_WaitAck();

  148.     REG_data= I2C_ReadByte();
  149.     I2C_NoAck();
  150.     I2C_Stop();
  151.     //return TRUE;
  152.     return REG_data;

  153. }

  154. //7bit地址多字节读取*****************************************
  155. int I2C_7bit_Mult_Read(u8 SlaveAddress,u8 * ptChar,u8 size)
  156. {
  157.     u8 i;

  158.     if(size < 1)
  159.         return 0;
  160.     if(!I2C_Start())
  161.         return 0;
  162.     I2C_SendByte(SlaveAddress);
  163.     if(!I2C_WaitAck())
  164.     {
  165.         I2C_Stop();
  166.         return 0;
  167.     }
  168.     I2C_Start();
  169.     I2C_SendByte(SlaveAddress+1);
  170.     I2C_WaitAck();

  171.     for(i=1;i<size; i++)
  172.     {
  173.         *ptChar++ = I2C_ReadByte();
  174.         I2C_Ack();
  175.     }
  176.     *ptChar++ = I2C_ReadByte();
  177.     I2C_NoAck();
  178.     I2C_Stop();
  179.     return 1;
  180. }



  181. //10bit地址单字节写入*******************************************
  182. int I2C_10bit_Single_Write(u8 SlaveAddress,u8 REG_Address,u8 REG_data)
  183. {
  184.     if(!I2C_Start())return 0;
  185.     I2C_SendByte(SlaveAddress);   //发送设备地址+写信号//I2C_SendByte(((REG_Address & 0x0700) >>7) | SlaveAddress & 0xFFFE);//设置高起始地址+器件地址
  186.     if(!I2C_WaitAck()){I2C_Stop(); return 0;}
  187.     I2C_SendByte(REG_Address );   //设置低起始地址
  188.     I2C_WaitAck();
  189.     I2C_SendByte(REG_data);
  190.     I2C_WaitAck();
  191.     I2C_Stop();
  192.     return 1;
  193. }

  194. //10bit地址单字节读取*****************************************
  195. u8 I2C_10bit_Single_Read(u8 SlaveAddress,u8 REG_Address)
  196. {   
  197.     unsigned char REG_data;
  198.     if(!I2C_Start())return 0;
  199.     I2C_SendByte(SlaveAddress); //I2C_SendByte(((REG_Address & 0x0700) >>7) | REG_Address & 0xFFFE);//设置高起始地址+器件地址
  200.     if(!I2C_WaitAck())
  201.     {
  202.         I2C_Stop();
  203.         return 0;
  204.     }
  205.     I2C_SendByte((u8) REG_Address);   //设置低起始地址
  206.     I2C_WaitAck();
  207.     I2C_Start();
  208.     I2C_SendByte(SlaveAddress+1);
  209.     I2C_WaitAck();

  210.     REG_data= I2C_ReadByte();
  211.     I2C_NoAck();
  212.     I2C_Stop();
  213.     //return TRUE;
  214.     return REG_data;

  215. }

  216. //10bit地址多字节读取*****************************************
  217. int I2C_10bit_Mult_Read(u8 SlaveAddress,u8 REG_Address,u8 * ptChar,u8 size)
  218. {
  219.     u8 i;

  220.     if(size < 1)
  221.         return 0;
  222.     if(!I2C_Start())
  223.         return 0;
  224.     I2C_SendByte(SlaveAddress);
  225.     if(!I2C_WaitAck())
  226.     {
  227.         I2C_Stop();
  228.         return 0;
  229.     }
  230.     I2C_SendByte(REG_Address);
  231.     I2C_WaitAck();

  232.     I2C_Start();
  233.     I2C_SendByte(SlaveAddress+1);
  234.     I2C_WaitAck();

  235.     for(i=1;i<size; i++)
  236.     {
  237.         *ptChar++ = I2C_ReadByte();
  238.         I2C_Ack();
  239.     }
  240.     *ptChar++ = I2C_ReadByte();
  241.     I2C_NoAck();
  242.     I2C_Stop();
  243.     return 1;
  244. }
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name          : I2C.h
  3. * Author             : WCH
  4. * Version            : V1.0
  5. * Date               : 2018/12/15
  6. * Description                  :
  7. *******************************************************************************/

  8. #ifndef __I2C_SOFT2_H__
  9. #define __I2C_SOFT2_H__
  10. #include "CH58x_common.h"

  11. #ifndef UINT8
  12. typedef unsigned char           u8;
  13. #endif
  14. #define I2C_Pin_SCL                GPIO_Pin_13
  15. #define I2C_Pin_SDA                GPIO_Pin_12

  16. #define SCL_H         GPIOB_SetBits( I2C_Pin_SCL )
  17. #define SCL_L         GPIOB_ResetBits( I2C_Pin_SCL )
  18. #define SDA_H         GPIOB_SetBits( I2C_Pin_SDA )
  19. #define SDA_L         GPIOB_ResetBits( I2C_Pin_SDA )
  20. #define SCL_read      GPIOB_ReadPortPin( I2C_Pin_SCL )
  21. #define SDA_read      GPIOB_ReadPortPin( I2C_Pin_SDA )
  22. #define SCL_out              GPIOB_ModeCfg(I2C_Pin_SCL, GPIO_ModeOut_PP_5mA)
  23. #define SCL_in              GPIOB_ModeCfg(I2C_Pin_SCL, GPIO_ModeIN_PU)
  24. #define SDA_out              GPIOB_ModeCfg(I2C_Pin_SDA, GPIO_ModeOut_PP_5mA)
  25. #define SDA_in              GPIOB_ModeCfg(I2C_Pin_SDA, GPIO_ModeIN_PU)
  26.                         

  27. void I2CInit(void);  
  28. int I2C_7bit_Single_Write(u8 SlaveAddress, u8 REG_data);

  29. u8 I2C_7bit_Single_Read(u8 Slave7BitAddress);

  30. int I2C_7bit_Mult_Read(u8 Slave7BitAddress,u8 * ptChar,u8 size);

  31. int I2C_10bit_Single_Write(u8 SlaveAddress,u8 REG_Address,u8 REG_data);        
  32. u8 I2C_10bit_Single_Read(u8 SlaveAddress,u8 REG_Address);
  33. int I2C_10bit_Mult_Read(u8 SlaveAddress,u8 REG_Address,u8 * ptChar,u8 size);

  34. void I2C_delay(void);
  35. int I2C_Start(void);
  36. void I2C_Stop(void);
  37. void I2C_Ack(void);
  38. void I2C_NoAck(void);
  39. int I2C_WaitAck(void);          //返回为:=1有ACK,=0无ACK
  40. void I2C_SendByte(u8 SendByte);
  41. u8 I2C_ReadByte(void);  //数据从高位到低位//


  42. #endif


AHT30初始化
  1. void Init_AHTx0(uint8_t address)
  2. {
  3.     uint8_t com[3]={0xBE,0x08,0x00};
  4.     I2C_Write_Byte(address,com,3);
  5.     printf("Init_AHTx0 OK\n");
  6.     DelayMs(100);
  7. }
AHT30读写函数
  1. uint8_t I2C_Write_Byte(uint8_t addr_7bit ,uint8_t  * data, uint8_t len)
  2. {
  3.     uint8_t i=0;
  4.     if(!I2C_Start())return 0;
  5.     I2C_SendByte(addr_7bit<<1);
  6.     if(!I2C_WaitAck()){I2C_Stop(); return 0;}
  7.     for(i=0;i<len;i++)
  8.     {
  9.         I2C_SendByte(data[i]);
  10.         I2C_WaitAck();
  11.     }
  12.     I2C_Stop();
  13.     return 1;

  14. }
  1. uint8_t I2C_Read_Byte(uint8_t addr_7bit, uint8_t *data, uint8_t len)
  2. {
  3.     uint8_t i=0;
  4.     if(!I2C_Start())return 0;
  5.     I2C_SendByte((addr_7bit<<1)|0x01);   //bit7:1 为读
  6.     if(!I2C_WaitAck()){I2C_Stop(); return 0;}
  7.     while(i<(len-1))
  8.     {
  9.         data[i]= I2C_ReadByte();
  10.         I2C_Ack();
  11.         i++;
  12.     }
  13.     data[i]= I2C_ReadByte();
  14.     I2C_NoAck();
  15.     I2C_Stop();
  16.     return 1;
  17. }

1.上电后要等待40ms,读取温湿度值之前, 首先要看状态字的校准使能位Bit[3]是否为 1(通过发送0x71可以获取一个字节的状态字),如果不为1,要发送0xBE命令(初始化),此命令参数有两个字节, 第一个字节为0x08,第二个字节为0x00。
  1. uint8_t com_init[3]={0xbe,0x08,0x00};//0xbe

2.直接发送 0xAC命令(触发测量),此命令参数有两个字节,第一个字节为 0x33,第二个字节为0x00。
3.等待75ms待测量完成,忙状态Bit[7]为0,然后可以读取六个字节(发0X71即可以读取)。
4.计算温湿度值。
  1. #define  buff_size 6
  2.   uint8_t com_read[3]={0xac,0x33,0x00};//0xac
  3.   uint8_t temprature_buff[buff_size]={0x00,0x00,0x00,0x00,0x00,0x00};
  4.   uint8_t t[20];
  1. void Get_tmprature(void)
  2. {

  3.     I2C_Write_Byte(0x38,com_read,3);//开始测量
  4.     DelayMs(150);
  5.     I2C_Read_Byte(0x38,temprature_buff,buff_size);//读取温湿度
  6.     Temp_Huimt(temprature_buff,t);

  7. }
  1. void Temp_Huimt(uint8_t * arr,uint8_t * t)
  2. {
  3.     int32_t  temp;
  4.     int32_t  humit;
  5.     humit =arr[1];
  6.     humit=((humit)<<8)|arr[2];
  7.     humit=((humit)<<4)|(arr[3]>>4);
  8.     temp =arr[3]&0x0f;
  9.     temp=((temp)<<8)|arr[4];
  10.     temp=((temp)<<8)|arr[5];
  11.     sprintf(t,"h=%.2f,t=%.2f\n\r",(float)humit*100/1048576,(float)temp*200/1048576-50);
  12. }



蓝牙部分
创建server
创建特性
  1. <blockquote>#define SIMPLEPROFILE_CHAR1         0           // RW uint8_t - Profile Characteristic 1 value

  1. // Simple Profile Characteristic 4 Properties
  2. static uint8_t simpleProfileChar4Props = GATT_PROP_NOTIFY;

  3. // Characteristic 4 Value
  4. static uint8_t simpleProfileChar4[SIMPLEPROFILE_CHAR4_LEN] = {0};

  5. // Simple Profile Characteristic 4 Configuration Each client has its own
  6. // instantiation of the Client Characteristic Configuration. Reads of the
  7. // Client Characteristic Configuration only shows the configuration for
  8. // that client and writes only affect the configuration of that client.
  9. static gattCharCfg_t simpleProfileChar4Config[PERIPHERAL_MAX_CONNECTION];

  10. // Simple Profile Characteristic 4 User Description
  11. static uint8_t simpleProfileChar4UserDesp[] = "Characteristic 4\0";

03.png

添加server服务
  1.     SimpleProfile_AddService(GATT_ALL_SERVICES); // Simple GATT Profile
初始化蓝牙
  1. void Peripheral_Init()
  2. {
  3.     //将事件的回调函数注册到 TMOS 中
  4.     Peripheral_TaskID = TMOS_ProcessEventRegister(Peripheral_ProcessEvent);

  5.     // Setup the GAP Peripheral Role Profile
  6.     {
  7.         uint8_t  initial_advertising_enable = TRUE;
  8.         uint16_t desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
  9.         uint16_t desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;

  10.         // Set the GAP Role Parameters
  11.         GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initial_advertising_enable);//使能广播
  12.         GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), scanRspData);//扫描回复数据,数据格式要遵循广播数据格式
  13.         GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);//扫描回复数据,数据格式要遵循广播数据格式
  14.         GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t), &desired_min_interval);//最小连接间隔
  15.         GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t), &desired_max_interval);//最大连接间隔
  16.     }

  17.     // Set the GAP Characteristics
  18.     GGS_SetParameter(GGS_DEVICE_NAME_ATT, sizeof(attDeviceName), attDeviceName);//GAP特征,设备名称

  19.     {
  20.         uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL;

  21.         // Set advertising interval
  22.         GAP_SetParamValue(TGAP_DISC_ADV_INT_MIN, advInt);
  23.         GAP_SetParamValue(TGAP_DISC_ADV_INT_MAX, advInt);

  24.         // Enable scan req notify
  25.         GAP_SetParamValue(TGAP_ADV_SCAN_REQ_NOTIFY, ENABLE);
  26.     }

  27.     // Setup the GAP Bond Manager
  28.     {
  29.         uint32_t passkey = 0; // passkey "000000"
  30.         uint8_t  pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
  31.         uint8_t  mitm = TRUE;
  32.         uint8_t  bonding = TRUE;
  33.         uint8_t  ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
  34.         GAPBondMgr_SetParameter(GAPBOND_PERI_DEFAULT_PASSCODE, sizeof(uint32_t), &passkey);
  35.         GAPBondMgr_SetParameter(GAPBOND_PERI_PAIRING_MODE, sizeof(uint8_t), &pairMode);
  36.         GAPBondMgr_SetParameter(GAPBOND_PERI_MITM_PROTECTION, sizeof(uint8_t), &mitm);
  37.         GAPBondMgr_SetParameter(GAPBOND_PERI_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
  38.         GAPBondMgr_SetParameter(GAPBOND_PERI_BONDING_ENABLED, sizeof(uint8_t), &bonding);
  39.     }

  40.     // Initialize GATT attributes
  41. //    GGS_AddService(GATT_ALL_SERVICES);           // GAP
  42. //    GATTServApp_AddService(GATT_ALL_SERVICES);   // GATT attributes
  43. //    DevInfo_AddService();                        // Device Information Service
  44.     SimpleProfile_AddService(GATT_ALL_SERVICES); // Simple GATT Profile

  45.     // Setup the SimpleProfile Characteristic Values
  46.     {
  47.         uint8_t charValue1[SIMPLEPROFILE_CHAR1_LEN] = {1};
  48.         uint8_t charValue2[SIMPLEPROFILE_CHAR2_LEN] = {2};
  49.         uint8_t charValue3[SIMPLEPROFILE_CHAR3_LEN] = {3};
  50.         uint8_t charValue4[SIMPLEPROFILE_CHAR4_LEN] = {4};
  51.         uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = {1, 2, 3, 4, 5};
  52.         uint8_t charValue6[SIMPLEPROFILE_CHAR6_LEN] = {'X','Q','-','B','L','E',0x0a};
  53.         SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR1, SIMPLEPROFILE_CHAR1_LEN, charValue1);
  54.         SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR2, SIMPLEPROFILE_CHAR2_LEN, charValue2);
  55.         SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR3, SIMPLEPROFILE_CHAR3_LEN, charValue3);
  56.         SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR4, SIMPLEPROFILE_CHAR4_LEN, charValue4);
  57.         SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5);
  58.         SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR6, SIMPLEPROFILE_CHAR6_LEN, charValue6);
  59.     }

  60.     // Init Connection Item
  61.     peripheralInitConnItem(&peripheralConnList);

  62.     // Register callback with SimpleGATTprofile
  63.     SimpleProfile_RegisterAppCBs(&Peripheral_SimpleProfileCBs);

  64.     // Register receive scan request callback
  65.     GAPRole_BroadcasterSetCB(&Broadcaster_BroadcasterCBs);

  66.     // Setup a delayed profile startup
  67.     tmos_set_event(Peripheral_TaskID, SBP_START_DEVICE_EVT); //启动Peripheral_TaskID任务下的SBP_START_DEVICE_EVT事件,其中tmos_set_event函数用于立刻执行某个事件
  68.     tmos_start_reload_task(Peripheral_TaskID, TASK_1,3200);//启动一个循环事件
  69.     tmos_start_reload_task(Peripheral_TaskID,TASK_TEMPRATURE,2200);//启动一个温湿度循环事件
  70. }
事件轮询
  1. uint16_t Peripheral_ProcessEvent(uint8_t task_id, uint16_t events)
  2. {
  3.     //  VOID task_id; // TMOS required parameter that isn't used in this function

  4.     if(events & SYS_EVENT_MSG)
  5.     {
  6.         uint8_t *pMsg;

  7.         if((pMsg = tmos_msg_receive(Peripheral_TaskID)) != NULL)
  8.         {
  9.             Peripheral_ProcessTMOSMsg((tmos_event_hdr_t *)pMsg);
  10.             // Release the TMOS message
  11.             tmos_msg_deallocate(pMsg);
  12.         }
  13.         // return unprocessed events
  14.         return (events ^ SYS_EVENT_MSG);
  15.     }

  16.     if(events & SBP_START_DEVICE_EVT)
  17.     {
  18.         // Start the Device
  19.         GAPRole_PeripheralStartDevice(Peripheral_TaskID, &Peripheral_BondMgrCBs, &Peripheral_PeripheralCBs);
  20.         return (events ^ SBP_START_DEVICE_EVT);
  21.     }

  22.     if(events & SBP_PERIODIC_EVT)
  23.     {
  24.         // Restart timer
  25.         if(SBP_PERIODIC_EVT_PERIOD)
  26.         {
  27.             tmos_start_task(Peripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);
  28.         }
  29.         // Perform periodic application task
  30.         performPeriodicTask();

  31.         return (events ^ SBP_PERIODIC_EVT);
  32.     }

  33.     if(events & SBP_PARAM_UPDATE_EVT)
  34.     {
  35.         // Send connect param update request
  36.         GAPRole_PeripheralConnParamUpdateReq(peripheralConnList.connHandle,
  37.                                              DEFAULT_DESIRED_MIN_CONN_INTERVAL,
  38.                                              DEFAULT_DESIRED_MAX_CONN_INTERVAL,
  39.                                              DEFAULT_DESIRED_SLAVE_LATENCY,
  40.                                              DEFAULT_DESIRED_CONN_TIMEOUT,
  41.                                              Peripheral_TaskID);

  42.         return (events ^ SBP_PARAM_UPDATE_EVT);
  43.     }

  44.     if(events & SBP_PHY_UPDATE_EVT)
  45.     {
  46.         // start phy update
  47.         PRINT("PHY Update %x...\n", GAPRole_UpdatePHY(peripheralConnList.connHandle, 0,
  48.                     GAP_PHY_BIT_LE_2M, GAP_PHY_BIT_LE_2M, GAP_PHY_OPTIONS_NOPRE));

  49.         return (events ^ SBP_PHY_UPDATE_EVT);
  50.     }

  51.     if(events & SBP_READ_RSSI_EVT)
  52.     {
  53.         GAPRole_ReadRssiCmd(peripheralConnList.connHandle);
  54.         tmos_start_task(Peripheral_TaskID, SBP_READ_RSSI_EVT, SBP_READ_RSSI_EVT_PERIOD);
  55.         return (events ^ SBP_READ_RSSI_EVT);
  56.     }
  57.     if(events & TASK_1)
  58.     {

  59.         Get_temp();
  60.         return (events ^ TASK_1);
  61.     }
  62.     if(events & TASK_TEMPRATURE)
  63.     {
  64.         Get_tmprature();
  65.         Temp_Huimt(temprature_buff,t);
  66.         printf("%s\n",t);
  67.         return (events ^ TASK_TEMPRATURE);
  68.     }

  69.     // Discard unknown events
  70.     return 0;
  71. }


三、功能展示及说明
06.jpg
手机链接蓝牙
04.jpg 05.jpg


07.jpg
chenjun89 发表于 2023-12-8 20:02 来自手机 | 显示全部楼层
沁恒的产品线越来越丰富了
超能电子 发表于 2023-12-21 16:29 | 显示全部楼层
蓝牙的稳定性如何?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

35

主题

204

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部

35

主题

204

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部