I'm trying to use ads1232 with pic 18F452. I'm using gain of 128, with crystal frequency of 4 MHz and 5V Vref. I'm having some difficulty to check Dout. I need help
#define a0 LATD0_bit
#define t LATD1_bit
#define speed LATD2_bit
#define g1 LATD3_bit
#define g0 LATD4_bit
#define rst LATD5_bit
#define exc LATD6_bit
#define d0 LATC4_bit
#define sck LATC3_bit
sbit Chip_Select_Direction at TRISC0_bit;
sbit Chip_Select at LATC0_bit;
// eof ADC click module connections
// Lcd module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End Lcd module connections
char valor1[24];
long valor=0;
long read_reg(char adr)
{
union char_long {
long l;
char c[4];
} result;
Chip_Select = 1;
SPI1_Write(1);
SPI1_Write(adr | 0x80);
result.c[2]=SPI1_Read(0xFF);
result.c[1]=SPI1_Read(0xFF);
result.c[0]=SPI1_Read(0XFF);
Chip_Select = 0;
if (result.c[2] & 0x80)
result.c[3]= 0xff;
return result.l;
}
void settling_time (void){
if (speed=0){
d0=1;
delay_us(653);
}
else {
d0=1;
delay_us(83);
}
}
void offset (void){
sck=1;
delay_ms(300);
sck=0;
if (speed=0){
d0=1;
sck=0;
delay_us(1303760);
}
else{
d0=1;
sck=0;
delay_us(164860);
}
}
void main() {
LATD7_bit=1;
TRISD=0;
g1=1;
g0=1;
a0=0;
t=0;
speed=0;
exc=0;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Chip_Select = 1;
Chip_Select_Direction = 0;
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
settling_time();
offset();
Lcd_Out(1,6,"Teste");
Lcd_Out(2,4,"ADS1232");
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
while(1){
int i;
long leitura[20];
long media;
valor=read_reg(0);
LongToStr(valor, valor1);
Lcd_Out(1,1,valor1);
}
}