Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem in spi interfacing between ad7796 and atmega 16

Status
Not open for further replies.

nimmyj

Newbie level 6
Newbie level 6
Joined
Nov 2, 2012
Messages
12
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,359
i have interface ad7796 chip to Atmega 16 using SPI. The input is taken from two strain gauges and connected to the ad7796 chip and the output is viewing through LCD. But i am getting zero value as output. i am attaching the code. I need help.
The code is given below.

#include <avr/io.h>
#define SPI_SS PB4
#define SPI_MOSI PB5
#define SPI_MISO PB6
#define SPI_SCK PB7
#define SPI_DDR DDRB
#define SPI_PORT PORTB
void spi_master_begin_transmission()
{

SPI_PORT &= ~_BV(SPI_SS);


}

void spi_master_transmit(char data)
{

//* start transmission
SPDR = data;
//* wait for transmission complete
while(! (SPSR & (1<<SPIF)));
}


// * After transmitting data, the master chip will tell the
// * destination slave it finished.
// * The slave is unselected by putting it's SS pin to HIGH.

void spi_master_end_transmission()
{
SPI_PORT |= _BV(SPI_SS);
//lcd_string("n");

}



int main(void)
{

unsigned long int var1,var2,var3;

init_devices();
lcd_set_4bit();
lcd_init();


spi_master_init();



spi_master_begin_transmission();

spi_master_transmit(0x10);//select config register in communication reg

spi_master_transmit(0x07);//msb burnout disable,bipolar


spi_master_transmit(0x10);// lsb channel //AIN+ - AIN-

while(1)
{



spi_master_transmit(0x08);// mode selection


spi_master_transmit(0x00);//msb singleconversion

spi_master_transmit(0x00);//Internal 64 kHz Clock is made available at the CLK pin.


spi_master_transmit(0x40);


var1= spi_master_receive();
lcd_cursor(1,1);



while((var1&0x80)==0x80)

//wait for the end of convertion by polling the status register RDY bit
{

spi_master_transmit(0x40);
var1=spi_master_receive();
}

spi_master_transmit(0x58);

var2=spi_master_receive();

spi_master_transmit(0x58);
var3=spi_master_receive();
var3=var2|var3;
lcd_print(2,5,var3,3);

spi_master_end_transmission();




}
}
 

Did you check whether your SPI communication happens properly.
Most of the time due to different problems in register settings, SPI communication does not happen.

Check the SPI communication pins with an oscilloscope. If you can see clock lines and data lines work, then read the datasheet throughly for proper timings & settings.
Sometimes, there are some sequence of applying signals such as first CS, then clock etc...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top