karbiuch
Junior Member level 1
Hi!
I wrote simply program to read data from Ad7739 (24bit adc) to atmega. My program works, but has one bug. Program is able to read data only from one channel. I cant read voltages from another channels. I think I do not understand datasheet becouse the SPI code works. It's probably a problem with correct sending channels addresses.
code looks like this, it gets correctly data from channel 0. But this code doesnt work for chanel 4. Where is problem? Do I put bad byte adress?
But this code doesnt work for chanel 4. Where is problem? I put bad adress of channel 4?
Could anyone tell my what values should have "communication register, mode register, comunnication register" to read correct from example chanel 4?
Sometimes I have in data only 0xFFFFFF. Do I make mistake on reading vstatus data?
Page 22
#define ADCCHANEL0 0x38
#define ADCCHANEL4 0x3c
#define READADC0 0x48
#define READADC4 0x4c
I wrote simply program to read data from Ad7739 (24bit adc) to atmega. My program works, but has one bug. Program is able to read data only from one channel. I cant read voltages from another channels. I think I do not understand datasheet becouse the SPI code works. It's probably a problem with correct sending channels addresses.
HTML:
http://www.analog.com/media/en/technical-documentation/data-sheets/AD7739.pdf
code looks like this, it gets correctly data from channel 0. But this code doesnt work for chanel 4. Where is problem? Do I put bad byte adress?
Code:
PORTB|=_BV(ADCVCS);
spi_hw_adcV_data_send(ADCCHANEL0);
//mode register //#define ADCCHANEL0 0x38
PORTB|=_BV(ADCVCS);
spi_hw_adcV_data_send(0x4A); //-
//single conversion; dump mode, 24bit mode
PORTB|=_BV(ADCVCS);
while(SPIPIN & _BV(ADCRDYVPIN));
spi_hw_adcV_data_send(READADC0);
//data register; ch0 //#define READADC0 0x48
PORTB|=_BV(ADCCS);
SPIPORT&= ~_BV(ADCVCS);
SPDR=0x00;
while((SPSR & _BV(SPIF)) == 0);
SPSR |= _BV(SPIF);
cData=SPDR;
SPIPORT|=_BV(ADCVCS);
vstatus = cData; //reading status
SPIPORT&= ~_BV(ADCVCS);
SPDR=0x00;
while((SPSR & _BV(SPIF)) == 0);
SPSR |= _BV(SPIF);
cData=SPDR;
AdcVFrame[2]=cData; //first byte 1/3
SPIPORT|=_BV(ADCCS);
PORTB|=_BV(ADCVCS);
SPIPORT&= ~_BV(ADCVCS);
SPDR=0x00;
while((SPSR & _BV(SPIF)) == 0);
SPSR |= _BV(SPIF);
cData=SPDR;
SPIPORT|=_BV(ADCCS);
PORTB|=_BV(ADCVCS);
AdcVFrame[1]=cData; //second byte 2/3
SPIPORT&= ~_BV(ADCVCS);
SPDR=0x00;
while((SPSR & _BV(SPIF)) == 0);
SPSR |= _BV(SPIF);
cData=SPDR
SPIPORT|=_BV(ADCCS);
PORTB|=_BV(ADCVCS);
AdcVFrame[0]=cData; //last byte 3/3
if(vstatus& _BV(OVR))
{ //error reading
if(vstatus& _BV(SIGN))
{
AdcVFrame[1] = 0x00;
AdcVFrame[0] = 0x00;
AdcVFrame[2] = 0x00;
}
else
{
AdcVFrame[1] = 0xff;
AdcVFrame[0] = 0xff;
AdcVFrame[2] = 0xff;
}
}
uartput(AdcVFrame[2]) ; //byte3
uartput(AdcVFrame[1]) ; //byte2
uartput(AdcVFrame[0]) ; //byte1
But this code doesnt work for chanel 4. Where is problem? I put bad adress of channel 4?
Could anyone tell my what values should have "communication register, mode register, comunnication register" to read correct from example chanel 4?
Sometimes I have in data only 0xFFFFFF. Do I make mistake on reading vstatus data?
Page 22
HTML:
http://www.analog.com/media/en/technical-documentation/data-sheets/AD7739.pdf
#define ADCCHANEL4 0x3c
#define READADC0 0x48
#define READADC4 0x4c
Last edited: