BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Sensors: HH10D

The HH10D is a humidity-to-frequency sensor that includes factory calibrated constants accessed through I2C.

main.c

#include <string.h>
/* Sanity check that the features we requested are present */
#if ! (BSP430_CONSOLE - 0)
#error Console is not configured correctly
#endif /* BSP430_CONSOLE */
/* Sanity check that the features we requested are present */
#if ! (BSP430_UPTIME - 0)
#error Uptime is not configured correctly
#endif /* BSP430_UPTIME */
#if ! (BSP430_TIMER_CCACLK - 0)
#error Application requires CCACLK support
#endif /* BSP430_TIMER_CCACLK */
/* Sanity check that we have the HH10D interface */
#ifndef APP_HH10D_PORT_PERIPH_HANDLE
#error No HH10D port specified
#endif /* APP_HH10D_PORT_PERIPH_HANDLE */
#ifndef APP_HH10D_INTERVAL_S
#define APP_HH10D_INTERVAL_S 2
#endif /* APP_HH10D_INTERVAL_S */
void main ()
{
sBSP430halPORT * hh10d_port = hBSP430portLookup(APP_HH10D_PORT_PERIPH_HANDLE);
hBSP430halSERIAL i2c = hBSP430serialLookup(APP_HH10D_I2C_PERIPH_HANDLE);
unsigned long uptime_Hz;
int rc;
cprintf("\nhh10d " __DATE__ " " __TIME__ "\n");
if (NULL == hh10d_port) {
cprintf("\nERROR: No port HAL; did you enable configBSP430_HAL_%s?\n", xBSP430portName(APP_HH10D_PORT_PERIPH_HANDLE) ?: "whatever");
return;
}
/* Initialize the state information used in the HH10D ISR. */
memset(&hh10d, 0, sizeof(hh10d));
hh10d.freq_timer = xBSP430hplLookupTIMER(APP_HH10D_TIMER_PERIPH_HANDLE);
hh10d.interval_tck = APP_HH10D_INTERVAL_S * uptime_Hz;
/* Set up so we can safely read the counter value, since the clock
* is asynchronous to MCLK. */
cprintf("HH10D I2C on %s at %p, bus rate %lu Hz, address 0x%02x\n",
xBSP430serialName(APP_HH10D_I2C_PERIPH_HANDLE) ?: "UNKNOWN",
i2c, (unsigned long)BSP430_SERIAL_I2C_BUS_SPEED_HZ,
APP_HH10D_I2C_ADDRESS);
#if BSP430_PLATFORM_PERIPHERAL_HELP
cprintf("HH10D I2C Pins: %s\n", xBSP430platformPeripheralHelp(APP_HH10D_I2C_PERIPH_HANDLE, BSP430_PERIPHCFG_SERIAL_I2C));
#endif /* BSP430_PLATFORM_PERIPHERAL_HELP */
cprintf("Monitoring HH10D on %s.%u using timer %s\n",
xBSP430portName(APP_HH10D_PORT_PERIPH_HANDLE) ?: "P?",
iBSP430portBitPosition(APP_HH10D_PORT_BIT),
xBSP430timerName(APP_HH10D_TIMER_PERIPH_HANDLE) ?: "T?");
cprintf("Uptime CC block %s.%u at %lu Hz sample duration %u ticks for interval %us\n",
APP_HH10D_UPTIME_CC_INDEX, uptime_Hz,
hh10d.interval_tck, APP_HH10D_INTERVAL_S);
0, 0);
if (! i2c) {
cprintf("I2C open failed.\n");
return;
}
if (0 != rc) {
cprintf("ERR: getCalibration returned %d\n", rc);
return;
}
cprintf("I2C read offset %u sensitivity %u\n", hh10d.cal_offs, hh10d.cal_sens);
/* Select input peripheral function mode for CCACLK timer clock
* signal, which is where the HH10D's frequency signal should be
* found, and configure the assigned timer to count that input
* continuously. */
BSP430_PORT_HAL_HPL_SEL(hh10d_port) |= APP_HH10D_PORT_BIT;
BSP430_PORT_HAL_HPL_DIR(hh10d_port) &= ~APP_HH10D_PORT_BIT;
hh10d.freq_timer->ctl = TASSEL_0 | MC_2 | TACLR;
/* Hook into the uptime infrastructure, then set the alarm to
* execute immediately, synthesizing an interrupt request for the
* current time. */
hBSP430uptimeTimer()->cc_cbchain_ni[APP_HH10D_UPTIME_CC_INDEX],
hh10d.cb,
next_ni);
hBSP430uptimeTimer()->hpl->ccr[APP_HH10D_UPTIME_CC_INDEX] = uiBSP430uptimeCounter_ni();
hBSP430uptimeTimer()->hpl->cctl[APP_HH10D_UPTIME_CC_INDEX] = CCIFG | CCIE;
/* Configuration done; enable interrupts */
while (1) {
unsigned long now_utt;
unsigned int lpc;
int hum_ppth;
do {
now_utt = ulBSP430uptime_ni();
lpc = hh10d.last_period_count;
hum_ppth = iBSP430sensorsHH10Dconvert_ppth_ni(&hh10d, APP_HH10D_INTERVAL_S);
} while (0);
cprintf("%s: Count %u ; humidity %u ppth\n",
xBSP430uptimeAsText(now_utt, as_text), lpc, hum_ppth);
}
}

