here is the Init. of my 24 bit analog to digital converter please check it out and review the pc eeg project could use YOUR help.
#include “ads1256.h”
//pin defines
//**************************** data lines
#define NEG_CHIP_SELECT 10 //Chip Select active low on pin 10
#define NEG_RESET 11 //RESET PIN active low on pin 11
//EEPROM Example
#define DATAOUT 14//MOSI
#define DATAIN 12//MISO
#define SPICLOCK 13//sck
#define SLAVESELECT 10//ss //this is redundant I am merging tutorials and need to decide on one…
//************************ end data lines definition
//*****************************
// global variables
//less efficent gain list but more straight forward
char g_Channel_0=(ADS1256_MUXP_AIN0 | ADS1256_MUXN_AINCOM);
char g_Channel_1=(ADS1256_MUXP_AIN1 | ADS1256_MUXN_AINCOM);
char g_Channel_2=(ADS1256_MUXP_AIN2 | ADS1256_MUXN_AINCOM);
char g_Channel_3=(ADS1256_MUXP_AIN3 | ADS1256_MUXN_AINCOM);
char g_Channel_4=(ADS1256_MUXP_AIN4 | ADS1256_MUXN_AINCOM);
char g_Channel_5=(ADS1256_MUXP_AIN5 | ADS1256_MUXN_AINCOM);
char g_Channel_6=(ADS1256_MUXP_AIN6 | ADS1256_MUXN_AINCOM);
char g_Channel_7=(ADS1256_MUXP_AIN7 | ADS1256_MUXN_AINCOM);
char g_Gain=ADS1256_GAIN_1;//gain setting
//global vareables from example*************************************************
unsigned char Regs[11];// holds a copy of the ADS1256 registers
unsigned char Buffer[70];// scratch buffer
int g_RateCode = ADS1256_RATE_30000; // holds the sample rate code for the ADS1256
int g_nSamples = 100;// holds the number of samples to acquire
int g_nChannels = 1;// holds the number of channels in the list
byte clr;//used to clear registers to bit trash bin.
//************************ end of example vareables
//*************************setup for spi to ad
void spi_to_AD_setup(){
SPCR=0;//clear control register
clr=SPCR; //coppy spi control register to clr to print out or clear it similar to clearing a status register
SPSR=0;
clr=SPSR;
//SPE=1 serial port enabled
//MSTR=1 master is AVR
//CPOL=0
//CPHA=0 Sample (Rising) Setup (Falling)
//SPI2X=1, SPR1=0 ,SPR0=1 FOSC/8 //this might have to be slower 7.68mhz/4 =1.92mhz
//spi2x is a little confusing it is different weather in master or slave mode? the MCU is master.
//SPSR uses SPI2X
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0);
SPSR= (1<<SPI2X);
//wait for things to settle
delay(10);
} //end of initilise spi
//*************************** spi sens from master to ad converter transfer function
//simple spi transfer function char in char out
//spdr = byte data register
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
return SPDR; // return the received byte
}
//******************************** end spi transfer function
//************************** initilise Analog to digital converter
void ADS1256Init(void){
ads1256Reset();
//set /Chip Select high
digitalWrite(NEG_CHIP_SELECT,HIGH); //disable device
}
//************************** end of init analog to digital converter
void ads1256Reset(void){
digitalWrite(NEG_RESET,HIGH); //disable device
digitalWrite(NEG_RESET,LOW); //enable device
}
void setup() {
// initialize the communication port
Serial.begin(9600);
//set pins to nessisary data direction
pinMode(NEG_CHIP_SELECT,OUTPUT);//10 //Chip Select active low on pin 10
pinMode(NEG_RESET,OUTPUT); //RESET PIN active low on pin 11
pinMode(DATAOUT,OUTPUT);//14 MOSI
pinMode(DATAIN,INPUT);//DATAIN 12//MISO
pinMode(SPICLOCK,OUTPUT);// 13 sck
pinMode(SLAVESELECT,OUTPUT);//10//ss //this is redundant I am merging tutorials and need to decide on one…
// prints state with ending line break
Serial.println(“ADS1256 Init soon”);
// wait for the long string to be sent
delay(1000); //1 sec delay(1);=delay 1 ms
// initialize Hardware for ADS1256
ADS1256Init();
// prints state with ending line break
Serial.println(“ADS1256 Init…ed”);
// wait for the long string to be sent
delay(1000); //1 sec delay(1);=delay 1 ms
}
void loop() {
// prints state with ending line break
Serial.println(“ADS1256 infinite loop wait 1 sec”);
// wait for the long string to be sent
delay(1000); //1 sec delay(1);=delay 1 ms
// prints state with ending line break
Serial.println(“waited 1 sec”);
// wait for the long string to be sent
delay(100); //100 msec delay(1);=delay 1 ms
}