初学者
10 分钟

使用HTU31D和MK64FN1M0VDC12,在您指尖体验完美气候

呼吸轻松,享受我们的气候魔力

Temp&Hum 14 Click with Clicker 2 for Kinetis

已发布 6月 27, 2024

点击板

Temp&Hum 14 Click

开发板

Clicker 2 for Kinetis

编译器

NECTO Studio

微控制器单元

MK64FN1M0VDC12

依靠我们的气候解决方案,提供有价值的温度和湿度洞察,为更智能、更可持续的未来做出贡献。

A

A

硬件概览

它是如何工作的?

Temp&Hum 14 Click基于HTU31D,这是TE Connectivity公司生产的数字相对湿度传感器,具有温度输出。HTU31D内部的两个传感器都经过了单独校准、补偿和测试。湿度可在0到100%RH的范围内测量,而温度传感器设计范围为-40到125°C。在环境温度下,湿度的典型精度为±2%RH(在20%RH至100%RH的测量范围内),温度为±0.2°C(在0°C至100°C之间),功耗最低可达3.78μW。该Click board™是一款I2C可配置的环境传感器,具有高可靠性和完全互换性,在标准条件下无需校

准。在饱和阶段长时间后,该传感器具有快速恢复时间,低功耗和快速响应时间。此外,即使在高达125°C的极端温度和湿度环境下,该传感器也能提供持续的性能。Temp & Hum 14 Click通过标准的I2C 2-Wire接口与MCU通信,最大频率为10MHz。HTU31D可以回答2个I2C地址,并允许通过将标有ADDR SEL的SMD跳线放置到标有0和1的适当位置来选择最低有效位(LSB)。除了此功能之外,该Click board™还包含额外的功能,通过mikroBUS™插座上的RST引脚进行路由。RST引脚可以生成一个传感

器复位,此功能所需的最小脉冲持续时间为1μs。HTU31D还提供了一个诊断寄存器,可用于检查湿度和温度值是否超出了指定范围。CRC检查(循环冗余校验)确保了安全的数据传输。湿度和温度信号响应时间以及恢复时间(在完全冷凝之后)在几秒钟内。该Click board™可以使用3.3V或5V逻辑电压级别运行,通过VCC SEL跳线选择。这样,既能够使3.3V和5V的MCU正常使用通信线路。此外,该Click board™配备了包含易于使用的功能和示例代码的库,可用作进一步开发的参考。

Temp&Hum 14 Click hardware overview image

功能概述

开发板

Clicker 2 for Kinetis 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位 ARM Cortex-M4F 微控制器,NXP 半导体公司的 MK64FN1M0VDC12,两个 mikroBUS™ 插槽用于 Click 板™连接,一个 USB 连接器,LED 指示灯,按钮,一个 JTAG 程序员连接器以及两个 26 针头用于与外部电子设备的接口。其紧凑的设计和清晰、易识别的丝网标记让您能够迅速构建具有独特功能和特性

的小工具。Clicker 2 for Kinetis 开发套件的每个部分 都包含了使同一板块运行最高效的必要组件。除了可以选择 Clicker 2 for Kinetis 的编程方式,使用 USB HID mikroBootloader 或外部 mikroProg 连接器进行 Kinetis 编程外,Clicker 2 板还包括一个干净且调节过的开发套件电源供应模块。它提供了两种供电方式;通过 USB Micro-B 电缆,其中板载电压调节器为板上每个组件提供适当的电压水平,或使用锂聚合物 电池通过板载电池连接器供电。所有 mikroBUS™ 本

身支持的通信方法都在这块板上,包括已经建立良好的 mikroBUS™ 插槽、重置按钮和几个用户可配置的按钮及 LED 指示灯。Clicker 2 for Kinetis 是 Mikroe 生态系统的一个组成部分,允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。

Clicker 2 for Kinetis dimensions image

微控制器概述 

MCU卡片 / MCU

default

建筑

ARM Cortex-M4

MCU 内存 (KB)

1024

硅供应商

NXP

引脚数

121

RAM (字节)

262144

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
PB11
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PD8
SCL
I2C Data
PD9
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Temp&Hum 14 Click Schematic schematic

一步一步来

项目组装

Clicker 2 for PIC32MZ front image hardware assembly

从选择您的开发板和Click板™开始。以Clicker 2 for Kinetis作为您的开发板开始。

Clicker 2 for PIC32MZ front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product7 hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

软件支持

库描述

该库包含 Temp&Hum 14 Click 驱动程序的 API。

关键功能:

  • temphum14_set_conversion - 设置将单个温度和湿度转换为HTU31D的数据分辨率的函数

  • temphum14_read_t_and_rh - 读取HTU31D的温度和湿度数据的函数

  • temphum14_get_temp_and_hum - 获取HTU31D的温度和湿度数值的函数

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief TempHum14 Click example
 *
 * # Description
 * This is an example that demonstrates the use of the Temp-Hum 14 Click board.
 * Temp-Hum 14 Click board can be used to measure temperature
 * and relative humidity.
 * All data logs write on USB uart changes every 3 sec.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialization driver enables I2C, and
 * hardware reset the device and read the serial number.
 *
 * ## Application Task
 * Reading temperature and humidity, and loging it on the USB uart. 
 * 
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "temphum14.h"

