This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
I have been working on ADS1256 for almost a month now. I am using AVR atmega1284P 8-bit micro-controller. The issue that I am facing is that when I program the ADS, it works for less than 5 seconds and does not work again unless I remove the power and plug it back again. It works for few seconds and then the output disappears again. Please look at my code below, any help is really appreciated. The fCLKIN is 8MHz and SCK is 2MHz. The interrupt function works fine I verified myself. Everything is in the default state and I am reading conversion result at default state. Also, please let me know if my t6 calculations are right. Another thing I want to mention is, I have gaps in SPI clock after every 8 clock cycles. Does this effect the output?
Thanks.
/* * ADS1256.cpp * * Created: 6/13/2018 3:47:12 PM * Author : Ajay */ #include <avr/io.h> #include <avr/interrupt.h> #define MYUBRR 51 #define F_CPU 8000000UL #include <util/delay.h> unsigned char spi_tranceiver (unsigned char data); void USART0_Init(void); void transmit (unsigned char DATA); int a = 0; unsigned long adc_val = 0; ISR(INT0_vect) { if (a == 0) { spi_tranceiver(0x03); _delay_us(25); a = 1; } adc_val = spi_tranceiver(0); adc_val <<= 8; adc_val = spi_tranceiver(0); adc_val <<= 8; adc_val = spi_tranceiver(0); } int main(void) { DDRB |= 0b10110000; //Setting the MOSI, SS & SCK as outputs and MISO as input SPCR |= (1<<SPE)|(0<<DORD)|(1<<MSTR)|(0<<CPOL)|(1<<CPHA)|(1<<SPR0)|(0<<SPR1); //Enabling SPI and setting freq to 2 MH. Also, setting MSB transferred first SPSR |= (1<<SPI2X); EIMSK |= (1<<INT0); //Enables INT0 EICRA |= (1<<ISC01)|(0<<ISC00); //Interrupt INT0 on falling edge sei(); //Enable the interrupts while (1) { USART0_Init(); transmit((adc_val >>16)); transmit((adc_val >>8)); transmit((adc_val)); } } unsigned char spi_tranceiver (unsigned char data) { SPDR = data; while(!(SPSR & (1<<SPIF))); return(SPDR); } void USART0_Init(void) { UBRR0H = (unsigned char)(MYUBRR>>8); UBRR0L = (unsigned char)(MYUBRR); UCSR0B = (1<<RXEN0)|(1<<TXEN0); UCSR0C = (0<<USBS0)|(1<<UCSZ00)|(1<<UCSZ01)|(0<<UCSZ02)|(0<<UMSEL00); } void transmit (unsigned char DATA) { while ( !(UCSR0A & (1<<UDRE0)) ); UDR0 = DATA; }
Hi AjayS,
Welcome to the TI E2E Forums!
Are you toggling the /CS pin or just setting it low?
/CS resets the SPI interface and helps recovery communication if the MCU and ADC should happen to get out of sync, so I would always recommend toggling /CS between SPI commands, if possible, to ensure a clean start to each command.
I would also recommend programming the ADS1256 to a slower data rate to see if communication improves. By default the ADS1256 is configured for the fastest (30 kSPS) data rate, which might be too fast for the microcontroller to keep up with reading data and transmitting it out the UART. Also, currently you might have only partially transmitted the full 24-bit value through UART when an interrupt occurs (so UART data might appear corrupted).
You might also have a look at this similar E2E thread: e2e.ti.com/.../2602393. A lot of the recommendations I gave to troubleshoot that issue would apply to this as well; particularly checking to see if perhaps there is a signal integrity issue on the SPI bus that might cause the ADC to stop responding to commands.
Best regards,
Chris
Hi Chris,
I have tried giving the 0x50, 0x00, 0x03 but the DRDY pulse is always the same which is 64us no matter what value of the SPS I give in. It means that there is something wrong with the code. So, the way I have it is as below:
a=0;
ISR(INT0_vect)
{
if (a == 0)
{
spi_tranceiver(0x50);
spi_tranceiver(0x00);
spi_tranceiver(0x03);
_delay_us(5);
a = 1;
}
else
{
spi_tranceiver(0x01);
spi_tranceiver(0x00);
spi_tranceiver(0x00);
spi_tranceiver(0x00);
}
}
I am not really sure other ways to do it.
Thank you for helping,
Hello Chris,
So, I played around with the ADS1256 a little bit and turns out that I did program it to sample at 2.5SPS. I wasn't zooming out on the oscilloscope to see 400ms. I had scale set to 50us and that's why I was missing the entire waveform. Also, I have tried the different commands for different SPS and it all worked out. The next issue that I am encountering is the output bits. For example, the output at maximum negative input should be 800000h but its not. Same for exact 0. The output does corresponds to the input and changes when I change the input but it is different that what it should be. I have attached the waveform picture below:
The blue wave is the SPI clock, the yellow is the DRDY and the green is the output. The input is ground to both the channels.
Thanks again