Hello,
I'm trying to interface two AD7715 with an ATMega1284 MPU. On this board, I have three SPI devices :
- one TLC1665 (that runs fine, without any trouble);
- two AD7715.
I cannot add an image, thus i will try to explain how I have connected this device (powered with a 5V regulated power supply and of course a lot of capacitors).
- AIN- : GND
- AIN+ : signal of interest (between 0 and 4V)
- REFIN- : GND
- REFIN+ : 5V
- #CS comes from a 74HCT138N
- SCLK, DIN, DOUT are connected to MPU with pull-up resistors.
- #DRDY is connected to MPU (I have tested with this signal or with register with the same bad result).
SPI bus runs fine in 8-bits mode as TLC1665 runs as expected (@ 250 kHz). I have checked that signals are clean on AD7715. Thus, I suppose I have done a mistake anywhere.
To access to SPI bus, I have written some functions :
uint8_t
spi_send8(int8_t device, uint8_t data)
{
spi_set_device(device);
SPDR = data;
while(!(SPSR & (1 << SPIF)));
spi_set_device(spi_none);
return(SPDR);
}
uint16_t
spi_send16(int8_t device, uint16_t data)
{
uint16_t tmp;
spi_set_device(device);
SPDR = data >> 8;
while(!(SPSR & (1 << SPIF)));
tmp = SPDR << 8;
SPDR = data & 0xFF;
while(!(SPSR & (1 << SPIF)));
tmp |= SPDR;
spi_set_device(spi_none);
return(tmp);
}
set_device(dev) is a function that set two lines of MPU to select SPI slave through 74HCT138N. This function runs also as expected. Now, I'm trying to read data from AD7715.
ad7715_rcan_init()
{
spi_send8(spi_rcan, 0x11);
spi_send8(spi_rcan, 0x7C);
while(PINC & (1 << DDC5)); // DRDY
return;
}
uint16_t
ad7715_read_rcan_data()
{
while(PINC & (1 << DDC5));
spi_send8(spi_rcan, 0x39);
return(spi_send16(spi_rcan, 0x0000));
}
First time I call ad7715_read_rcan_data(), I read a value. But always the same and regardless the real value on pin AIN+. And all other read actions return 0. Where is my mistake ?
Best regards,
JB