Hello,
I'm trying to write a SPI function that will start a 16 bits conversion with a ADS8317
According to the datasheet, page 8 , i should send more than 22 clocks edges to get the conversion completed and the result returned.
My problem is i do not understand how i should shift or built the 16 bits result integer .
Datasheet says MSB comes first ( after 5th clock edge ) and then LSB comes up.
Can someone lights me, i really don't know how to proceed.
Here is the function i wrote so far :
For test purposes, i've applied 2.41V on ADS8317 V+ pin.
V- is grounded.
Vref set to 3.0V
This is the capture of the SPI frame when running the function :
I do not know how to deal with the 3 bytes returned on MISO line
What 16 bits result the following represents ?
How could i verify this 16 bit result is correct and represents 2.41V ?
I'm trying to write a SPI function that will start a 16 bits conversion with a ADS8317
According to the datasheet, page 8 , i should send more than 22 clocks edges to get the conversion completed and the result returned.
My problem is i do not understand how i should shift or built the 16 bits result integer .
Datasheet says MSB comes first ( after 5th clock edge ) and then LSB comes up.
Can someone lights me, i really don't know how to proceed.
Here is the function i wrote so far :
Code:
unsigned int ADS8317_read(void)
{
unsigned int pressure_MSB;
unsigned int pressure_LSB;
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_SPICON1 = ADS8317_SPICON1_CFG; // Set SPICON1 register
ADS8317_SPIEN = 1; // Enable the interface
/***********************************************************************/
ADS8317_CS_IO = 0; // Enable CS
ADS8317_SPI_IF = 0; // Clear SPI Flag
/*********************************/
ADS8317_SSPBUF = 0x00; // Send dummy value (0x00) in order to get the FIRST 8 bit byte
while(!ADS8317_SPI_IF);ADS8317_SPI_IF = 0; // Wait until data is shifted out
pressure_MSB = ADS8317_SSPBUF; // Get MSB
/*********************************/
/*********************************/
ADS8317_SSPBUF = 0x00; // Send dummy value (0x00) in order to get the FIRST 8 bit byte
while(!ADS8317_SPI_IF);ADS8317_SPI_IF = 0; // Wait until data is shifted out
pressure_LSB = ADS8317_SSPBUF; // Get LSB
/*********************************/
/*********************************/
ADS8317_SSPBUF = 0x00; // Send dummy value (0x00) 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
/*********************************/
ADS8317_CS_IO = 1; // Disable CS
/***********************************************************************/
ADS8317_SPIEN = 0; // Disable the interface
/***********************************************************************/
return ADC_result;
}
For test purposes, i've applied 2.41V on ADS8317 V+ pin.
V- is grounded.
Vref set to 3.0V
This is the capture of the SPI frame when running the function :
I do not know how to deal with the 3 bytes returned on MISO line
What 16 bits result the following represents ?
How could i verify this 16 bit result is correct and represents 2.41V ?