加入星計(jì)劃,您可以享受以下權(quán)益:

  • 創(chuàng)作內(nèi)容快速變現(xiàn)
  • 行業(yè)影響力擴(kuò)散
  • 作品版權(quán)保護(hù)
  • 300W+ 專(zhuān)業(yè)用戶
  • 1.5W+ 優(yōu)質(zhì)創(chuàng)作者
  • 5000+ 長(zhǎng)期合作伙伴
立即加入

【智能家居挑戰(zhàn)賽】+ 智障小助手之使用RT1010驅(qū)動(dòng)SHT30讀取溫濕度的程序

05/17 08:23
2318
服務(wù)支持:
技術(shù)交流群

完成交易后在“購(gòu)買(mǎi)成功”頁(yè)面掃碼入群,即可與技術(shù)大咖們分享疑惑和經(jīng)驗(yàn)、收獲成長(zhǎng)和認(rèn)同、領(lǐng)取優(yōu)惠和紅包等。

虛擬商品不可退

當(dāng)前內(nèi)容為數(shù)字版權(quán)作品,購(gòu)買(mǎi)后不支持退換且無(wú)法轉(zhuǎn)移使用。

加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點(diǎn)資訊討論
放大
電路板圖(3)
相關(guān)方案
  • 方案介紹
  • 推薦器件
  • 相關(guān)推薦
  • 電子產(chǎn)業(yè)圖譜
申請(qǐng)入駐 產(chǎn)業(yè)圖譜

今天先來(lái)一篇使用RT1010驅(qū)動(dòng)SHT30讀取溫濕度的程序。

其中通信方式使用的是IIC,框圖如下:

其中命令是16位長(zhǎng)度。

比較核心的命令是數(shù)值查詢。發(fā)送指令0x2C06,返回為6字節(jié)的數(shù)組:

1[溫度高八位]

2[溫度第八位]

3[溫度crc校驗(yàn)]

4[濕度高八位]

5[濕度第八位]

6[濕度crc校驗(yàn)]

手冊(cè)也給出了溫濕度單位轉(zhuǎn)換方式。

 

IO初始化部分

  IOMUXC_SetPinMux(IOMUXC_GPIO_01_LPI2C1_SDA,1U);
                                       /* GPIO_01 is configured as LPI2C1_SDA */
                                       /* Software Input On Field: Force input path of pad GPIO_01 */
  IOMUXC_SetPinMux(IOMUXC_GPIO_02_LPI2C1_SCL,1U); 
                                       /* GPIO_02 is configured as LPI2C1_SCL */
                                       /* Software Input On Field: Force input path of pad GPIO_02 */
  IOMUXC_SetPinConfig(IOMUXC_GPIO_01_LPI2C1_SDA,0xD8B0U);
                                       /* GPIO_01 PAD functional properties : */
                                       /* Slew Rate Field: Slow Slew Rate
                                          Drive Strength Field: R0/6
                                          Speed Field: fast(150MHz)
                                          Open Drain Enable Field: Open Drain Enabled
                                          Pull / Keep Enable Field: Pull/Keeper Enabled
                                          Pull / Keep Select Field: Keeper
                                          Pull Up / Down Config. Field: 22K Ohm Pull Up
                                          Hyst. Enable Field: Hysteresis Disabled */
  IOMUXC_SetPinConfig(IOMUXC_GPIO_02_LPI2C1_SCL,0xD8B0U);
                                       /* GPIO_02 PAD functional properties : */
                                       /* Slew Rate Field: Slow Slew Rate
                                          Drive Strength Field: R0/6
                                          Speed Field: fast(150MHz)
                                          Open Drain Enable Field: Open Drain Enabled
                                          Pull / Keep Enable Field: Pull/Keeper Enabled
                                          Pull / Keep Select Field: Keeper
                                          Pull Up / Down Config. Field: 22K Ohm Pull Up
                                          Hyst. Enable Field: Hysteresis Disabled */

IIC初始化部分

const lpi2c_master_config_t ACCEL_I2C_masterConfig = {
    .enableMaster            = true,
    .enableDoze              = true,
    .debugEnable             = false,
    .ignoreAck               = false,
    .pinConfig               = kLPI2C_2PinOpenDrain,
    .baudRate_Hz             = 100000,
    .busIdleTimeout_ns       = 0,
    .pinLowTimeout_ns        = 0,
    .sdaGlitchFilterWidth_ns = 0,
    .sclGlitchFilterWidth_ns = 0,
    .hostRequest             = {
    .enable = false, .source = kLPI2C_HostRequestExternalPin, .polarity = kLPI2C_HostRequestPinActiveHigh}};