static temphum14_t temphum14;
static log_t logger;
static temphum14_diagn_t status_data;
static float temperature;
static float humidity;
uint32_t ser_numb;

void display_diagnostic ( void ) {
    log_printf( &logger, "-----------------------------\r\n" );
    log_printf( &logger, "\r\n NVM Error        :" );
    if ( status_data.nvm_error == TEMPHUM14_STATUS_ON ) {
        log_printf( &logger, " Error \r\n" );
    } else {
        log_printf( &logger, " No Error \r\n" );
    }

    log_printf( &logger, "\r\n Humidity U/O     :" );
    if ( status_data.hum_un_over == TEMPHUM14_STATUS_ON ) {
        log_printf( &logger, " Under/Overrun \r\n" );
    } else {
        log_printf( &logger, " No Error \r\n" );
    }

    log_printf( &logger, "\r\n Humidity Error   :" );
    if ( status_data.hum_h_err == TEMPHUM14_STATUS_ON ) {
        log_printf( &logger, " Below -10%% RH \r\n" );
    } else if ( status_data.hum_l_err == TEMPHUM14_STATUS_ON ) {
        log_printf( &logger, " Above 120%% RH \r\n" );
    } else {
        log_printf( &logger, " No Error \r\n" );
    }
    
    log_printf( &logger, "\r\n Temperature U/O  :" );
    if ( status_data.temp_un_over == TEMPHUM14_STATUS_ON ) {
        log_printf( &logger, " Under/Overrun \r\n" );
    } else {
        log_printf( &logger, " No Error \r\n" );
    }

    log_printf( &logger, "\r\n Temperature Error:" );
    if ( status_data.temp_h_err == TEMPHUM14_STATUS_ON ) {
        log_printf( &logger, " Below -50 C \r\n" );
    } else if ( status_data.temp_l_err == TEMPHUM14_STATUS_ON ) {
        log_printf( &logger, " Above 150 C \r\n" );
    } else {
        log_printf( &logger, " No Error \r\n" );
    }

    log_printf( &logger, "\r\n Heater Status    :" );
    if ( status_data.heater_on == TEMPHUM14_STATUS_ON ) {
        log_printf( &logger, " ON \r\n" );
    } else {
        log_printf( &logger, " OFF \r\n" );
    }

    log_printf( &logger, "-----------------------------\r\n" );
}

void application_init ( void ) {
    log_cfg_t log_cfg;  /**< Logger config object. */
    temphum14_cfg_t temphum14_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_printf( &logger, "-----------------------------\r\n" );
    log_info( &logger, " Application Init " );
    log_printf( &logger, "-----------------------------\r\n" );

    // Click initialization.
    temphum14_cfg_setup( &temphum14_cfg );
    TEMPHUM14_MAP_MIKROBUS( temphum14_cfg, MIKROBUS_1 );
    err_t init_flag = temphum14_init( &temphum14, &temphum14_cfg );
    if ( I2C_MASTER_ERROR == init_flag ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    Delay_ms ( 100 );
    log_printf( &logger, "-----------------------------\r\n" );
    log_printf( &logger, " Hardware Reset \r\n" );
    temphum14_hw_reset( &temphum14 );
    Delay_ms ( 100 );
    
    ser_numb = temphum14_get_serial_number( &temphum14 );
    log_printf( &logger, "-----------------------------\r\n" );
    log_printf( &logger, " Serial Number : %lu \r\n", ser_numb );
    log_printf( &logger, "-----------------------------\r\n" );
    log_printf( &logger, " Software Reset \r\n" );
    temphum14_soft_reset( &temphum14 );
    Delay_ms ( 100 );
    
    temphum14_get_diagnostic( &temphum14, &status_data );
    Delay_ms ( 100 );

    display_diagnostic( );
    Delay_ms ( 100 );
    
    log_info( &logger, " Application Task " );
    log_printf( &logger, "-----------------------------\r\n" );
}

void application_task ( void ) {
    temphum14_set_conversion( &temphum14, TEMPHUM14_CONVERSION_HUM_OSR_0_020, TEMPHUM14_CONVERSION_TEMP_0_040 );
    Delay_ms ( 10 );
    
    temphum14_get_temp_and_hum( &temphum14, &temperature, &humidity );
    Delay_ms ( 10 );
    
    log_printf( &logger, "  Temperature : %.2f C \r\n", temperature );
    log_printf( &logger, "  Humidity    : %.2f %% \r\n", humidity );
    log_printf( &logger, "-----------------------------\r\n" );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。