Other Parts Discussed in Thread: ADS1256
Hi there,
For a few days I'm trying to communicate to the ADC on my board. As a µC I'm using a Atmega168 and its Hardware SPI Pins. I've already tried different SPI-Modes but without success. At several places on the net i read that the time interval between DIn and DOUT (t6) is very critical. So i added a delay of 50 µs in my SPI-transceiver method.
I thought i could start simple and try to read out the STATUS-register of the chip. So i sent the commands to the chip. Problem is i am always reading back "0xFFFFFFFF" even if i change the register to be read to DRATE or something else. So thats not valid. I'm new to this kind of ADC communication so maybe i am doing something completely wrong.. I will add my code here maybe someone instantly could identify some mistakes. I'm not using the external interrupt for !DRDY yet. In the main-loop i am only reading the status register at 1000ms intervals.
The scematic of the chip is according to the dataseet page 28. 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>
static void uart_transmit_char (unsigned char ch)
{
while (!(UCSR0A & (1<<UDRE0)))
{
;
}
UDR0 = ch;
}
static void uart_transmit_string (char * s)
{
while (*s)
{
uart_putc (*s);
s++;
}
}
char UART_receive(void){
while(!(UCSR0A & (1<<RXC0)));
return UDR0;
}
void UARTinit(){
UBRR0H = (unsigned char) (UBRR0_Value >> 8);
UBRR0L = (unsigned char) UBRR0_Value;
UCSR0B = (1<<TXEN0) | (1<<RXEN0);
UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
}
void spi_init()
{
DDRB = (1<<5)|(1<<3)|(1<<2); // MOSI, !CS , SCK as Output
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); // SPI Enable, SPI = Master, Prescaler = 16
}
unsigned char ADS1255_transceive (unsigned char data)
{
SPDR = data;
while(!(SPSR & (1<<SPIF) ));
_delay_us(50); // wait for 50µ until DOUT (t6)
return(SPDR);
}
char ADS1255_Read_Status(){
char ans; // Return variable
PORTB &= ~(1 << PORTB2); // !CS = LOW
_delay_us(10);
ADS1255_transceive(0x10|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(10);
return ans;
}
int main(void)
{
char test;
DDRD &= ~(1 << 2);
PORTD |= (1 << 2);
EICRA |= (1 << ISC00) |(1 << ISC01);
EIMSK |= (1<<INT0); // external Interrupt (!DOUT) at INT0
UARTinit(); // UART
spi_init(); // SPI
//sei();
while(1)
{
test = ADS1255_Read_Status();
uart_transmit_char(test);
_delay_ms(1000);
}
}
ISR(INT0_vect){
// !DOUT-Interrupt
}





