Skip to content

wrgallo/ADS127L11

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ADS127L11 ADC Library


Product Details | Datasheet | ADS127L11 Example C Code


Overview

Description
This library aims to be a port of the ADS127L11 Example C Code provided by Texas Instrument.

Hardware Abstraction Layer
Use a ads_hal_t constant to set your SPI and GPIO functions.

typedef struct _ads_hal_t
{
    // Required parameters
    cb_write_pin_t          write_cs;             //!< Write SPI CS Pin status
    cb_spi_exchange_array_t spi_exchange_array;   //!< Send and receive multiple bytes over SPI
    cb_spi_exchange_byte_t  spi_exchange_byte;    //!< Send and receive a single byte over SPI

    // Optional parameters (can be NULL)
    cb_write_pin_t          write_start;          //!< Write START Pin status (can be NULL if the pin is floating)
    cb_write_pin_t          write_reset;          //!< Write RESET Pin status (can be NULL if the pin is floating)
    cb_delay_ms_t           delay_ms;             //!< Wait milliseconds (can be NULL)
    void*                   param;                //!< Extra param for callback handlers (can be NULL)
} ads_hal_t;

Save the ads_hal_t and basic configurations inside the ads127l11_t instance and that's it.

/// @brief ADS127L11 instance
typedef struct _ads127l11_t
{
    ads_hal_t                     hal;                            //!< HAL Callback Functions
    const ads127l11_config4_reg_t cfg4_reg;                       //!< CONFIG4 Register Value
    const bool                    spi_3_wire;                     //!< Flag SPI 3 Wire is enabled
    uint8_t                       reg[ ADS127L11_NUM_REGISTERS ]; //!< ADS127L11 Register Map
} ads127l11_t;

Configuration
Initialize the ads127l11_t instance with ads127l11_setup

/// @brief Setup the ADS127L11 before usage
///
/// @note Call 'ads127l11_write_register' for every other register configuration after calling this function
///
/// @param[in] ads 'ads127l11_t' instance
/// @param[in] config1_reg CONFIG1_REG register configuration
/// @param[in] config2_reg CONFIG2_REG register configuration
/// @param[in] config3_reg CONFIG3_REG register configuration
/// @param[in] config4_reg CONFIG4_REG register configuration
/// @return True if all config registers were written successfully
bool ads127l11_setup( ads127l11_t* ads,
    const ads127l11_config1_reg_t config1_reg,
    const ads127l11_config2_reg_t config2_reg,
    const ads127l11_config3_reg_t config3_reg,
    const ads127l11_config4_reg_t config4_reg );

Use ads127l11_read_data to get a sample when the ADC is ready.

/// @brief ADC sample data information
typedef struct _ads127l11_ch_data_t
{
    uint8_t     status;   //!< Status
    uint8_t     crc;      //!< CRC
    int32_t     data;     //!< ADC sample as signed 32-bit word
} ads127l11_ch_data_t;

/// @brief Read sample
/// @param[in] ads 'ads127l11_t' instance
/// @param[out] data Pointer to where data will be saved (can be NULL)
/// @return ADC sample as a signed 32-bit word
int32_t  ads127l11_read_data(ads127l11_t* ads, ads127l11_ch_data_t* data);

About

ADS127L11 ADC library as a port of the TI's SBAC296 example code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages