esp-open-rtos/extras/pcf8591/pcf8591.c

23 lines
407 B
C
Raw Normal View History

2017-04-23 08:35:23 +00:00
#include <stddef.h>
#include <stdint.h>
#include <i2c/i2c.h>
#include "pcf8591.h"
2017-04-25 16:57:40 +00:00
/**
* CAUTION: PLEASE SET I2C_FREQUENCY_400K IS 'false' IN 'i2c.h' FILE
*/
2017-04-23 08:35:23 +00:00
2017-04-25 16:57:40 +00:00
#define PCF8591_CTRL_REG_READ 0x03
uint8_t
pcf8591_read(uint8_t addr, uint8_t analog_pin)
2017-04-23 08:35:23 +00:00
{
2017-04-25 16:57:40 +00:00
uint8_t res = 0;
uint8_t control_reg = PCF8591_CTRL_REG_READ & analog_pin;
i2c_slave_read(addr, &control_reg, &res, 1);
return res;
2017-04-23 08:35:23 +00:00
}