I am still facing some major problem and cant read any valid data. In a loop I am setting REG1 to measure temperature, wait about 60ms and try to read values. Received buffer looks randomly- eg. 0x04 13 2B and is constant. Like it would have something in common with measurement but measurement is done one time and than I am reading same and same value from the internal register. At the end of the loop, I am again waiting, this time 1s before loop repeating. Below I am posting some arduino code that shows that process: #include #define DEFAULT_CONFIG_REG0 0b00000000 // AINP=AIN0, AINN=AIN1, Gain 1, PGA enabled #define DEFAULT_CONFIG_REG1 0b00000100 // Data rate: 20 SPS, Normal Operating mode, Continuous conversion mode, Temperature sensor disabled, Burn-out disabled #define DEFAULT_CONFIG_REG2 0b00010000 // Internal 2.048-V reference, Simultaneous 50-Hz and 60-Hz rejection, Switch always open, IDAC Off #define DEFAULT_CONFIG_REG3 0b00000000 // IDAC1 disabled, IDAC2 disabled, Only DRDY #define ADS1220 _CS_PIN 1 #define PIN_NUM_ADC_PWR 2 #define WREG 0x40 #define RREG 0x20 #define RDATA 0x10 #define START 0x08 #define SPI_MASTER_DUMMY 0xFF void setup() { Serial.begin(115200); pinMode( ADS1220 _CS_PIN, OUTPUT); pinMode(PIN_NUM_ADC_PWR, OUTPUT); digitalWrite(PIN_NUM_ADC_PWR, LOW); delay(100); SPI.begin(); SPI.setBitOrder(MSBFIRST); SPI.setDataMode (SPI_MODE1); SPI.setClockDivider(SPI_CLOCK_DIV128); Serial.println("DEFAULT_CONFIG Write"); writeSingleRegister( 0, DEFAULT_CONFIG_REG0 ); writeSingleRegister( 1, DEFAULT_CONFIG_REG1 ); writeSingleRegister( 2, DEFAULT_CONFIG_REG2 ); writeSingleRegister( 3, DEFAULT_CONFIG_REG3 ); delay(100); Serial.println("DEFAULT_CONFIG Read"); Serial.println(readRegister(0),HEX); Serial.println(readRegister(1),HEX); Serial.println(readRegister(2),HEX); Serial.println(readRegister(3),HEX); Serial.println(" "); // OK : read what I have written writeCommand( START ); delay(1000); readData(); } void loop() { while(1) { writeSingleRegister( 1, DEFAULT_CONFIG_REG1 & (1 << 1)); // Enable temperature sensor // if I add START command here , values starts changing but still looks random like "0x4 4-14-3A", "0x4 4-13-66". It is not temp value // delay(1); writeCommand( START ); delay(60); readData(); delay(1000); } } void writeSingleRegister(uint8_t address, const uint8_t value) { digitalWrite( ADS1220 _CS_PIN, LOW); SPI.transfer(WREG | (address<<2)); SPI.transfer(value); digitalWrite( ADS1220 _CS_PIN,HIGH); } uint8_t readRegister(uint8_t address) { uint8_t data; digitalWrite( ADS1220 _CS_PIN,LOW); SPI.transfer(RREG|(address<<2)); data = SPI.transfer(SPI_MASTER_DUMMY); digitalWrite( ADS1220 _CS_PIN,HIGH); return data; } void readData() { digitalWrite( ADS1220 _CS_PIN,LOW); Serial.print("\n0x"); Serial.print(SPI.transfer(RDATA), HEX); Serial.print(" "); for (int i = 0; i < 3; i++, Serial.print("-")) { uint8_t data = SPI.transfer(SPI_MASTER_DUMMY); Serial.print(data, HEX); } digitalWrite( ADS1220 _CS_PIN,HIGH); } void writeCommand(uint8_t cmd) { digitalWrite( ADS1220 _CS_PIN, LOW); SPI.transfer(cmd); digitalWrite( ADS1220 _CS_PIN,HIGH); } void setup() { Serial.begin(115200); pinMode( ADS1220 _CS_PIN, OUTPUT); pinMode(PIN_NUM_ADC_PWR, OUTPUT); digitalWrite(PIN_NUM_ADC_PWR, LOW); delay(100); SPI.begin(); SPI.setBitOrder(MSBFIRST); SPI.setDataMode (SPI_MODE1); SPI.setClockDivider(SPI_CLOCK_DIV128); Serial.println("DEFAULT_CONFIG Write"); writeSingleRegister( 0, DEFAULT_CONFIG_REG0 ); writeSingleRegister( 1, DEFAULT_CONFIG_REG1 ); writeSingleRegister( 2, DEFAULT_CONFIG_REG2 ); writeSingleRegister( 3, DEFAULT_CONFIG_REG3 ); delay(100); Serial.println("DEFAULT_CONFIG Read"); Serial.println(readRegister(0),HEX); Serial.println(readRegister(1),HEX); Serial.println(readRegister(2),HEX); Serial.println(readRegister(3),HEX); Serial.println(" "); // OK : I read what I have written writeCommand( START ); delay(1000); readData(); } void loop() { while(1) { writeSingleRegister( 1, DEFAULT_CONFIG_REG1 & (1 << 1)); // Enable temperature sensor // if I add START command here, values starts changing but still looks random like "0x4 4-14-3A", "0x4 4-13-66". It is not temp value // delay(1); writeCommand( START ); delay(60); readData(); delay(1000); } } Unfortunately, I have no easy access to Logic Analyzer and cant test real values on MOSI, MISO. Could you also point me a difference when I read data after conversation is ready, just ticking with clock, and when I am sending RDATA command. How does ADS1220 know that it should send me data now or after one byte (because I am sending RDATA), when there isn't any time delay?
↧