ADS124S08 Example C Code
1.0.0
|
Example of a hardware abstraction layer. More...
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 |
Example of a hardware abstraction layer.
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.
#define SPI_SPEED 2000000 |
#define SPI_WORD_SIZE 8 |
void delay_ms | ( | const uint32_t | delay_time_ms | ) |
delay_ms() Provides a timing delay with 'ms' resolution.
[in] | delay_time_ms | Is the number of milliseconds to delay. |
void delay_us | ( | const uint32_t | delay_time_us | ) |
delay_us() Provides a timing delay with 'us' resolution.
[in] | delay_time_us | Is the number of microseconds to delay. |
void enableDRDYinterrupt | ( | const bool | intEnable | ) |
enableDRDYinterrupt() Enables or disables the nDRDY interrupt.
[in] | intEnable | Where interrupt is enabled with true; false disables the interrupt. |
bool getCS | ( | void | ) |
getCS() Returns the state of the MCU's ADC_CS GPIO pin
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
bool getSTART | ( | void | ) |
getSTART() Returns the state of the MCU's ADC_START GPIO pin
void GPIO_DRDY_IRQHandler | ( | uint_least8_t | index | ) |
GPIO_DRDY_IRQHandler() Interrupt handler for nDRDY falling edge interrupt.
[in] | index | Position of the interrupt for callback. |
bool InitADCPeripherals | ( | SPI_Handle * | spiHdl | ) |
InitADCPeripherals() Initialize MCU peripherals and pins to interface with ADC.
[in] | *adcChars | ADC characteristics |
[in] | *spiHdl | SPI_Handle pointer for TI Drivers |
void InitGPIO | ( | void | ) |
InitGPIO() Configures the MCU's GPIO pins that interface with the ADC.
void InitSPI | ( | void | ) |
InitSPI() Configures the MCU's SPI peripheral, for interfacing with the ADC.
void sendPowerdown | ( | SPI_Handle | spiHdl | ) |
sendPowerdown() Sends POWERDOWN command through SPI
[in] | spiHdl | SPI_Handle pointer for TI Drivers |
void sendRESET | ( | SPI_Handle | spiHdl | ) |
sendRESET() Sends RESET Command through SPI, then waits 4096 tCLKs
[in] | spiHdl | SPI_Handle pointer for TI Drivers |
void sendSTART | ( | SPI_Handle | spiHdl | ) |
sendSTART() Sends START Command through SPI
[in] | spiHdl | SPI_Handle pointer for TI Drivers |
void sendSTOP | ( | SPI_Handle | spiHdl | ) |
sendSTOP() Sends STOP Command through SPI
[in] | spiHdl | SPI_Handle pointer for TI Drivers |
void sendWakeup | ( | SPI_Handle | spiHdl | ) |
sendWakeup() Sends WAKEUP command through SPI
[in] | spiHdl | SPI_Handle pointer for TI Drivers |
void setCS | ( | bool | state | ) |
setCS() Sets the state of the "/CS" GPIO pin
[in] | level | Sets the state of the "/CS" pin |
void setDRDYinterruptStatus | ( | const bool | value | ) |
setDRDYinterruptStatus() Sets the value of the nDRDY interrupt flag.
[in] | value | where status is set with true; false clears the status. |
void setRESET | ( | bool | state | ) |
setRESET() Sets the state of the MCU ADC_RESET GPIO pin
[in] | state | level of /RESET pin (false = low, true = high) |
void setSTART | ( | bool | state | ) |
setSTART() Sets the state of the MCU START GPIO pin
[in] | state | level of START pin (false = low, true = high) |
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
[in] | spiHdl | SPI_Handle from TI Drivers |
[in] | *DataTx | array of SPI data to send on MOSI pin |
[in] | *DataRx | array of SPI data that will be received from MISO pin |
[in] | byteLength | number of bytes to send/receive on the SPI |
uint8_t spiSendReceiveByte | ( | SPI_Handle | spiHdl, |
uint8_t | dataTx | ||
) |
spiSendReceiveByte() Sends a single byte to ADC and returns a response
[in] | spiHdl | SPI_Handle from TI Drivers |
[in] | dataTx | byte to send on DIN pin |
void toggleRESET | ( | void | ) |
void toggleSTART | ( | bool | direction | ) |
toggleSTART() Pulses the START GPIO pin low param[in] direction sets the toggle direction base on initial START pin configuration
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.
[in] | timeout_ms | number of milliseconds to allow until a timeout |
|
static |
SPI_Handle g_SPIhandle |