Hello,
I don't understand what is going wrong. When the data line is ready I read 24 bits, but the value is always the same: 0x800000.
I enable AVDD voltage, wait 2 seconds to make sure voltage is okay, and wait 15useconds between measure and measure because od the update time.
Why am I getting this value??
This is my code:
void ads1231_on()
{
DO_PIN_AVDD = 1; // Enable AVDD
DO_PIN_ADS_PDWN = 0;
__delay_ms(2000);
DO_PIN_ADS_PDWN = 1; // Enable ADS1231
DO_PIN_ADS_CLOCK = 0;
}
void ads1231_off()
{
DO_PIN_AVDD = 0;
DO_PIN_ADS_PDWN = 0;
}
int24_t ads1231_read()
{
int24_t data = 0;
int24_t tmp = 0;
int8_t bit_shift;
// Wait the IC to be ready
while( (DI_PIN_ADS_DATA)==1 ){};
__delay_us(100);
// Read data
for(bit_shift=23; bit_shift >= 0; bit_shift--)
{
DO_PIN_ADS_CLOCK = 1;
__delay_ns(200);
tmp = DI_PIN_ADS_DATA;
tmp = (tmp << bit_shift);
data |= tmp;
DO_PIN_ADS_CLOCK = 0;
__delay_ns(200);
}
// Send Final clock signal to end transmition
DO_PIN_ADS_CLOCK = 1;
__delay_ns(200);
DO_PIN_ADS_CLOCK = 0;
__delay_ns(200);
return data;
}
void main(void)
{
setup(); // Setup IO
int24_t value1;
int24_t value2;
int24_t value3;
int24_t value4;
int24_t value5;
int24_t value6;
int24_t value7;
ads1231_on();
while(1)
{
value1 = ads1231_read();
__delay_us(15);
value2 = ads1231_read();
__delay_us(15);
value3 = ads1231_read();
__delay_us(15);
value4 = ads1231_read();
__delay_us(15);
value5 = ads1231_read();
__delay_us(15);
value6 = ads1231_read();
__delay_us(15);
value7 = ads1231_read();
__delay_us(15);
}
}
Thank you!