Library for working with the HYCON HY3116/8 24-bit weigh-scales ADC series.
Diff: HY3116.cpp
- Revision:
- 5:3fdbe36e5057
- Parent:
- 4:1571244a8486
- Child:
- 6:435b50250491
--- a/HY3116.cpp Tue Jun 28 13:51:20 2016 +0000 +++ b/HY3116.cpp Mon Jul 04 18:21:14 2016 +0000 @@ -1,23 +1,27 @@ #include "HY3116.h" -/** - * Constructor. - * Prepares the output pins. - */ -HY3116::HY3116(PinName sda, - PinName scl) : i2c(sda, scl) -{ - // Set the I2C clock frequency - i2c.frequency(100000); -} // End constructor +I2C i2c(p22, p21); +//I2C i2c(p6, p5); -/** - * Destructor. - */ -HY3116::~HY3116() -{ +///** +// * Constructor. +// * Prepares the output pins. +// */ +//HY3116::HY3116(PinName sda, +// PinName scl) : i2c(sda, scl) +//{ +// +// // Set the I2C clock frequency +// i2c.frequency(100000); +//} // End constructor -} +///** +// * Destructor. +// */ +//HY3116::~HY3116() +//{ +// +//} // Single-byte write helper function void HY3116::writeByte(uint8_t address, uint8_t subAddress, uint8_t data) @@ -94,6 +98,8 @@ // void HY3116::init() { + // Set the I2C clock frequency + i2c.frequency(100000); // Set-up the SYS register writeByte(HY3116_ADDRESS, SYS, 0b00011100); // Enable the ADC & LDO @@ -112,8 +118,13 @@ wait_ms(1); // wait 100 ms to stabilize // Set-up the ADC4 register - writeByte(HY3116_ADDRESS, ADC4, 0b01001100); // Set LDO to 3.0V, REFO = 1.2V, conv. rate = 327kHz, SPS = 40 - wait_ms(1); // wait 100 ms to stabilize + // [0:1] = LDO voltage select, 01 = 3.0V + // [2] = REFO voltage, 0 = 1.2V + // [3] = HS conversion rate, 0 = slow (327kHz) + // [4:6] = OSR ADC output rate, 110 = 40SPS (when HS = 0) + // [7] = N/A + writeByte(HY3116_ADDRESS, ADC4, 0b01001100); + wait_ms(1); // Wait to stabilise resetChip(); wait_ms(1);