Closed joba-1 closed 2 years ago
had the wait for data ready at the wrong place and the cs line was wrongly connected. Looks good now:
Channel[0]: mux=0x08, adc=1381
Channel[1]: mux=0x18, adc=1469739
Channel[2]: mux=0x28, adc=1499217
Channel[3]: mux=0x38, adc=1516425
Channel[4]: mux=0x48, adc=1522240
Channel[5]: mux=0x58, adc=1547419
Channel[6]: mux=0x68, adc=1581812
Channel[7]: mux=0x78, adc=1877784
with this loop:
void loop() {
long raw[8];
unsigned char mux[8];
for (int i = 0; i < sizeof(mux); ++i) {
adc.setChannel(i);
adc.waitDRDY();
mux[i] = adc.readRegister(ADS1256_RADD_MUX);
raw[i] = adc.readCurrentChannelRaw();
}
Serial.println();
for (int i = 0; i < sizeof(mux); ++i) {
Serial.printf("Channel[%d]: mux=0x%02x, adc=%ld\n", i, mux[i], raw[i]);
}
delay(5000); // repeat once per 5 seconds
}
@joba-1 why are you sending 11 00 00 at the beginning of each reading? Is that like a wake up or something like that? And i experience high velocity on the first reading or named as HIGH bit. I saw everywhere value = (rx_buffer[0] << 16) + (rx_buffer[1] << 8) + (rx_buffer[2]); but i need to use value = (rx_buffer[2] << 16) + (rx_buffer[3] << 8) + (rx_buffer[1]); even with my setup:
STATUS : STATUS REGISTER (ADDRESS 00h)
Reset Value = x1h
BIT 7 BIT 6 BIT 5 BIT 4 BIT 3 BIT 2 BIT 1 BIT 0
ID ID ID ID ORDER ACAL BUFEN DRDY
Bits 7-4 ID3, ID2, ID1, ID0 Factory Programmed Identification Bits (Read Only)
Bit 3 ORDER: Data Output Bit Order
0 = Most Significant Bit First (default)
1 = Least Significant Bit First
Input data is always shifted in most significant byte and bit first. Output data is always shifted out most significant
byte first. The ORDER bit only controls the bit order of the output data within the byte.
Bit 2 ACAL: Auto-Calibration
0 = Auto-Calibration Disabled (default)
1 = Auto-Calibration Enabled
When Auto-Calibration is enabled, self-calibration begins at the completion of the WREG command that changes
the PGA (bits 0-2 of ADCON register), DR (bits 7-0 in the DRATE register) or BUFEN (bit 1 in the STATUS register)
values.
Bit 1 BUFEN: Analog Input Buffer Enable
0 = Buffer Disabled (default)
1 = Buffer Enabled
Bit 0 DRDY: Data Ready (Read Only)
This bit duplicates the state of the DRDY pin.
**************************************************************************************************************/
byte status_reg = 0x00; // address (datasheet p. 30)
byte status_data = 0x01; // 01h = 0000 0 0 0 1 => status: Most Significant Bit First, Auto-Calibration Disabled, Analog Input Buffer Disabled
//byte status_data = 0x07; // 01h = 0000 0 1 1 1 => status: Most Significant Bit First, Auto-Calibration Enabled, Analog Input Buffer Enabled
SPI.transfer( 0x50 | status_reg );
SPI.transfer( 0x00 ); // 2nd command byte, write one register only
SPI.transfer( status_data );// write the databyte to the register
delayMicroseconds( 100 );
.
.
.
sorry, I don‘t remember details on that, but it could be a wait for new data. I wrote my own lib https://github.com/joba-1/Joba_Ads1256 and then never had to worry about these details - it just works :)
Not sure what you mean with the rest. Maybe your chip has a different endianness?
Hi chepo,
thanks for your code, as you suggested, I tried this version (master branch) for my ESP32 experiments.
A slightly adapted ADS1256_Basic_Switching_Channel code (to do measurements every 5 s) looks promising, but not quite there yet. If I let all ain0-7 open, they all show values around 1850000 (+/- 5000) If I short ain0 or 1, nothing happens If I short ain2 - ain6, only the respective reading goes down to ~1300 - thats more or less what I would expect for all ain's This is what I get, if I short ain7 to ground.
My problem now is:
I hooked up a logic analyzer and saw SCK at ~1,9MHz and mostly reasonable MOSI/MISO traffic:
Can't make sense of the data ready signal though. The program often hangs forever until I unplug the data ready line - guess I have to look after this first. This could very well cause the bogous readings of the different channels.
Any hints? Do I need pullup or pulldown resistors (or configure the pins to provide one)? I guess this could differ from ESP to Atmega
Best Regards, Joachim