Hello
I'm trying to write a SPI function in C language that starts a 16 bits conversion on a ADS817.
According to datasheet 22 clock edges are required :
Here is the code i've wrote so far :
unsigned int ADS8317_read(void)
{
unsigned char Dummy;
unsigned int ADC_result;
/***********************************************************************/
// Configure SPI
ADS8317_SPIEN = 0; // Disable the interface
// Apply new SPI settings for ADS8317
ADS8317_SPISTATbits.CKE = 1; // Transmit data from active to idle clock state
ADS8317_SPISTATbits.SMP = 0; // Input sampled at middle of data output time
ADS8317_SPIEN = 1; // Enable the interface
/***********************************************************************/
ADS8317_CS_IO = 0; // Enable CS
ADS8317_SPI_IF = 0; // Clear SPI Flag
/*********************************/
ADS8317_SSPBUF = 0x01; // Send dummy value (0x01) in order to get the FIRST 8 bit byte
while(!ADS8317_SPI_IF);ADS8317_SPI_IF = 0; // Wait until data is shifted out
Dummy = ADS8317_SSPBUF; // Get the FIRST 8 bit byte ( 8 clock edges )
/*********************************/
/*********************************/
ADS8317_SSPBUF = 0x01; // Send dummy value (0x01) in order to get the FIRST 8 bit byte
while(!ADS8317_SPI_IF);ADS8317_SPI_IF = 0; // Wait until data is shifted out
Dummy = ADS8317_SSPBUF; // Get 8 bit byte ( 8 clock edges )
/*********************************/
/*********************************/
ADS8317_SSPBUF = 0x01; // Send dummy value (0x01) in order to get the FIRST 8 bit byte
while(!ADS8317_SPI_IF);ADS8317_SPI_IF = 0; // Wait until data is shifted out
ADC_result = ADS8317_SSPBUF; // Get 8 bit byte ( 8 clock edges )
/*********************************/
ADS8317_CS_IO = 1; // Disable CS
/***********************************************************************/
ADS8317_SPIEN = 0; // Disable the interface
/***********************************************************************/
return ADC_result;
}
Here i send 3 x 8 clock edges to the chip in order to get the conversion result on MISO line.
For test purposes, V+ voltage is 2.41V and V- pin is grounded.
ADS8317 returns a 3 bytes value but i don't know how retrieve this result (ADC_result) and return it into an integer.
Can someone show me how to proceed please ?
How could i verify that ADC_result value is correct according to V+ pin voltage ?
I wondering the following, but i'm not sure this is correct :
ADC_result = ( 32768 x V+ ) / Vs
Vs supply voltage is 3V.
if V+ = 2.41
ADC_result should be ~= 26208.
Do you confirm this calculation is correct ?
Many thanks for your help and advices.
Best regards,