ADS124S08 Example C Code  1.0.0
Macros | Functions | Variables
hal.c File Reference

Example of a hardware abstraction layer. More...

#include "hal.h"
#include "ads124s08.h"
Include dependency graph for hal.c:

Macros

#define SPI_SPEED   2000000
 
#define SPI_WORD_SIZE   8
 

Functions

void InitGPIO (void)
 InitGPIO() Configures the MCU's GPIO pins that interface with the ADC. More...
 
void InitSPI (void)
 InitSPI() Configures the MCU's SPI peripheral, for interfacing with the ADC. More...
 
void GPIO_DRDY_IRQHandler (uint_least8_t index)
 GPIO_DRDY_IRQHandler() Interrupt handler for nDRDY falling edge interrupt. More...
 
bool getDRDYinterruptStatus (void)
 getDRDYinterruptStatus() Gets the current status of nDRDY interrupt flag. More...
 
void setDRDYinterruptStatus (const bool value)
 setDRDYinterruptStatus() Sets the value of the nDRDY interrupt flag. More...
 
void enableDRDYinterrupt (const bool intEnable)
 enableDRDYinterrupt() Enables or disables the nDRDY interrupt. More...
 
void delay_ms (const uint32_t delay_time_ms)
 delay_ms() Provides a timing delay with 'ms' resolution. More...
 
void delay_us (const uint32_t delay_time_us)
 delay_us() Provides a timing delay with 'us' resolution. More...
 
bool InitADCPeripherals (SPI_Handle *spiHdl)
 InitADCPeripherals() Initialize MCU peripherals and pins to interface with ADC. More...
 
bool getRESET (void)
 getRESET() Returns the state of the MCU's ADC_RESET GPIO pin More...
 
void setRESET (bool state)
 setRESET() Sets the state of the MCU ADC_RESET GPIO pin More...
 
void toggleRESET (void)
 toggleRESET() Pulses the /RESET GPIO pin low More...
 
bool getSTART (void)
 getSTART() Returns the state of the MCU's ADC_START GPIO pin More...
 
void setSTART (bool state)
 setSTART() Sets the state of the MCU START GPIO pin More...
 
void toggleSTART (bool direction)
 toggleSTART() Pulses the START GPIO pin low param[in] direction sets the toggle direction base on initial START pin configuration More...
 
void sendSTART (SPI_Handle spiHdl)
 sendSTART() Sends START Command through SPI More...
 
void sendSTOP (SPI_Handle spiHdl)
 sendSTOP() Sends STOP Command through SPI More...
 
void sendRESET (SPI_Handle spiHdl)
 sendRESET() Sends RESET Command through SPI, then waits 4096 tCLKs More...
 
void sendWakeup (SPI_Handle spiHdl)
 sendWakeup() Sends WAKEUP command through SPI More...
 
void sendPowerdown (SPI_Handle spiHdl)
 sendPowerdown() Sends POWERDOWN command through SPI More...
 
void setCS (bool state)
 setCS() Sets the state of the "/CS" GPIO pin More...
 
bool getCS (void)
 getCS() Returns the state of the MCU's ADC_CS GPIO pin More...
 
bool waitForDRDYHtoL (uint32_t timeout_ms)
 waitForDRDYHtoL() Waits for a nDRDY GPIO to go from High to Low or until a timeout condition occurs The DRDY output line is used as a status signal to indicate when a conversion has been completed. DRDY goes low when new data is available. More...
 
void spiSendReceiveArrays (SPI_Handle spiHdl, uint8_t DataTx[], uint8_t DataRx[], uint8_t byteLength)
 spiSendReceiveArrays() Sends SPI commands to ADC and returns a response in array format More...
 
uint8_t spiSendReceiveByte (SPI_Handle spiHdl, uint8_t dataTx)
 spiSendReceiveByte() Sends a single byte to ADC and returns a response More...
 

Variables

SPI_Handle g_SPIhandle
 
static volatile bool flag_nDRDY_INTERRUPT = false
 

Detailed Description

Example of a hardware abstraction layer.

Warning
This software utilizes TI Drivers

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of Texas Instruments Incorporated nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

#define SPI_SPEED   2000000
#define SPI_WORD_SIZE   8

Function Documentation

void delay_ms ( const uint32_t  delay_time_ms)

delay_ms() Provides a timing delay with 'ms' resolution.

Parameters
[in]delay_time_msIs the number of milliseconds to delay.
Returns
none
void delay_us ( const uint32_t  delay_time_us)

delay_us() Provides a timing delay with 'us' resolution.

Parameters
[in]delay_time_usIs the number of microseconds to delay.
Returns
none
void enableDRDYinterrupt ( const bool  intEnable)

enableDRDYinterrupt() Enables or disables the nDRDY interrupt.

Parameters
[in]intEnableWhere interrupt is enabled with true; false disables the interrupt.
Returns
None
bool getCS ( void  )

getCS() Returns the state of the MCU's ADC_CS GPIO pin

Returns
boolean level of CS pin (false = low, true = high)
bool getDRDYinterruptStatus ( void  )

getDRDYinterruptStatus() Gets the current status of nDRDY interrupt flag.

@ return boolean status of flag_nDRDY_INTERRUPT

bool getRESET ( void  )

getRESET() Returns the state of the MCU's ADC_RESET GPIO pin

Returns
boolean level of /RESET pin (false = low, true = high)
bool getSTART ( void  )

