jmahatodeep
Newbie level 5
I'm trying to interface ADS8513 with PIC18F45k20. I'm unable to read data from ADC. I'm using MikroC. I'm also using MCP4921 DAC.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Obviously you did something wrong.I'm unable to read data from ADC
sbit Conversion_Select at RC1_bit;
sbit Conversion_Select_Direction at TRISC1_bit;
sbit Slave_Select at RA5_bit;
sbit Slave_Select_Direction at TRISA5_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;
void Init_Main()
{
Slave_Select=1;
Slave_Select_Direction=1;
Conversion_Select=0;
Conversion_Select_Direction=0;
SPI1_Init_Advanced(_SPI_SLAVE_SS_ENABLE,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_HIGH_2_LOW);
}
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.*/
}
short ADC_Value ()
{
short take, buffer;
Conversion_Select=1;
Delay_us(10);
Conversion_Select=0;
take=SPI_Read1();
buffer= (take) & 0x0000;
buffer= (buffer << 8);
take=SPI_Read1();
buffer = (buffer) & (take);
return (buffer);
}
void main()
{
char txt[16];
short i;
ANSEL = 0;
ANSELH = 0;
Init_Main();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
while(1)
{
i = ADC_Value();
ShortToStr(i,txt);
Lcd_Out(1,5,"ADC test");
Lcd_Out(2,1,txt);
}
}
take=SPI_Read1();
buffer= (take) & 0x0000; --> gives 0 !
buffer= (buffer << 8);
take=SPI_Read1();
buffer = (buffer) & (take);
return (buffer);
take=SPI_Read1();
buffer= (take<< 8);
take=SPI_Read1();
buffer = buffer + (take& 0x00FF) ;
return (buffer);
Still, the data transferred to MCU by the ADC is not displayed on LCD.hello,
Code:take=SPI_Read1(); buffer= (take) & 0x0000; --> gives 0 ! buffer= (buffer << 8); take=SPI_Read1(); buffer = (buffer) & (take); return (buffer);
maybe like this ?
Code:take=SPI_Read1(); buffer= (take<< 8); take=SPI_Read1(); buffer = buffer + (take& 0x00FF) ; return (buffer);
void ShortToStr(short input, char *output); |
Converts input short (signed byte) number to a string |
void WordToStr(unsigned input, char *output); |
Converts input word to a string. |