I have tried to communicate with this device with no success. Anybody have any tips. Or has anybody successfully worked with it. I implemented until now just a read and write function and the psuedo code here under.
Table XX. Pseudo-Code for Setting Up AD7730 for Continuous Conversion and Continuous Read Operation
- Write 02 Hex to Serial Port /* Writes to Communications Register Setting Next Operation as Write to Mode Register*/
- Write 2180 Hex to Serial Port /* Writes to Mode Register Starting Continuous Conversions for 0 mV to +10 mV Input Range*/
- Write 21 Hex to Serial Port /* Writes to Communications Register Setting Next Operation as Continuous Read From Data Register*/
- Set DIN Line of AD7730 Low /* Ensures Part is not Reset While in Continuous Read Mode*/
- READ_DATA: Wait for RDY Low /* Wait for RDY pin to go low to Indicate Output Update*/
- Read 24-Bit Data From Serial Port /* Read Conversion Result from AD7730's Data Register*/
- Loop to READ_DATA Until All Data Gathered
- Write 30 Hex to Serial Port /* Ends Continuous Read Operation and Places Part in Mode Where It Expects Write to Communications Register*/
My read and write code:
unsigned long AD7730_readRegistry(uint8_t regAddress, int bytes)
{
uint8_t data[5] = {0x00, 0x00, 0x00, 0x00, 0x00};
unsigned long receivedData = 0x00;
data[0] = CR_SINGLE_R | AD7730_COMM_ADD(regAddress);
spi_write(data[0]);
spi_read(data, bytes);
if(bytes == 3){
receivedData += ((unsigned long)data[0] << 16);
receivedData += ((unsigned long)data[1] << 8);
receivedData += ((unsigned long)data[2]);
}
if(bytes == 2){
receivedData += (data[0] << 8);
receivedData += (data[1]);
}
if(bytes == 1){
receivedData += (data[0]);
}
return receivedData;
}
void AD7730_writeRegistry(uint8_t regAddress, uint32_t regValue, int bytes)
{
uint8_t data[5] = {0x00, 0x00, 0x00, 0x00, 0x00};
data[0] = CR_SINGLE_W | AD7730_COMM_ADD(regAddress);
if(bytes == 3){
data[3] = ((regValue & 0x0000FF));
data[2] = ((regValue >> 8) & 0x00FF00);
data[1] = ((regValue >> 16) & 0xFF0000);
}
if(bytes == 2){
data[2] = ((regValue & 0x0000FF));
data[1] = ((regValue >> 8) & 0x00FF00);
}
if(bytes == 1){
data[1] = regValue;
}
for(int i = 0; i < bytes; i++){
spi_write(data[i]);
}
}
int main(void)
{
Config32MHzClock_Ext16M();
init_stream(F_CPU);
AD7730_spi_init();
AD7730_hardwareReset();
sei();
AD7730_writeRegistry(AD7730_MODE_REG, 0x2180, 2);
AD7730_writeRegistry(AD7730_DATA_REG, CR_START_CONT, 1);
PORTD.OUTCLR = SPI_MOSI_bm;
while (1)
{
AD7730_readRegistry(AD7730_DATA_REG, 3);
AD7730_WaitReady();
}
}
Datasheet: AD7730/AD7730L
These two functions set the device in the whatever mode and continuous read.
//Write specific mode
void AD7730_SetMode(unsigned short modeOperation, unsigned char nputRange, unsigned char channel)
{
unsigned short oldRegisterVal = 0x0;
unsigned short newRegisterVal = 0x0;
oldRegisterVal = AD7730_GetRegisterValue(AD7730_COMM_ADDR(AD7730_REG_MODE), 2);
newRegisterVal = oldRegisterVal & ~(AD7730_MODE_SEL(0x07) | AD7730_MODE_RANGE_SEL(0x03) | AD7730_MODE_CHANNEL_SEL(0x03));
newRegisterVal = newRegisterVal | modeOperation | inputRange | channel;
AD7730_SetRegisterValue(AD7730_COMM_ADDR(AD7730_REG_MODE), newRegisterVal, 2);
}
//Returns avg of several conversion
unsigned long AD7730_ContinuousReadAvg(unsigned char channel, unsigned char inputRange, unsigned char sampleNumber)
{
unsigned char registerWord[4] = {0};
unsigned long samplesAverage = 0;
unsigned char count = 0x00;
AD7730_SetMode(AD7730_MODE_SEL(AD7730_MODE_CONT_CONV), inputRange, channel);
registerWord[0] = 0x01;
registerWord[1] = AD7730_COMM_RW(AD7730_COMM_START_CONT_RD) | AD7730_COMM_ADDR(AD7730_REG_DATA);
spi_write(registerWord, 1);
for(count = 0; count < sampleNumber;count ++)
{
registerWord[0] = 0x01;
registerWord[1] = 0x0;
registerWord[2] = 0x0;
registerWord[3] = 0x0;
AD7730_WaitReady();
spi_read(registerWord, 3);
samplesAverage += ((unsigned long)registerWord[0] << 16) + ((unsigned long)registerWord[1] << 8) + registerWord[2];
}
samplesAverage = samplesAverage / sampleNumber;
registerWord[0] = 0x01;
registerWord[1] = AD7730_COMM_RW(AD7730_COMM_STOP_CONT_RD) | AD7730_COMM_ADDR(AD7730_REG_COMM);
spi_write(registerWord, 1);
return(samplesAverage);
}
Playing around with the code reading the signals on an oscilloscope. An issue that I notice during a single read is that the ready output does not pulse or signal that data is ready to be read. I'll keep posting updates.
</sarcasm>
\$\endgroup\$