developing code to communicate with ADS1243

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

Hello guys,

I am recently developing a project to read analog signals using the ADS1243 of Texas Instruments, but I have difficulties with the part.

I am using 4Mhz crystal for ADS1243
Also I am using 4Mhz for mega8535

I want to read from 7 analog channels of ADS1243 but is not working. Something is wrong with my code.

If I modificate the following code to read values from one channel, its possible to read analog values.

With the following code is possible to read and write from\to AD1243 registers.

Scanning from all channels I read wrong values, like the one channel affects the other.

When I am using DSYNC command the result is worse, only reading zeros from analog channels.

I reed the manual but not detailed informations or any code example:
http://focus.ti.com/lit/ds/symli...

. Any Idea, can somebody help me?
. Does any body used this part before?
. Does any body knows the right sequence of commands to communicate with ADS1243?

unsigned char ADS1243_greg;
unsigned char ADS1243_Steps=0;
unsigned char ADS1243_channels[8];


#define 	CHANNEL1	0x37
#define 	CHANNEL2	0x27
#define 	CHANNEL3	0x67
#define 	CHANNEL4	0x57
#define 	CHANNEL5	0x47
#define 	CHANNEL6	0x17
#define 	CHANNEL7	0x07

varStr1_struct				 __flash 	ads1243Channels[] PROGMEM = {
	//SETUP			//MUX
	b00000101, 		CHANNEL1, //1
	b00000101, 		CHANNEL2, //2
	b00000101, 		CHANNEL3, //3
	b00000101, 		CHANNEL4, //4
	b00000101, 		CHANNEL5, //5
	b00000101, 		CHANNEL6, //6
	b00000101, 		CHANNEL7  //7
};

//Read AD Channels
//----------------
void readADChannels(void){

	
	//waiting until delay_ms = 0
	if (delay_ms == 0){

		switch (ADS1243_Steps){
		//-------------------------------------------------------------------------------------------------
		//initialize
		case 0:
			cli();	//clear interrupt
			SBT (ADS1243_CS, ADS1243_CS_);					
			CBT (ADS1243_SCLK, ADS1243_SCLK_);
			
			WCOMM(COMM_RESET);				//initialize ads1243
			sei();	//set interrupt
			delay_ms = 500;					//delay 500ms
			//
			ADS1243_Steps = 1;
			break;

		//-------------------------------------------------------------------------------------------------
		//set next channel
		case 1:
			//read from look up table the next setup value and mux value
			v1 = ReadTable1 ((__flash void*) &ads1243Channels[curChnl]);

			//prepare the next channel
			//clear interrupt

			ADS1243_greg = v1.val8b1;
			WREG (REG_SETUP, 0, &ADS1243_greg);		//write to SETUP register 
			ADS1243_greg =  v1.val8b2;
			WREG (REG_MUX, 0, &ADS1243_greg);		//write to MUX register 

			WCOMM (COMM_DSYNC);

			delay_ms = 5;							
			ADS1243_Steps = 2;
			break;

		//-------------------------------------------------------------------------------------------------
		//read data
		case 2:		
			//
			cli();	//clear interrupt
			RDATA ((void*)&number[curChnl]);		//read analog data
			sei();	//set interrupt

			ADS1243_Steps = 3;
			break;

		//-------------------------------------------------------------------------------------------------
		//read data
		case 3:
			//select next channel
			curChnl++;
			if (curChnl >= ((sizeof(ads1243Channels))/2)){
				curChnl=0;
			}
			
			//curChnl=1;
			
			ADS1243_Steps = 1;
			break;
		}
	}
}

//Write a command to ADS1243
//--------------------------
void WCOMM (unsigned char comm){
	cli();	//clear interrupt
	CBT (ADS1243_CS, ADS1243_CS_);
	
	write_byte(comm);
	
	SBT (ADS1243_CS, ADS1243_CS_);
	sei();	//set interrupt
}

//Read analog value from select channel
//-------------------------------------
void RDATA (unsigned char * dataBuff){
	cli();	//clear interrupt
	CBT (ADS1243_CS, ADS1243_CS_);
	//αποστολή εντολής ανάγνωσης
	write_byte (b00000001);
	//ανάγνωση bytes
	read_bytes (dataBuff, 3);
	SBT (ADS1243_CS, ADS1243_CS_);
	sei();	//set interrupt
}

//Write to register
//-----------------
//r -> write from register of ads1243
//n -> total bytes to write
//dataBuff -> data that will be transfered to the ads1243
void WREG (unsigned char r, unsigned char n, unsigned char * dataBuff){
	cli();	//clear interrupt
	CBT (ADS1243_CS, ADS1243_CS_);

	//εγγραφή 1ου byte εντολής
	write_byte((r & 0x0F) | b01010000);
	//εγγραφή 2ου byte εντολής
	write_byte(n & 0x0F);

	//ανάγνωση
	n++;
	while (n > 0){
		write_byte(*dataBuff);
		dataBuff++;
		n--;
	}

	SBT (ADS1243_CS, ADS1243_CS_);
	sei();	//set interrupt
}

//Read from Registers
//-------------------
//r -> read from register of ads1243
//n -> total bytes to read
//dataBuff -> address that the data will be placed
void RREG (unsigned char r, unsigned char n, unsigned char * dataBuff){
	cli();	//clear interrupt
	CBT (ADS1243_CS, ADS1243_CS_);

	//write RREG command in register 
	write_byte((r & 0x0F) | b00010000);
	//write n bytes to be readen
	write_byte(n & 0x0F);
	//read bytes from ads1243
	read_bytes (dataBuff, n+1);

	SBT (ADS1243_CS, ADS1243_CS_); 
	sei();	//set interrupt
}

//Read bytes from ADS1243
//-----------------------
//dataBuff -> address that the data will be readen
//totalBytes -> total bytes to read
void read_bytes (unsigned char * dataBuff, unsigned char totalBytes){
	dataBuff += (totalBytes-1);
	//ανάγνωση
	while (totalBytes > 0){
		*dataBuff = read_byte();
		dataBuff--;
		totalBytes--;
	}
}

//Write bytes in ADS1243
//-----------------------
//dataBuff -> address that the data will be writen
//totalBytes -> total bytes to read
void write_bytes (unsigned char * dataBuff, unsigned char totalBytes){
	while (totalBytes > 0){
		write_byte(*dataBuff);
		dataBuff++;
		totalBytes--;
	}
}

//Pause for 1uS
//-------------
void pause1uS(void){
	volatile unsigned char pause;
	pause = 1;
	pause = 1;
}

//Write one byte in ADS1243
//-------------------------
//data -> byte to write in ads1243
void write_byte(unsigned char data)
{	
	unsigned char i;

	for(i=0;i<=7;++i) {
		SBT (ADS1243_SCLK, ADS1243_SCLK_);			//SERIAL CLOCK = 1
		
		pause1uS();									//pause for 1uS
		
		if (CHBT (data, 7)) 						//SET DATA PIN
			SBT (ADS1243_DIN, ADS1243_DIN_);		
		else
			CBT (ADS1243_DIN, ADS1243_DIN_);
		
		pause1uS();									//pause for 1uS
		
		data = data << 1;
		CBT (ADS1243_SCLK, ADS1243_SCLK_);			//SERIAL CLOCK = 0
		
		pause1uS();									//pause for 1uS
 	}
	
	for(i=0;i<=50;++i) {	}
}

//Read one byte for ads1243
//-------------------------
unsigned char read_byte(void){
	unsigned char i;
	unsigned char ttlBits=8;
	unsigned char data=0;
	for(i=0;i

Learn as long as you live