CSR101x BLE芯片 简简单单实现一个 温湿度BLE 传感器结点

CSR101x ble 结点

由于工作的性质,手头有许多Csr101X beacon开发板,想利用这些开发板做几个温度湿度的sensor ble 节点设备,进行 Ble 组网的测试。于是,开始动手,并把整个过程记录下来,希望对同行有个帮助。事情 并不复杂,代码量也不大。纯属个人消遣。

开发软件和硬件

IDE环境: csr uEngery SDK 2.6.3.12(xIDE) ,软件包里带了一些应用场景的例子。
演示软件:CSR uEnergy Profile Demonstrator 2.6.2.1
BLE demo板 :CSR1010 shelf Tag
温湿度传感器:SHT21 工业级温度湿度传感器(I2C)

硬件原理图和硬件连接

这里参考的是Csr1010 shelf tag 原理图,Csr1010 作为一个ble 结点方案的实现还是有很大的优势的。电路很简单,profile的参考例子也很多,不用购买license。适合初学者上手。
起初,想把 SHT21的传感器连接到I2c flash 的总线上,但是代码中并没有这样实现,为了方便起见,充分利用了 空闲的GPIO,用于连接 SHT21 传感器。
原理图参考如下,如果需要完整的原理图可与我单独联系。
csr1010 原理图PIO(0) SCL 用于连接 SHT21 的 SCL pin
PIO(1) SDA 用于连接 SHT21的 SDA pin
VDD_BAT 连接SHT21 的VDD
GND 连接SHT21 的GND

软件的修改

这里选择Environment sensor 工程的例子
在这里插入图片描述在软件定义中 user_config.h 中定义了I2c 数据线的配置
/* I2C communication lines */
#define I2C_SCL_PIO (1)
#define I2C_SDA_PIO (0)

在user_config.h 配置文件中

定义#define INCLUDE_TEMPERATURE_SENSING 使能温度传感器功能,

使能SHT21 传感器的支持
在这里插入图片描述定义 #define INCLUDE_HUMIDITY_SENSING 使能SHT21 对湿度的支持
在这里插入图片描述在humidity_sensor.h 添加SHT21 湿度支持文件
在这里插入图片描述添加温度读写的代码
在sht21_humidity_sensor.c 文件中添加如下代码

extern bool SHT21_ReadBlocking_temp(int16 *p_tempture)
{
    int32 temperture_value = 0; /* Humidity value requires only 16bits but to 
                                * avoid overflow while doing calculations, the 
                                * value has been defined as uint32.
                                */
    uint8 temperture[2] = {0};
    bool success = FALSE;
    uint8 poll_wait = 0;
    if(I2CAcquire())
    {
        /* Initialise I2C */
        I2CcommsInit();

         TimeDelayUSec(5 * MILLISECOND);
        /* Write command for humidity measurement in NO Hold mode */
        success = sht21_writeCommand(SHT21_I2C_ADDRESS, 
                           SHT21_TRIGGER_T_MEASUREMENT_NO_HOLD_MODE);

        if(success)
        {
            /* The sensor takes maximum 30ms for humidity measurement. */
            TimeDelayUSec(5 * MILLISECOND);
            do{
                success = sht21_readTwoBytes(SHT21_I2C_ADDRESS, &temperture[0]);
                poll_wait++;
                TimeDelayUSec(2 * MILLISECOND);
              }while((poll_wait < MAX_MEASUREMENT_TIME) && (!success));
            if(success)
            {
                /* 4 LSBs should be converted to zeros. */
                temperture_value= (((uint32 )temperture[0])<<8) | 
                                  ((uint32 )(temperture[1] & 0xFC));

                /* Conversion of Signal Output:
                 * Default resolution is set to 12 bit relative humidity and 14
                 * bit temperature reading. Measured data are transferred in
                 * two byte packages, i.e. in frames of 8 bit length where the
                 * most significant bit (MSB) is transferred first (left 
                 * aligned).Each byte is followed by an acknowledge bit. The 
                 * twostatus bits, the last bits of LSB, must be set to 0 
                 * before calculating physical values. 
                 *
                 * Relative Humidity Conversion
                 * With the relative humidity signal output SRH the relative
                 * humidity RH is obtained by the following formula (result in
                 * %RH), no matter which resolution is chosen:
                 * 
                  * RH = -6 + (125*(SRH/2^16))
                 *
                 * T = -46.85 +(175.72 *(SRT/2^12))
                 */

                /* Since the application needs to send humidity percentage with 
                 * a resolution of 0.01 percent, multiply by 100.
                 */
                temperture_value= (( temperture_value *17500)/65536) - (4685);

                *p_tempture= (int16)temperture_value;
            }
        }

        /* Release the I2C bus */
        I2CRelease();
    }
    return(success);
}

软件和硬件修改完后,编译并且通过下载器下载到csr1010 tag 的开发板中
demo 板如下
在这里插入图片描述在这里插入图片描述

DEMO的演示

我们使用CSR 软件包中提供 CSR uEnergy Profile Demonstrate 2.6.2.1软件
扫描,配对后,便可以获得BLE 节点 发送过来的温度和湿度的结果。
强调文本 强调文本

在这里插入图片描述

参考文档:
【1】 cs-331349-DD-1 cns12015 beacon board schematic.pdf

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

redparrot2008

打赏+收藏,私信获得部分资源。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值