✨ Add M3426 A<addr> parameter (#24130)
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
committed by
Scott Lahteine
parent
54e543872b
commit
995221e68e
@ -34,7 +34,7 @@
|
||||
#include "adc_mcp3426.h"
|
||||
|
||||
// Read the ADC value from MCP342X on a specific channel
|
||||
int16_t MCP3426::ReadValue(uint8_t channel, uint8_t gain) {
|
||||
int16_t MCP3426::ReadValue(uint8_t channel, uint8_t gain, uint8_t address) {
|
||||
Error = false;
|
||||
|
||||
#if PINS_EXIST(I2C_SCL, I2C_SDA) && DISABLED(SOFT_I2C_EEPROM)
|
||||
@ -44,7 +44,7 @@ int16_t MCP3426::ReadValue(uint8_t channel, uint8_t gain) {
|
||||
|
||||
Wire.begin(); // No address joins the BUS as the master
|
||||
|
||||
Wire.beginTransmission(I2C_ADDRESS(MCP342X_ADC_I2C_ADDRESS));
|
||||
Wire.beginTransmission(I2C_ADDRESS(address));
|
||||
|
||||
// Continuous Conversion Mode, 16 bit, Channel 1, Gain x4
|
||||
// 26 = 0b00011000
|
||||
@ -75,7 +75,7 @@ int16_t MCP3426::ReadValue(uint8_t channel, uint8_t gain) {
|
||||
uint8_t buffer[len] = {};
|
||||
|
||||
do {
|
||||
Wire.requestFrom(I2C_ADDRESS(MCP342X_ADC_I2C_ADDRESS), len);
|
||||
Wire.requestFrom(I2C_ADDRESS(address), len);
|
||||
if (Wire.available() != len) {
|
||||
Error = true;
|
||||
return 0;
|
||||
|
@ -29,12 +29,9 @@
|
||||
#include <stdint.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// Address of MCP342X chip
|
||||
#define MCP342X_ADC_I2C_ADDRESS 104
|
||||
|
||||
class MCP3426 {
|
||||
public:
|
||||
int16_t ReadValue(uint8_t channel, uint8_t gain);
|
||||
int16_t ReadValue(uint8_t channel, uint8_t gain, uint8_t address);
|
||||
bool Error;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user