jmahatodeep
Newbie level 5
I am trying to interface ADS8513 ADC with PIC18 uC. But unable to configure. I'm following the timing diagram to start conversion but on the logic analyzer except for SCLK no other pin is changing.
Here is my code.
Here is my code.
Code:
sbit Conversion_Select at RC0_bit;
sbit Conversion_Select_Direction at TRISC0_bit;
sbit Chip_Select at RC1_bit;
sbit Chip_Select_Direction at TRISC1_bit;
sbit Busy_Select at RC2_bit;
sbit Busy_Select_Direction at TRISC2_bit;
// LCD module connections (pinout settings)
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
// LCD pin direction
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
unsigned short msb,lsb;
double ADCvalue;
double temp;
char txt[16];
void Init_Main()
{
Chip_Select=1; // CS pin is high at ADC
Chip_Select_Direction=0; // RC1 pin's direction is set as output
Conversion_Select=1; // CONV pin is high at ADC
Conversion_Select_Direction=0; // RC0 pin's direction is set as output
//Busy_Select=1; // BUSY pin is high at ADC
Busy_Select_Direction=1; // RC2 pin's direction is set as input
}
unsigned char SPI_Read1()
{
SSPBUF=0xff; /* Copy flush data in SSBUF */
while(!PIR1.SSPIF); /* Wait for complete 1 byte transmission */
PIR1.SSPIF=0; /* Clear SSPIF flag */
return(SSPBUF); /* Return received data.*/
}
float ADC_Output()
{
SPI1_Init();
SPI1_Write(0x20);
Chip_Select=1;
Conversion_Select=1; // Conversion pin is high at ADC
Conversion_Select=0;
Conversion_Select=1;
//SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV16, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
SPI1_Write(0x61);
msb=SPI_Read1(); //sending out zero as a dummy byte, to receive the answer (the register value) from chip
lsb=SPI_Read1(); //sending out zero as a dummy byte, to receive the answer (the register value) from chip
Chip_Select=1;
ADCvalue = (msb <<8) + (lsb& 0x00FF) ;
return (ADCvalue);
}
void main() {
ANSEL = ANSELH = 0; // All I/O pins are configured as digital
//PORTC=0;
Init_Main();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,5,"ADC test");
while(1)
{
temp=ADC_Output();
temp= ((ADCvalue*5)/65536);
//temp = ceil(temp * 100) / 100;
//IntToStr(ADCvalue,txt);
FloatToStr(temp,txt);
//temp=ADCvalue+0x30;
Lcd_Out(2,1,txt);
}
}
Last edited by a moderator: