Honeywell HumidIcon Digital Humidty/Temperature Sensor.

Dependents:   test_HIH6130 testSensor

Committer:
Rhyme
Date:
Tue May 16 02:34:57 2017 +0000
Revision:
5:939573b6796d
Parent:
4:b5bedc9b6d04
start_CM and start_NOM functions added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:8d7f06935726 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Rhyme 0:8d7f06935726 2 *
Rhyme 0:8d7f06935726 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Rhyme 0:8d7f06935726 4 * and associated documentation files (the "Software"), to deal in the Software without
Rhyme 0:8d7f06935726 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Rhyme 0:8d7f06935726 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Rhyme 0:8d7f06935726 7 * Software is furnished to do so, subject to the following conditions:
Rhyme 0:8d7f06935726 8 *
Rhyme 0:8d7f06935726 9 * The above copyright notice and this permission notice shall be included in all copies or
Rhyme 0:8d7f06935726 10 * substantial portions of the Software.
Rhyme 0:8d7f06935726 11 *
Rhyme 0:8d7f06935726 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Rhyme 0:8d7f06935726 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Rhyme 0:8d7f06935726 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Rhyme 0:8d7f06935726 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Rhyme 0:8d7f06935726 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Rhyme 0:8d7f06935726 17 */
Rhyme 0:8d7f06935726 18
Rhyme 0:8d7f06935726 19 #include "HIH6130.h"
Rhyme 0:8d7f06935726 20
Rhyme 0:8d7f06935726 21 HIH6130::HIH6130(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr<<1) {
Rhyme 0:8d7f06935726 22 // activate the peripheral
Rhyme 0:8d7f06935726 23 }
Rhyme 0:8d7f06935726 24
Rhyme 0:8d7f06935726 25 HIH6130::~HIH6130() { }
Rhyme 0:8d7f06935726 26
Rhyme 4:b5bedc9b6d04 27 void HIH6130::measure(void)
Rhyme 4:b5bedc9b6d04 28 {
Rhyme 5:939573b6796d 29 m_i2c.start() ;
Rhyme 4:b5bedc9b6d04 30 m_i2c.write(m_addr) ;
Rhyme 4:b5bedc9b6d04 31 m_i2c.stop() ;
Rhyme 4:b5bedc9b6d04 32 }
Rhyme 4:b5bedc9b6d04 33
Rhyme 5:939573b6796d 34 /**
Rhyme 5:939573b6796d 35 * start Command Mode
Rhyme 5:939573b6796d 36 *
Rhyme 5:939573b6796d 37 * @param none
Rhyme 5:939573b6796d 38 * @returns none
Rhyme 5:939573b6796d 39 *
Rhyme 5:939573b6796d 40 * @note this must be called within 3ms or 10ms
Rhyme 5:939573b6796d 41 * @note after Power On
Rhyme 5:939573b6796d 42 */
Rhyme 5:939573b6796d 43 void HIH6130::start_CM(void)
Rhyme 5:939573b6796d 44 {
Rhyme 5:939573b6796d 45 uint8_t data[3] = { 0xA0, 0x00, 0x00 } ;
Rhyme 5:939573b6796d 46 m_i2c.write(m_addr, (char *)data, 3);
Rhyme 5:939573b6796d 47 }
Rhyme 5:939573b6796d 48
Rhyme 5:939573b6796d 49 /**
Rhyme 5:939573b6796d 50 * Ends Command Mode and enter Normal Operation Mode
Rhyme 5:939573b6796d 51 *
Rhyme 5:939573b6796d 52 * @param none
Rhyme 5:939573b6796d 53 * @returns none
Rhyme 5:939573b6796d 54 *
Rhyme 5:939573b6796d 55 * @note only valid in Command Mode
Rhyme 5:939573b6796d 56 */
Rhyme 5:939573b6796d 57 void HIH6130::start_NOM(void)
Rhyme 5:939573b6796d 58 {
Rhyme 5:939573b6796d 59 uint8_t data[3] = { 0x80, 0x00, 0x00 } ;
Rhyme 5:939573b6796d 60 m_i2c.write(m_addr, (char *)data, 3);
Rhyme 5:939573b6796d 61 }
Rhyme 5:939573b6796d 62
Rhyme 0:8d7f06935726 63 uint16_t HIH6130::getValue(float *humidity, float *temperature)
Rhyme 0:8d7f06935726 64 {
Rhyme 0:8d7f06935726 65 uint16_t status = 0 ;
Rhyme 0:8d7f06935726 66 uint8_t data[4] ;
Rhyme 0:8d7f06935726 67 data[0] = 0x00 ;
Rhyme 0:8d7f06935726 68 readRegs(0, data, 4) ;
Rhyme 0:8d7f06935726 69
Rhyme 0:8d7f06935726 70 status = (data[0] >> 6) & 0x03 ;
Rhyme 0:8d7f06935726 71 *humidity = (float)((data[0] & 0x3F) * 256 + data[1]) * 100.0 / (float)0x3FFF ;
Rhyme 0:8d7f06935726 72 *temperature = (float)((data[2] * 64) + (data[3] >> 2)) * 165.0 / (float)0x3FFF - 40.0 ;
Rhyme 0:8d7f06935726 73 return( status ) ;
Rhyme 0:8d7f06935726 74 }
Rhyme 0:8d7f06935726 75
Rhyme 0:8d7f06935726 76 void HIH6130::readRegs(int addr, uint8_t * data, int len) {
Rhyme 0:8d7f06935726 77 char t[1] = {addr};
Rhyme 0:8d7f06935726 78 m_i2c.write(m_addr, t, 1, true);
Rhyme 0:8d7f06935726 79 m_i2c.read(m_addr, (char *)data, len);
Rhyme 0:8d7f06935726 80 }
Rhyme 0:8d7f06935726 81
Rhyme 0:8d7f06935726 82 void HIH6130::writeRegs(uint8_t * data, int len) {
Rhyme 0:8d7f06935726 83 m_i2c.write(m_addr, (char *)data, len);
Rhyme 0:8d7f06935726 84 }