Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: test_HIH6130 testSensor
HIH6130.cpp
00001 /* Copyright (c) 2010-2011 mbed.org, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #include "HIH6130.h" 00020 00021 HIH6130::HIH6130(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr<<1) { 00022 // activate the peripheral 00023 } 00024 00025 HIH6130::~HIH6130() { } 00026 00027 void HIH6130::measure(void) 00028 { 00029 m_i2c.start() ; 00030 m_i2c.write(m_addr) ; 00031 m_i2c.stop() ; 00032 } 00033 00034 /** 00035 * start Command Mode 00036 * 00037 * @param none 00038 * @returns none 00039 * 00040 * @note this must be called within 3ms or 10ms 00041 * @note after Power On 00042 */ 00043 void HIH6130::start_CM(void) 00044 { 00045 uint8_t data[3] = { 0xA0, 0x00, 0x00 } ; 00046 m_i2c.write(m_addr, (char *)data, 3); 00047 } 00048 00049 /** 00050 * Ends Command Mode and enter Normal Operation Mode 00051 * 00052 * @param none 00053 * @returns none 00054 * 00055 * @note only valid in Command Mode 00056 */ 00057 void HIH6130::start_NOM(void) 00058 { 00059 uint8_t data[3] = { 0x80, 0x00, 0x00 } ; 00060 m_i2c.write(m_addr, (char *)data, 3); 00061 } 00062 00063 uint16_t HIH6130::getValue(float *humidity, float *temperature) 00064 { 00065 uint16_t status = 0 ; 00066 uint8_t data[4] ; 00067 data[0] = 0x00 ; 00068 readRegs(0, data, 4) ; 00069 00070 status = (data[0] >> 6) & 0x03 ; 00071 *humidity = (float)((data[0] & 0x3F) * 256 + data[1]) * 100.0 / (float)0x3FFF ; 00072 *temperature = (float)((data[2] * 64) + (data[3] >> 2)) * 165.0 / (float)0x3FFF - 40.0 ; 00073 return( status ) ; 00074 } 00075 00076 void HIH6130::readRegs(int addr, uint8_t * data, int len) { 00077 char t[1] = {addr}; 00078 m_i2c.write(m_addr, t, 1, true); 00079 m_i2c.read(m_addr, (char *)data, len); 00080 } 00081 00082 void HIH6130::writeRegs(uint8_t * data, int len) { 00083 m_i2c.write(m_addr, (char *)data, len); 00084 }
Generated on Wed Jul 13 2022 20:12:03 by
1.7.2