ADS131A04 Example C Code
1.0.0
|
#include "ads131a04.h"
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include "ti/devices/msp432e4/driverlib/driverlib.h"
Go to the source code of this file.
Macros | |
#define | nDRDY_PORT (GPIO_PORTM_BASE) |
#define | nDRDY_PIN (GPIO_PIN_0) |
#define | nDRDY_INT (INT_GPIOM) |
#define | nCS_PORT (GPIO_PORTK_BASE) |
#define | nCS_PIN (GPIO_PIN_5) |
#define | nRESET_PORT (GPIO_PORTK_BASE) |
#define | nRESET_PIN (GPIO_PIN_4) |
#define | HIGH ((bool) true) |
#define | LOW ((bool) false) |
Functions | |
void | InitADC (void) |
void | delay_ms (const uint32_t delay_time_ms) |
void | delay_us (const uint32_t delay_time_us) |
void | setCS (const bool state) |
void | setRESET (const bool state) |
void | toggleRESET (void) |
void | spiSendReceiveArrays (const uint8_t DataTx[], uint8_t DataRx[], const uint8_t byteLength) |
uint8_t | spiSendReceiveByte (const uint8_t dataTx) |
bool | waitForDRDYinterrupt (const uint32_t timeout_ms) |
#define HIGH ((bool) true) |
Alias used for setting GPIOs pins to the logic "high" state
#define LOW ((bool) false) |
Alias used for setting GPIOs pins to the logic "low" state
#define nCS_PIN (GPIO_PIN_5) |
#define nCS_PORT (GPIO_PORTK_BASE) |
#define nDRDY_INT (INT_GPIOM) |
#define nDRDY_PIN (GPIO_PIN_0) |
#define nDRDY_PORT (GPIO_PORTM_BASE) |
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 nRESET_PIN (GPIO_PIN_4) |
#define nRESET_PORT (GPIO_PORTK_BASE) |
void delay_ms | ( | const uint32_t | delay_time_ms | ) |
Provides a timing delay with 'ms' resolution.
delay_time_ms | number of milliseconds to delay. |
void delay_us | ( | const uint32_t | delay_time_us | ) |
Provides a timing delay with 'us' resolution.
delay_time_us | number of microseconds to delay. |
void InitADC | ( | void | ) |
Initializes MCU peripherals for interfacing with the ADC.
void setCS | ( | const bool | state | ) |
Controls the state of the nCS GPIO pin.
state | boolean indicating which state to set the nCS pin (0=low, 1=high) |
NOTE: The 'HIGH' and 'LOW' macros defined in hal.h can be passed to this function for the 'state' parameter value.
void setRESET | ( | const bool | state | ) |
Controls the state of the nRESET GPIO pin.
state | boolean indicating which state to set the nRESET pin (0=low, 1=high) |
NOTE: The 'HIGH' and 'LOW' macros defined in hal.h can be passed to this function for the 'state' parameter value.
void spiSendReceiveArrays | ( | const uint8_t | dataTx[], |
uint8_t | dataRx[], | ||
const uint8_t | byteLength | ||
) |
Sends SPI byte array on MOSI pin and captures MISO data to a byte array.
dataTx | byte array of SPI data to send on MOSI. |
dataRx | byte array of SPI data captured on MISO. |
byteLength | number of bytes to send & receive. |
NOTE: Make sure 'dataTx[]' and 'dataRx[]' contain at least as many bytes of data, as indicated by 'byteLength'.
uint8_t spiSendReceiveByte | ( | const uint8_t | dataTx | ) |
Sends SPI byte on MOSI pin and captures MISO return byte value.
dataTx | data byte to send on MOSI pin. |
NOTE: This function is called by spiSendReceiveArrays(). If it is called directly, then the nCS pin must also be directly controlled.
void toggleRESET | ( | void | ) |
Toggles the nRESET pin to trigger a reset (LOW, delay 2 ms, then HIGH).
NOTE: The adcStartup() function should be called after resetting the device.
bool waitForDRDYinterrupt | ( | const uint32_t | timeout_ms | ) |
Waits for the nDRDY interrupt or until the specified timeout occurs.
timeout_ms | number of milliseconds to wait before timeout event. |