Go Down

Topic: 24 bit read and write register of tdc7200 using SPI  (Read 1 time) previous topic - next topic

hmrashmi

Hi,
    am trying to read 24 bit register of tdc7200 but its reading zero every time please suggest me how to read 24 bit register ......?
currently i am using function as below to reg 24 bit register if its wrong please guide me to get it correct

uint32_t readRegister24(byte address3)
 {
  SPI.begin(); // wake up the SPI bus.
  SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));
 
  digitalWrite(SS1,LOW);
  delay(1);
  SPI.transfer(address3);
  val1 = SPI.transfer(0xFF);
  Serial.println("val1");
  Serial.println(val1);
  val2 = SPI.transfer(0xFF);
  Serial.println("val2");
  Serial.println(val2);
  val3 = SPI.transfer(0xFF);
  Serial.println("val3");
  Serial.println(val3);
  value = (val1 << 16) + (val2 << 8) + val3;
  Serial.println("value");
  Serial.println(value);
  digitalWrite(SS1,HIGH);
  SPI.endTransaction();
  SPI.end();
  return value;
 }

Regards,
Rashmi HM

ard_newbie

If there is no need for a fast frequency of transfers, you can use shiftin() function instead of the SPI Library.

https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftin/

An example sketch to retrieve 24-bit samplings from an ADS1244:

Code: [Select]

/*
  ADS1244
 
*/

int DATA = 4;
int SCLK = 5;

void setup() {
 
  pinMode(DATA, INPUT);
  pinMode(SCLK, OUTPUT);
 
  Serial.begin(115200);
 
  // generate a 2.4MHz clock signal on pin 3
  pinMode(3, OUTPUT);      //CLK
 
  // 17.11 Register Description
  TCCR2A = 0x33;  // 0011 0011 
  TCCR2B = 0x09;  // 0000 1001
  OCR2A  = 0x06;  // 0000 0110
  OCR2B  = 0x03;  // 0000 0011
 
  Serial.print("ADS1244\n");    // output 'AADS1244' (?) additional 'A' in front
  delay(100);
}

void loop() {
 
  // Code for reading the data:
     
  int32_t value = 0;
 
  //digitalWrite(SCLK, HIGH);  //enter slleep mode
  delay(300);
  digitalWrite(SCLK, LOW);  // wake up ADC
 
     
  // wait for data ready, stay in while-loop until LOW
  while (digitalRead(DATA) == HIGH);     

  value = shiftIn(DATA, SCLK, MSBFIRST);
  value <<= 8;
  value |= shiftIn(DATA, SCLK, MSBFIRST);
  value <<= 8;
  value |= shiftIn(DATA, SCLK, MSBFIRST);

  digitalWrite(SCLK, HIGH);  // enter sleep mode
  //digitalWrite(SCLK, LOW); // 25th pulse to keep DATA high till next data ready
   
  // process as int24_t (two's compliment 24bit) 
  value = ((signed long) (value << 8)) >> 8;   
   
   
  Serial.println(value, DEC);
  Serial.flush();

}





hmrashmi

Hello,
         since am trying to read the data stored in register and not at the pin s i dint get how shiftin() will be helpful to me so please explain in brief ..

Regards,
Rashmi H M

Go Up