nimmyj
Newbie level 6
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();
}
}
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();
}
}