SPI communication between Atmega168 and ADS1255

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

for a few days now, I am trying to communicate to the ADC on my PCB. But no matter what i try the Chip doesn't want to talk to me. I already probed all the SPI lines and i think they look okay. Only the DOUT line stays on low for the whole transmission. I add some pictures down below of one command sequence. The yellow curve is showing the !SS line and the blue ones the DIN line and the SCLK line. Here is the datasheet of the chip.

 

http://www.ti.com/product/ads1255

 

The schematic is according to page 28 and the SPI timing can be found on page 6. First i am sending the SDATAC command (stop read data continuously) and than in a 1 second pattern a wakup command followed by a RREG (read register) command.  The command and register set of the ADS1255 is on page 30 and 34 of the datasheet.

 

 

 

I read at several places, that the t6 interval of the SPI timing is quite important. But i think i added enough delay. I will also add my code down below. Maybe someone knows the chip or can identify some major mistakes. I just dont know why the chip is not answering. Thank you very much.

 

#define BAUD 115200UL
#define UBRR0_Value (F_CPU/(16*BAUD)-1)

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

// Send char via UART
//__________________________________________________________
static void uart_transmit_char (unsigned char ch)
{
	while (!(UCSR0A & (1<<UDRE0)))
	{
		;
	}

	UDR0 = ch;
}

// Send string via UART
//__________________________________________________________
static void uart_transmit_string (char * s)
{
	while (*s)
	{
		uart_putc (*s);
		s++;
	}
}

// Receive Byte via UART
// _________________________________________________________
char UART_receive(void){
	while(!(UCSR0A & (1<<RXC0)));
	return UDR0;
}

// Configure UART
//__________________________________________________________
void UARTinit(){
	UBRR0H = (unsigned char) (UBRR0_Value >> 8);
	UBRR0L = (unsigned char) UBRR0_Value;
	UCSR0B = (1<<TXEN0) | (1<<RXEN0);
	UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
	
}

// Configure SPI
// ________________________________________________________
void spi_init()
{
	DDRB = (1<<5)|(1<<3)|(1<<2);			 // MOSI, !CS , SCK as Output
	SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0)|(1<<CPHA);     // SPI Enable, SPI = Master, Prescaler = 16
}                                                       //SPI mode 1


// Send SPI Data and return the return byte
//________________________________________________________
unsigned char ADS1255_transceive (unsigned char data)
{
	SPDR = data;           
	while(!(SPSR & (1<<SPIF) ));    // Wait until transmission complete
	_delay_us(20);					// wait for 20µ until DOUT (t6)
	return(SPDR);                      
}

// Read Status-Register of ADS1255
// _______________________________________________________
char ADS1255_Read_Status(){
	
	char ans;						// return value
	 
	PORTB &= ~(1 << PORTB2);		// !CS = LOW  
	_delay_us(20);
    ADS1255_transceive(0b10|0x00);   // Send RREG command (Status)
	//_delay_us(10);
	ADS1255_transceive(0);           // read one register
	//_delay_us(10);
	ans = ADS1255_transceive(0);     // send Dummy-Byte and save return value
//	_delay_us(10);
	PORTB |= (1 << PORTB2);			// !CS = HIGH
    _delay_us(20);
	
	return ans;
}

int main(void)
{
	
	 char test;
	 
	
	 // External Interrupt for !DRDY -- Not used yet
	 //_______________________________________________-
	 DDRD &= ~(1 << 2);    
	 PORTD |= (1 << 2);     
	 EICRA |= (1 << ISC00) |(1 << ISC01);  
	 EIMSK |= (1<<INT0);				   
		
	 
	// Start UART and SPI
	//_______________________________________________
	UARTinit();							   
	spi_init();
	
	
	_delay_ms(500);   // wait for 0.5 sec
	
	// Send SDATAC Command
	//____________________________________________
	PORTB |= (1 << PORTB2);	
	_delay_us(20);
	PORTB &= ~(1 << PORTB2);		// !CS = LOW	
	_delay_us(20);
	ADS1255_transceive(0xF);        // SDATAC	
	PORTB |= (1 << PORTB2);			// !CS = HIGH
	_delay_us(20);						   
	
	//___________________________________________
	
	//sei();
	
    while(1)
	
    {     
		// send WAKEUP command
		//__________________________________________________
		PORTB &= ~(1 << PORTB2);		// !CS = LOW
		_delay_us(20);
		ADS1255_transceive(0);          // Send WAKUP
		PORTB |= (1 << PORTB2);			// !CS = HIGH
		_delay_us(20);
		
		// read status register every second
		//_____________________________________________
		
		test = ADS1255_Read_Status();    // Send RREG command (Status)
		uart_transmit_char(test);		 // Send register value via UART
		_delay_ms(1000);				 // wait 1 sec
    }
}

ISR(INT0_vect){
	
 // !DOUT-Interrupt
}