bsp430_config.h

/* Use a crystal if one is installed. Much more accurate timing
* results. */
#define BSP430_PLATFORM_BOOT_CONFIGURE_LFXT1 1
/* Application does output: support spin-for-jumper */
#define configBSP430_PLATFORM_SPIN_FOR_JUMPER 1
/* Request help for figuring out where I2C connects */
#define configBSP430_PLATFORM_PERIPHERAL_HELP 1
#define configBSP430_CONSOLE 1
#define configBSP430_UPTIME 1
/* We're going to need a timer to capture a frequency, which is what
* BSP430_TIMER_CCACLK does. We only need the HPL for the timer, but
* we need the CLK port and its HAL. */
#define configBSP430_TIMER_CCACLK 1
#define configBSP430_TIMER_CCACLK_CLK_PORT 1
#define configBSP430_TIMER_CCACLK_CLK_PORT_HAL 1
/* We need to know the port and pin to attach the HH10D to, which is
* the clock source for the timer we're going to use. */
#define APP_HH10D_PORT_PERIPH_HANDLE BSP430_TIMER_CCACLK_CLK_PORT_PERIPH_HANDLE
#define APP_HH10D_PORT_BIT BSP430_TIMER_CCACLK_CLK_PORT_BIT
#define APP_HH10D_TIMER_PERIPH_HANDLE BSP430_TIMER_CCACLK_PERIPH_HANDLE
/* And we need a CC block on the uptime counter that we can use to
* determine the frequency of the HH10D signal. Don't use CC0; we
* didn't ask for configBSP430_UPTIME_TIMER_HAL_CC0_ISR. */
#define APP_HH10D_UPTIME_CC_INDEX 1
/* Need I2C to access the calibration constants */
#define configBSP430_SERIAL_ENABLE_I2C 1
#if (BSP430_PLATFORM_EXP430F5438 - 0) || (BSP430_PLATFORM_TRXEB - 0)
#define APP_HH10D_I2C_PERIPH_HANDLE BSP430_PERIPH_USCI5_B3
#define configBSP430_HAL_USCI5_B3 1
#elif (BSP430_PLATFORM_EXP430F5529 - 0)
#define APP_HH10D_I2C_PERIPH_HANDLE BSP430_PERIPH_USCI5_B0
#define configBSP430_HAL_USCI5_B0 1
#elif (BSP430_PLATFORM_EXP430F5529LP - 0)
#define APP_HH10D_I2C_PERIPH_HANDLE BSP430_PERIPH_USCI5_B1
#define configBSP430_HAL_USCI5_B1 1
#elif ((BSP430_PLATFORM_EXP430FR5739 - 0) \
|| (BSP430_PLATFORM_EXP430FR4133 - 0) \
|| (BSP430_PLATFORM_EXP430FR5969 - 0) \
|| (BSP430_PLATFORM_WOLVERINE - 0))
#define APP_HH10D_I2C_PERIPH_HANDLE BSP430_PERIPH_EUSCI_B0
#define configBSP430_HAL_EUSCI_B0 1
#else
#define APP_HH10D_I2C_PERIPH_HANDLE BSP430_PERIPH_USCI_B0
#define configBSP430_HAL_USCI_B0 1
#endif
/* Address for the thing. */
#define APP_HH10D_I2C_ADDRESS 0x51
/* Need CLK capability on CCACLK for EXP430F5529 */
#if (BSP430_PLATFORM_EXP430F5529 - 0)
#define configBSP430_PLATFORM_EXP430F5529_CCACLK_NEED_CLK 1
#endif /* BSP430_PLATFORM_EXP430F5529 */
/* Get platform defaults */

Makefile

PLATFORM ?= exp430fr5739
TEST_PLATFORMS_EXCLUDE=em430 surf wolverine exp430fr5969
MODULES=$(MODULES_PLATFORM)
MODULES += $(MODULES_CONSOLE) $(MODULES_UPTIME)
MODULES += $(MODULES_TIMER)
MODULES += periph/port
VPATH += $(BSP430_ROOT)/src/sensors
MODULES += sensors/hh10d
SRC=main.c
include $(BSP430_ROOT)/make/Makefile.common