Device driver for Atlas Scientific pH OEM sensor with SMBus/I2C interface. More...
Device driver for Atlas Scientific pH OEM sensor with SMBus/I2C interface.
The Atlas Scientific pH OEM sensor can be used with or without the interrupt pin. Per default this pin is mapped to GPIO_UNDEF if not otherwise defined in your makefile.
If you use an electrical isolation for most accurate readings e.g. with the ADM3260, keep in mind that its not recommended to use the interrupt pin without also isolating it somehow. The preferred method, if not using an isolation on the interrupt line, would be polling. In this case leave the interrupt pin undefined.
The Sensor has no integrated temperature sensor and for the highest possible precision it requires another device to provide the temperature for error compensation.
Once the pH OEM is powered on it will be ready to receive commands and take readings after 1ms.
Files | |
file | ph_oem.h |
Device driver for Atlas Scientific pH OEM Sensor with SMBus/I2C interface. | |
file | ph_oem_params.h |
Default configuration for Atlas Scientific pH OEM sensors. | |
file | ph_oem_regs.h |
Register definitions for the Atlas Scientific pH OEM sensor. | |
Data Structures | |
struct | ph_oem_params |
pH OEM sensor params More... | |
struct | ph_oem |
pH OEM device descriptor More... | |
Typedefs | |
typedef struct ph_oem_params | ph_oem_params_t |
pH OEM sensor params | |
typedef void(* | ph_oem_interrupt_pin_cb_t) (void *) |
pH OEM interrupt pin callback | |
typedef struct ph_oem | ph_oem_t |
pH OEM device descriptor | |
Enumerations | |
enum | ph_oem_named_returns_t { PH_OEM_OK = 0, PH_OEM_NODEV = -1, PH_OEM_READ_ERR = -2, PH_OEM_WRITE_ERR = -3, PH_OEM_NOT_PH = -4, PH_OEM_INTERRUPT_GPIO_UNDEF = -5, PH_OEM_GPIO_INIT_ERR = -6, PH_OEM_TEMP_OUT_OF_RANGE = -7 } |
Named return values. More... | |
enum | ph_oem_led_state_t { PH_OEM_LED_ON = 0x01, PH_OEM_LED_OFF = 0x00 } |
LED state values. More... | |
enum | ph_oem_device_state_t { PH_OEM_TAKE_READINGS = 0x01, PH_OEM_STOP_READINGS = 0x00 } |
Device state values. More... | |
enum | ph_oem_irq_option_t { PH_OEM_IRQ_RISING = 0x02, PH_OEM_IRQ_FALLING = 0x04, PH_OEM_IRQ_BOTH = 0x08 } |
Interrupt pin option values. More... | |
enum | ph_oem_calibration_option_t { PH_OEM_CALIBRATE_LOW_POINT = 0x02, PH_OEM_CALIBRATE_MID_POINT = 0x03, PH_OEM_CALIBRATE_HIGH_POINT = 0x04 } |
Calibration option values. More... | |
Functions | |
int | ph_oem_init (ph_oem_t *dev, const ph_oem_params_t *params) |
Initialize a pH OEM sensor. More... | |
int | ph_oem_set_i2c_address (ph_oem_t *dev, uint8_t addr) |
Sets a new address to the pH OEM device by unlocking the PH_OEM_REG_UNLOCK register and writing a new address to the PH_OEM_REG_ADDRESS register. More... | |
int | ph_oem_enable_interrupt (ph_oem_t *dev, ph_oem_interrupt_pin_cb_t cb, void *arg) |
Enable the pH OEM interrupt pin if ph_oem_params_t::interrupt_pin is defined. More... | |
int | ph_oem_reset_interrupt_pin (const ph_oem_t *dev) |
The interrupt pin will not auto reset on option PH_OEM_IRQ_RISING and PH_OEM_IRQ_FALLING after interrupt fires, so call this function again to reset the pin state. More... | |
int | ph_oem_set_led_state (const ph_oem_t *dev, ph_oem_led_state_t state) |
Set the LED state of the pH OEM sensor by writing to the PH_OEM_REG_LED register. More... | |
int | ph_oem_set_device_state (const ph_oem_t *dev, ph_oem_device_state_t state) |
Sets the device state (active/hibernate) of the pH OEM sensor by writing to the PH_OEM_REG_HIBERNATE register. More... | |
int | ph_oem_start_new_reading (const ph_oem_t *dev) |
Starts a new reading by setting the device state to PH_OEM_TAKE_READINGS. More... | |
int | ph_oem_clear_calibration (const ph_oem_t *dev) |
Clears all calibrations previously done. More... | |
int | ph_oem_set_calibration (const ph_oem_t *dev, uint16_t calibration_value, ph_oem_calibration_option_t option) |
Sets the PH_OEM_REG_CALIBRATION_BASE register to the calibration_value which the pH OEM sensor will be calibrated to. More... | |
int | ph_oem_read_calibration_state (const ph_oem_t *dev, uint16_t *calibration_state) |
Read the PH_OEM_REG_CALIBRATION_CONFIRM register. More... | |
int | ph_oem_set_compensation (const ph_oem_t *dev, uint16_t temperature_compensation) |
Sets the PH_OEM_REG_TEMP_COMPENSATION_BASE register to the temperature_compensation value which the pH OEM sensor will use to compensate the reading error. More... | |
int | ph_oem_read_compensation (const ph_oem_t *dev, uint16_t *temperature_compensation) |
Reads the PH_OEM_REG_TEMP_CONFIRMATION_BASE register to verify the temperature compensation value that was used to take the pH reading is set to the correct temperature. More... | |
int | ph_oem_read_ph (const ph_oem_t *dev, uint16_t *ph_value) |
Reads the PH_OEM_REG_PH_READING_BASE register to get the current pH reading. More... | |
enum ph_oem_irq_option_t |
enum ph_oem_led_state_t |
Named return values.
Enumerator | |
---|---|
PH_OEM_OK | Everything was fine. |
PH_OEM_NODEV | No device found on the bus. |
PH_OEM_READ_ERR | Reading to device failed. |
PH_OEM_WRITE_ERR | Writing to device failed. |
PH_OEM_NOT_PH | Not an Atlas Scientific pH OEM device. |
PH_OEM_INTERRUPT_GPIO_UNDEF | Interrupt pin is GPIO_UNDEF. |
PH_OEM_GPIO_INIT_ERR | Error while initializing GPIO PIN. |
PH_OEM_TEMP_OUT_OF_RANGE | Temperature is out of range. |
int ph_oem_clear_calibration | ( | const ph_oem_t * | dev | ) |
Clears all calibrations previously done.
[in] | dev | device descriptor |
int ph_oem_enable_interrupt | ( | ph_oem_t * | dev, |
ph_oem_interrupt_pin_cb_t | cb, | ||
void * | arg | ||
) |
Enable the pH OEM interrupt pin if ph_oem_params_t::interrupt_pin is defined.
[in] | dev | device descriptor |
[in] | cb | callback called when the pH OEM interrupt pin fires |
[in] | arg | callback argument |
int ph_oem_init | ( | ph_oem_t * | dev, |
const ph_oem_params_t * | params | ||
) |
Initialize a pH OEM sensor.
[in,out] | dev | device descriptor |
[in] | params | device configuration |
int ph_oem_read_calibration_state | ( | const ph_oem_t * | dev, |
uint16_t * | calibration_state | ||
) |
Read the PH_OEM_REG_CALIBRATION_CONFIRM register.
After a calibration event has been successfully carried out, the calibration confirmation register will reflect what calibration has been done, by setting bits 0 - 2.
[in] | dev | device descriptor |
[out] | calibration_state | calibration state reflected by bits 0 - 2 (0 = low, 1 = mid, 2 = high) |
int ph_oem_read_compensation | ( | const ph_oem_t * | dev, |
uint16_t * | temperature_compensation | ||
) |
Reads the PH_OEM_REG_TEMP_CONFIRMATION_BASE register to verify the temperature compensation value that was used to take the pH reading is set to the correct temperature.
[in] | dev | device descriptor |
[out] | temperature_compensation | raw temperature compensation value. Divide by 100 for floating point e.g 3426 / 100 = 34.26 |
int ph_oem_read_ph | ( | const ph_oem_t * | dev, |
uint16_t * | ph_value | ||
) |
Reads the PH_OEM_REG_PH_READING_BASE register to get the current pH reading.
[in] | dev | device descriptor |
[out] | ph_value | raw pH value divide by 1000 for floating point e.g 8347 / 1000 = 8.347 |
int ph_oem_reset_interrupt_pin | ( | const ph_oem_t * | dev | ) |
The interrupt pin will not auto reset on option PH_OEM_IRQ_RISING and PH_OEM_IRQ_FALLING after interrupt fires, so call this function again to reset the pin state.
[in] | dev | device descriptor |
int ph_oem_set_calibration | ( | const ph_oem_t * | dev, |
uint16_t | calibration_value, | ||
ph_oem_calibration_option_t | option | ||
) |
Sets the PH_OEM_REG_CALIBRATION_BASE register to the calibration_value which the pH OEM sensor will be calibrated to.
Multiply the floating point calibration value of your solution by 1000 e.g. pH calibration solution => 7.002 * 1000 = 7002 = 0x00001B5A
The calibration value will be saved based on the given ph_oem_calibration_option_t and retained after the power is cut.
[in] | dev | device descriptor |
[in] | calibration_value | pH value multiplied by 1000 e.g 7,002 * 1000 = 7002 |
[in] | option | ph_oem_calibration_option_t |
int ph_oem_set_compensation | ( | const ph_oem_t * | dev, |
uint16_t | temperature_compensation | ||
) |
Sets the PH_OEM_REG_TEMP_COMPENSATION_BASE register to the temperature_compensation value which the pH OEM sensor will use to compensate the reading error.
Multiply the floating point temperature value by 100 e.g. temperature in degree Celsius = 34.26 * 100 = 3426
[in] | dev | device descriptor |
[in] | temperature_compensation | valid temperature range is 1 - 20000 (0.01 °C to 200.0 °C) |
int ph_oem_set_device_state | ( | const ph_oem_t * | dev, |
ph_oem_device_state_t | state | ||
) |
Sets the device state (active/hibernate) of the pH OEM sensor by writing to the PH_OEM_REG_HIBERNATE register.
[in] | dev | device descriptor |
[in] | state | ph_oem_device_state_t |
int ph_oem_set_i2c_address | ( | ph_oem_t * | dev, |
uint8_t | addr | ||
) |
Sets a new address to the pH OEM device by unlocking the PH_OEM_REG_UNLOCK register and writing a new address to the PH_OEM_REG_ADDRESS register.
The device address will also be updated in the device descriptor so it is still usable.
Settings are retained in the sensor if the power is cut.
The address in the device descriptor will reverse to the default address you provided through PH_OEM_PARAM_ADDR after the microcontroller restarts
[in] | dev | device descriptor |
[in] | addr | new address for the device. Range: 0x01 - 0x7f |
int ph_oem_set_led_state | ( | const ph_oem_t * | dev, |
ph_oem_led_state_t | state | ||
) |
Set the LED state of the pH OEM sensor by writing to the PH_OEM_REG_LED register.
[in] | dev | device descriptor |
[in] | state | ph_oem_led_state_t |
int ph_oem_start_new_reading | ( | const ph_oem_t * | dev | ) |
Starts a new reading by setting the device state to PH_OEM_TAKE_READINGS.
[in] | dev | device descriptor |