getSTART() Returns the state of the MCU's ADC_START GPIO pin

Returns
boolean level of START pin (false = low, true = high)
void GPIO_DRDY_IRQHandler ( uint_least8_t  index)

GPIO_DRDY_IRQHandler() Interrupt handler for nDRDY falling edge interrupt.

Parameters
[in]indexPosition of the interrupt for callback.
Returns
None
bool InitADCPeripherals ( SPI_Handle *  spiHdl)

InitADCPeripherals() Initialize MCU peripherals and pins to interface with ADC.

Parameters
[in]*adcCharsADC characteristics
[in]*spiHdlSPI_Handle pointer for TI Drivers
Returns
true for successful initialization false for unsuccessful initialization
1 if ( !InitADCPeripherals( &spiHdl ) ) {
2  // Error initializing MCU SPI Interface
3  Display_printf( displayHdl, 0, 0, "Error initializing master SPI\n" );
4  return( false );
5 }
6 // MCU initialized ADC successfully
7 return( true );

Here is the call graph for this function:

void InitGPIO ( void  )

InitGPIO() Configures the MCU's GPIO pins that interface with the ADC.

Returns
none

Here is the call graph for this function:

void InitSPI ( void  )

InitSPI() Configures the MCU's SPI peripheral, for interfacing with the ADC.

Returns
None
void sendPowerdown ( SPI_Handle  spiHdl)

sendPowerdown() Sends POWERDOWN command through SPI

Parameters
[in]spiHdlSPI_Handle pointer for TI Drivers
Returns
None

Here is the call graph for this function:

void sendRESET ( SPI_Handle  spiHdl)

sendRESET() Sends RESET Command through SPI, then waits 4096 tCLKs

Parameters
[in]spiHdlSPI_Handle pointer for TI Drivers
Returns
None

Here is the call graph for this function:

void sendSTART ( SPI_Handle  spiHdl)

sendSTART() Sends START Command through SPI

Parameters
[in]spiHdlSPI_Handle pointer for TI Drivers
Returns
None

Here is the call graph for this function:

void sendSTOP ( SPI_Handle  spiHdl)

sendSTOP() Sends STOP Command through SPI

Parameters
[in]spiHdlSPI_Handle pointer for TI Drivers
Returns
None

Here is the call graph for this function:

void sendWakeup ( SPI_Handle  spiHdl)

sendWakeup() Sends WAKEUP command through SPI

Parameters
[in]spiHdlSPI_Handle pointer for TI Drivers
Returns
None

Here is the call graph for this function:

void setCS ( bool  state)

setCS() Sets the state of the "/CS" GPIO pin

Parameters
[in]levelSets the state of the "/CS" pin
Returns
None
void setDRDYinterruptStatus ( const bool  value)

setDRDYinterruptStatus() Sets the value of the nDRDY interrupt flag.

Parameters
[in]valuewhere status is set with true; false clears the status.
Returns
None
void setRESET ( bool  state)

setRESET() Sets the state of the MCU ADC_RESET GPIO pin

Parameters
[in]statelevel of /RESET pin (false = low, true = high)
Returns
None
void setSTART ( bool  state)

setSTART() Sets the state of the MCU START GPIO pin

Parameters
[in]statelevel of START pin (false = low, true = high)
Returns
None

Here is the call graph for this function:

void spiSendReceiveArrays ( SPI_Handle  spiHdl,
uint8_t  DataTx[],
uint8_t  DataRx[],
uint8_t  byteLength 
)

spiSendReceiveArrays() Sends SPI commands to ADC and returns a response in array format

Parameters
[in]spiHdlSPI_Handle from TI Drivers
[in]*DataTxarray of SPI data to send on MOSI pin
[in]*DataRxarray of SPI data that will be received from MISO pin
[in]byteLengthnumber of bytes to send/receive on the SPI
Returns
None

Here is the call graph for this function:

uint8_t spiSendReceiveByte ( SPI_Handle  spiHdl,
uint8_t  dataTx 
)

spiSendReceiveByte() Sends a single byte to ADC and returns a response

Parameters
[in]spiHdlSPI_Handle from TI Drivers
[in]dataTxbyte to send on DIN pin
Returns
SPI response byte

Here is the call graph for this function:

void toggleRESET ( void  )

toggleRESET() Pulses the /RESET GPIO pin low

Returns
None

Here is the call graph for this function:

void toggleSTART ( bool  direction)

toggleSTART() Pulses the START GPIO pin low param[in] direction sets the toggle direction base on initial START pin configuration

Returns
None

Here is the call graph for this function:

bool waitForDRDYHtoL ( uint32_t  timeout_ms)

waitForDRDYHtoL() Waits for a nDRDY GPIO to go from High to Low or until a timeout condition occurs The DRDY output line is used as a status signal to indicate when a conversion has been completed. DRDY goes low when new data is available.

Parameters
[in]timeout_msnumber of milliseconds to allow until a timeout
Returns
Returns true if nDRDY interrupt occurred before the timeout
1 // Read next conversion result
2 if ( waitForDRDYHtoL( TIMEOUT_COUNTER ) ) {
3  adcValue = readConvertedData( spiHdl, &status, COMMAND );
4 } else {
5  // Error reading conversion result
6  Display_printf( displayHdl, 0, 0, "Timeout on conversion\n" );
7  return( false );
8 }

Variable Documentation

volatile bool flag_nDRDY_INTERRUPT = false
static
SPI_Handle g_SPIhandle