Problem with reading DATA_REG on ADC with ARDUINO

Hi everybody,

I am using AD7793 (24bit ADC) with ARDUINO Leonardo to measure the temperature of a PT1000. However I am having trouble reading DATA_REG on ADC and I get always FFFFFF as output. Could anyone please help me?

Schematics? Code?

But why on earth are you using a 24-bit ADC to read temperature?

Hi thanks for reply.

this code gives me FFFFFF but as result for REG_ID it gives the correct one for AD7793. When I pull out the CS cable (on pin 10 on ARDUINO), it continues giving out the same FFFFFF!! I guess there is sth with this CS pin!

void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  SPI.setDataMode(SPI_MODE3);
  SPI.setBitOrder(MSBFIRST);
  pinMode(10, OUTPUT);
}

void loop()
{
  unsigned long value;
  value = AD7793_GetRegisterValue ( AD7793_REG_DATA,3 );
  Serial.println(value);
}

Here is the GetRegisterValue Code:

unsigned long AD7793_GetRegisterValue(unsigned char regAddress, unsigned char Size)
{
  unsigned char data[5] = {  0x00, 0x00, 0x00, 0x00, 0x00  };
  unsigned long receivedData = 0x000000;        
  data[1] = AD7793_COMM_READ |  AD7793_COMM_ADDR(regAddress);
  select(); //CS LOW
  SPI_Write(&data[1],1);
  SPI_Read(data,Size);
  deselect(); //CS HIGH
  
  if(Size == 1)
  {
    receivedData += (data[0] << 0);
  }
  if(Size == 2)
  {
    receivedData += (data[0] << 8);
    receivedData += (data[1] << 0);
  }
  if(Size == 3)
  {
    receivedData = data[0];
    receivedData = (receivedData << 16) ;
    receivedData += (data[1] << 8);
    receivedData += (data[2] << 0);
  }
  return receivedData;
  
}

What do you mean “on earth”? I have completely no idea of electronics, I just program this board.

Perhaps you could post us your schematic - that would help

regards

Allan

srt92:
Hi thanks for reply.
What do you mean "on earth"?

I think he means that a 24-bit A/D (if you ever will get that resolution) is overkill.
You could have 25000 A/D steps per degree C.
24-bit stuff needs carefull circuit board layout, very good shielding, and noise-free power supplies.
Leo..

allanhurst:
Perhaps you could post us your schematic - that would help

regards

Allan

I am not sure what you mean with schematic, because I have no idea of electronics I am just going to write a code for this device, anyway I have uploaded some pictures of the ADC and ARDUINO and also PIN Configuration of AD7793 which might be helpful:
Here the link
Thanks
Soroor

Wawa:
I think he means that a 24-bit A/D (if you ever will get that resolution) is overkill.
You could have 25000 A/D steps per degree C.
24-bit stuff needs carefull circuit board layout, very good shielding, and noise-free power supplies.
Leo..

Thanks for comment. Actually what now matters for me is to have an output from this device. Does it mean that I have to change my ADC?

Does it mean that I have to change my ADC?

No, it just means it is a poor choice. Like paying $800 on some shoes to do the gardening in.

What do you mean "on earth"?

You are not a native English speaker then. It is a colloquium expression expressing utter surprise.

I am not sure what you mean with schematic,

It is a diagram showing how things are connected up. Those photographs are useless, you can not even see where the wires go from one board to the other.

I have no idea of electronics

That's a surprise then.

I am just going to write a code for this device,

You can not write code for an embedded system without understanding the circuit of what you are trying to interface to.

If you want help you have to post all your code, not just the little bits that you posted.

Quote
Does it mean that I have to change my ADC?
No, it just means it is a poor choice. Like paying $800 on some shoes to do the gardening in.

Quote
What do you mean "on earth"?
You are not a native English speaker then. It is a colloquium expression expressing utter surprise.

Quote
I am not sure what you mean with schematic,
It is a diagram showing how things are connected up. Those photographs are useless, you can not even see where the wires go from one board to the other.

Quote
I have no idea of electronics
That's a surprise then.

Quote
I am just going to write a code for this device,
You can not write code for an embedded system without understanding the circuit of what you are trying to interface to.

If you want help you have to post all your code, not just the little bits that you posted.

Thanks for your help.

Here I have uploaded the full code, it was too long I was not able to post it here. The functions and also the library are found in AD7793 website. I have changed them though a little bit.

It gets "AD7793 OK" (means recognizing AD7793 ID) and also FFFFFF for the value of DATA.
Thanks again.

Hi again.

For a while I got some acceptable results, but after that nothing again(only FFFFFF) till now.

In some places you have writing to the ADC wrapped in chip select control (AD7793_CS_LOW/AD7793_CS_HIGH), but not always and not in the main loop SPI.transfer()s. Does this matter? Most SPI chips require the CS to be controlled.

srt92:
Hi again.

For a while I got some acceptable results, but after that nothing again(only FFFFFF) till now.

If that is with the same software then you have unreliable wiring. You need soldered joints.

And yes you need to control the chip select pin otherwise you will get all ones.

In some places you have writing to the ADC wrapped in chip select control (AD7793_CS_LOW/AD7793_CS_HIGH), but not always and not in the main loop SPI.transfer()s. Does this matter? Most SPI chips require the CS to be controlled.

Yes I have seen that in a code for another ADC model with same function. And I think this is due to these diagrams in Datasheet (Ad7793):

CS should be set low when reading and writing to the registery. I guess sth is wrong with CLK! But no idea!

CS should also be set high when the reading is finished or it will not work. The point at which the data is clocked in on the clock waveform is defined by the SPI mode, this has to match your device. You could try another of the four modes.

Grumpy_Mike:
If that is with the same software then you have unreliable wiring. You need soldered joints.

And yes you need to control the chip select pin otherwise you will get all ones.

I'll check that.

Grumpy_Mike:
CS should also be set high when the reading is finished or it will not work. The point at which the data is clocked in on the clock waveform is defined by the SPI mode, this has to match your device. You could try another of the four modes.

The reason I'm asking is the following topic: (on high precision ADC 24-bit with arduino) http://forum.arduino.cc/?topic=57873.0

The OP seems to have abandoned that thread. If it is only two wires it is not SPI.

How have you generated the clock signal?

Grumpy_Mike:
The OP seems to have abandoned that thread. If it is only two wires it is not SPI.

How have you generated the clock signal?

It is SPI and through ICSP ports on arduino the clock signal will be generated. (connection btw. SCK on arduino & the SCLK on ADC)

It is SPI

No it is not. It is an SPI like interface. Not using a CS pin makes it not able to do the "bus" bit of the interface protocol.

through ICSP ports on arduino the clock signal will be generated

There is no difference between the signals you get on the ICSP port and the ones you get on the normal I/O pins. They are just grouped together in a header.
If you look at the data sheet you can see the SCLK signal on the A/D is not a normal clock signal for an SPI interface.
The clock input to the A/D is not concerned with data transfer so where do you get it from? You can not get it from the normal SPI interface because that clock stops and starts with the data transfer.

Grumpy_Mike:
No it is not. It is an SPI like interface. Not using a CS pin makes it not able to do the "bus" bit of the interface protocol.
There is no difference between the signals you get on the ICSP port and the ones you get on the normal I/O pins. They are just grouped together in a header.
If you look at the data sheet you can see the SCLK signal on the A/D is not a normal clock signal for an SPI interface.
The clock input to the A/D is not concerned with data transfer so where do you get it from? You can not get it from the normal SPI interface because that clock stops and starts with the data transfer.

I don't understand some parts. So what should I do? :frowning: