So I am writing to the register 0x05 hence 000101 ok page 85-94. this register has 8 bits 0-7.
i write to each of the bits a 1, hence data =0xff. what does 0x3f do? its 63 it doesnt matter if I send 0xff or 0x3f.
i get back the following from Serial Monitor: register 0x05 shows 10100 Hex 14 DEC 20
this means that the ID number is 16, and the Silicon Revision number =4;
Code:
#include <SPI.h>
//SPI defines
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST -1
#define AD7124_CS 8
#define AD7124_SPEED 5000000 //max speed
#define REG 0x05
#define DATA 0xff
SPISettings settingsAD7124(5000000, MSBFIRST, SPI_MODE3); //Page 38-94 SPI_MODE3 CS LOW
void setup()
{
pinMode(AD7124_CS, OUTPUT);
pinMode(TFT_CS, OUTPUT);
SPI.begin();
//Initialize serial and wait for port to open:
Serial.begin (38400);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
}
void loop()
{
AD7124_Write(REG,DATA);
unsigned char val=AD7124_Read(REG);
Serial.print(" register 0x05 shows ");
Serial.print(val,BIN);
Serial.print(" Hex ");
Serial.print(val,HEX);
Serial.print(" DEC ");
Serial.println(val,DEC);
}
void AD7124_Write(unsigned char reg, unsigned char data)
{
digitalWrite(AD7124_CS,LOW);
SPI.beginTransaction(settingsAD7124);
SPI.transfer(reg & data); // write to register 0x05 hence 000101 bin, and write to the register 0xFF
// SPI.transfer(data); //i get back a value for all bits 0-7
SPI.endTransaction();
digitalWrite(AD7124_CS,HIGH);
}
unsigned char AD7124_Read(unsigned char reg)
{
unsigned char data;
digitalWrite(AD7124_CS,LOW);
SPI.beginTransaction(settingsAD7124);
SPI.transfer((reg&0xff)|0x40); // select register to read from
data = SPI.transfer(0);
SPI.endTransaction();
digitalWrite(AD7124_CS,HIGH);
delay(1000); // optional delay for between transaction spacing
return data;
}
}
after this it becomes useful to write an array for the registers and data that needs to be send.
reading a RTD:
Reset the ADC. for 0x01 & 0x0000
2.Select the power mode 0x01 &
0x01 & ED0 ( bit 15-13 are 0, Bit12 is 0, Bit 11=1=Continious Read,Bit 10=1 status, Bit 9=1 Set diagnostics, Bit 8=0 Internal Ref(not Sure if needed to set), Bit7=1,Bit6=1,Bit5-2=0000; bit 1 =1; bit 0=0; hence 0000111011000011=EC3;
3.Set the CHANNEL_0 register analog input to AIN1/AIN2. 0x09 & 0x8001 From the AD7124 Library (bit 15=1,14:12=000, Setup 0 AIN1 is AIN2., 11:10=0, 9:5=00000, 4:0=00001 is=0x8001.
Assign Setup 0 to this channel. this is bit 14:12.
Configure Setup 0 to have a gain of 16 and select the reference source REFIN2(±). 0x31 & 0x50000 ? why i Dont understand this from the PDF it sets the Gain for the Config0 thats a gain of 327680 if I understand it correctly. (not much is written on the Gain part in the pdf)
Select the filter type and set the output data rate.
#define AD7124_FILT_REG_FILTER(x) ((uint32_t)((x) & 0x7) << 21) this I dont understand at all ( conversion to uint32_t ((x)&0x07 of errorregister ) << bit shift 21 to the left
4.Program the excitation currents to 500 μA and output the currents on the AIN0 and AIN3 pins. 5.Wait until RDY goes low. (((x) & 0x7) << 11) on address 0x03 & (23:16=0, bit 15=PDSW=0; 14=0; 13:11=100=500uA, 10:8=500uA?(not sure, but it is written that both excitations currents are required), 7:4=0000 Channel 0; 3:0=0011 for AIN3; gives 2403 in hex value
Read the conversion value. eeehm ? how do I do this? is this set at the 0x00 & 10000000 at channel 0, and 0x00 10000011 at channel 3?
6. Repeat Step 4.