lpi2c_master_handle_t ACCEL_I2C_masterHandle;

        LPI2C_MasterInit(LPI2C1, &ACCEL_I2C_masterConfig, 60000000UL);
    LPI2C_MasterTransferCreateHandle(LPI2C1, &ACCEL_I2C_masterHandle, NULL, NULL);

IIC讀寫(xiě)函數(shù)

status_t BOARD_LPI2C_Send(LPI2C_Type *base,
                          uint8_t deviceAddress,
                          uint32_t subAddress,
                          uint8_t subAddressSize,
                          uint8_t *txBuff,
                          uint8_t txBuffSize)
{
    lpi2c_master_transfer_t xfer;

    xfer.flags          = kLPI2C_TransferDefaultFlag;
    xfer.slaveAddress   = deviceAddress;
    xfer.direction      = kLPI2C_Write;
    xfer.subaddress     = subAddress;
    xfer.subaddressSize = subAddressSize;
    xfer.data           = txBuff;
    xfer.dataSize       = txBuffSize;

    return LPI2C_MasterTransferBlocking(base, &xfer);
}

status_t BOARD_LPI2C_Receive(LPI2C_Type *base,
                             uint8_t deviceAddress,
                             uint32_t subAddress,
                             uint8_t subAddressSize,
                             uint8_t *rxBuff,
                             uint8_t rxBuffSize)
{
    lpi2c_master_transfer_t xfer;

    xfer.flags          = kLPI2C_TransferDefaultFlag;
    xfer.slaveAddress   = deviceAddress;
    xfer.direction      = kLPI2C_Read;
    xfer.subaddress     = subAddress;
    xfer.subaddressSize = subAddressSize;
    xfer.data           = rxBuff;
    xfer.dataSize       = rxBuffSize;

    return LPI2C_MasterTransferBlocking(base, &xfer);
}

主函數(shù)

SDK_DelayAtLeastUs(1000*1000, 600*1000*1000);
BOARD_LPI2C_Receive(LPI2C1, 0x44, 0x2C06, 2, sht30_buff, 6);

uint16_t tem = ((sht30_buff[0]<<8) | sht30_buff[1]);//溫度拼接                        
float Temperature= (175.0*(float)tem/65535.0-45.0) ;// T = -45 + 175 * tem / (2^16-1)/*轉(zhuǎn)換實(shí)際溫度*/

uint16_t hum = ((sht30_buff[3]<<8) | sht30_buff[4]);//濕度拼接
float Humidity= (100.0*(float)hum/65535.0);

uint8_t shi = Temperature/10;
uint8_t ge = Temperature - shi*10;
uint8_t sound[] = {'0'+shi, '0'+ge, 'C', ' '};

shi = Humidity/10;
ge = Humidity - shi*10;
uint8_t sound1[] = {'0'+shi, '0'+ge, '%', 'r', 'n'};

LPUART_WriteBlocking(LPUART1, sound, sizeof(sound) / sizeof(sound[0]));
LPUART_WriteBlocking(LPUART1, sound1, sizeof(sound1) / sizeof(sound1[0]));

效果

推薦器件

更多器件
器件型號(hào) 數(shù)量 器件廠商 器件描述 數(shù)據(jù)手冊(cè) ECAD模型 風(fēng)險(xiǎn)等級(jí) 參考價(jià)格 更多信息
PLR135/T5P 1 Everlight Electronics Co Ltd Receiver, 16Mbps, Panel Mount, ROHS COMPLIANT PACKAGE-3
$2.4 查看
HFBR-2416MZ 1 Foxconn Receiver, ST Connector, Through Hole Mount, ROHS COMPLIANT, PLASTIC, 8 PIN
$99.38 查看
SN74LVC1G32DCKR 1 Texas Instruments Single 2-input, 1.65-V to 5.5-V OR gate 5-SC70 -40 to 125

ECAD模型

下載ECAD模型
$0.36 查看

相關(guān)推薦

電子產(chǎn)業(yè)圖譜