Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to read a 16 bit result issued from ADS8317 ADC ?

Status
Not open for further replies.

crocu

Member
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 :

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 :

SPI_capture_ADS8317.png

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 ?
 
You'll need three read cycles with the CS bit low..

The first byte received will contain 3 bits
The second contains 8 bits
The last contains the remaining 5 bits.

Be aware that the first bit always seems to be low...


Oh! and the bits represent 0 to 65536 which in turn represents 0 to Vmax

so... ADCin *3.000 / 65535

Your output appears to be 0100111000111000 0r 0001-1100-0111-0010 or 0x1C72
For 2.4 volts I would expect 0xCCC !!!
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top