SimpleLink MCU SDK Driver APIs  tidrivers_msp43x_3_01_01_03
Data Structures | Macros | Typedefs | Enumerations | Variables
ADCBufMSP432.h File Reference

Detailed Description

ADC driver implementation for a MSP432 analog-to-digital converter.

============================================================================

Driver include

The ADC header file should be included in an application as follows:

#include <ti/drivers/adc/ADCBufMSP432.h>

Overview

This is a MSP432 specific implementation of the generic TI-RTOS ADC driver. The generic ADC API specified in ti/drivers/ADCBuf.h should be called by the application. The board file will define the device specific configuration, and casting in the general API will ensure that the correct device specific functions are called. It is advised to specify a ADCBufMSP432_ParamsExtension in the custom field of the ADCBuf_Params that suits the application at hand. The default settings will work for many, but not all, usecases.

General Behavior

The application should call ADCBuf_init() once by the application to set the isOpened flag to false, indicating that the driver is ready to be used.

The ADC driver is opened by calling ADCBuf_open() which in turn will set up interrupts and configure the internal components of the driver. However the ADC hardware or analog pins are not yet configured until the ADCBuf_convert() is called.

In order to perform an ADC conversion, the application should call ADCBuf_convert(). This call will request the ADC resource, configure the ADC, and perform the requested ADC conversion on the selected channel defined by the ADCBuf_Conversion structure.

Error handling

The following errors may occur when opening the ADC:

The following errors may occur when requesing an ADC conversion:

The following errors may occur when adjusting ADC results by calling ADCBuf_adjustRawValues():

Power Management

The power management framework will try to put the device into the most power efficient mode whenever possible. Please see the technical reference manual for further details on each power mode.

The ADCBufMSP432 driver sets a power constraint during operation to keep the device out of standby. When the operation has finished, the power constraint is released. The following statements are valid:

Supported Functions

API function Description
ADCBuf_init() Initialize ADC driver
ADCBuf_open() Open the ADC driver and configure driver
ADCBuf_convert() Perform ADC conversion
ADCBuf_convertCancel() Cancel ongoing ADC conversion
ADCBuf_close() Close ADC driver
ADCBuf_Params_init() Initialise ADCBuf_Params structure to default values
ADCBuf_adjustRawValues() Adjust ADC raw values based on gain and offset
ADCBuf_convertAdjustedToMicroVolts() Convert adjusted values to micro volts unit

Not Supported Functionality

TBD

Use Cases

Basic one-shot conversion

Perform one conversion on DIO30 in ADCBuf_RETURN_MODE_BLOCKING.

// Code will go here when the API is stable
// One shot and blocking mode
ADCBuf_Params param = {0};
param.samplingFrequency = 10000; //10K
ADCBufHandle adc = ADCBuf_open(Board_ADCBuf0, &param);
ADCBuf_Conversion conversion = {0};
conversion.samplesRequestedCount = 10;
conversion.sampleBuf = adcBuf;
conversion.adcChannel = Board_ADC0_CHANNEL_A0;
ADCBuf_convert(adc, &conversion, 1);
//Recurrence and callback mode
void myCallback(ADCBuf_Handle handle,
ADCBuf_Conversion *conversion,
void *activeADCBuffer)
{
//Process activeADCBuffer
for (i=0; i<conversion->sampleCount; i++) {
sum += activeADCBuffer[i];
}
avg = sum / conversion->sampleCount;
}
ADCBuf_Params param = {0};
param.samplingFrequency = 10000;
param.callbackFxn = myCallBack;
ADCBufHandle adc = ADCBuf_open(Board_ADCBuf0, &param);
ADCBuf_Conversion conversion[2] = {0};
conversion[0].samplesRequestedCount = 10;
conversion[0].sampleBuf = adcBuf0;
conversion[0].adcChannel = Board_ADC0_CHANNEL_A0;
conversion[1].samplesRequestedCount = 10;
conversion[1].sampleBuf = adcBuf1;
conversion[1].adcChannel = Board_ADC0_CHANNEL_A1;
ADCBuf_convert(adc, &conversion, 2);

Instrumentation

The ADC driver interface produces log statements if instrumentation is enabled.

Diagnostics Mask Log details
Diags_USER1 basic ADC operations performed
Diags_USER2 detailed ADC operations performed

#include <stdint.h>
#include <stdbool.h>
#include <ti/drivers/ADCBuf.h>
#include <ti/drivers/dpl/HwiP.h>
#include <ti/drivers/dpl/SemaphoreP.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/dma/UDMAMSP432.h>
#include <ti/devices/msp432p4xx/driverlib/adc14.h>
Include dependency graph for ADCBufMSP432.h:

Go to the source code of this file.

Data Structures

struct  ADCBufMSP432_ParamsExtension
 MSP432 specfic extension to ADCBuf_Params. More...
 
struct  ADCBufMSP432_Channels
 ADCMSP432 Channel setting These fields define channel-specific settings: GPIO and reference voltage. These settings happen when ADCBuf_convert() is called. More...
 
struct  ADCBufMSP432_HWAttrs
 ADCBufMSP432 Hardware attributes These fields are populated by PinMux tool but user is allowed to change for different channels setting. More...
 
struct  ADCBufMSP432_Object
 ADCBufMSP432 Object. More...
 

Macros

#define ADCBufMSP432_P4_0_A13   ((13 << 10) | 0x0340) /* ch 13, port 4, pin 0 */
 
#define ADCBufMSP432_P4_1_A12   ((12 << 10) | 0x0341) /* ch 12, port 4, pin 1 */
 
#define ADCBufMSP432_P4_2_A11   ((11 << 10) | 0x0342) /* ch 11, port 4, pin 2 */
 
#define ADCBufMSP432_P4_3_A10   ((10 << 10) | 0x0343) /* ch 10, port 4, pin 3 */
 
#define ADCBufMSP432_P4_4_A9   ((9 << 10) | 0x0344) /* ch 9, port 4, pin 4 */
 
#define ADCBufMSP432_P4_5_A8   ((8 << 10) | 0x0345) /* ch 8, port 4, pin 5 */
 
#define ADCBufMSP432_P4_6_A7   ((7 << 10) | 0x0346) /* ch 7, port 4, pin 6 */
 
#define ADCBufMSP432_P4_7_A6   ((6 << 10) | 0x0347) /* ch 6, port 4, pin 7 */
 
#define ADCBufMSP432_P5_0_A5   ((5 << 10) | 0x0350) /* ch 5, port 5, pin 0 */
 
#define ADCBufMSP432_P5_1_A4   ((4 << 10) | 0x0351) /* ch 4, port 5, pin 1 */
 
#define ADCBufMSP432_P5_2_A3   ((3 << 10) | 0x0352) /* ch 3, port 5, pin 2 */
 
#define ADCBufMSP432_P5_3_A2   ((2 << 10) | 0x0353) /* ch 2, port 5, pin 3 */
 
#define ADCBufMSP432_P5_4_A1   ((1 << 10) | 0x0354) /* ch 1, port 5, pin 4 */
 
#define ADCBufMSP432_P5_5_A0   ((0 << 10) | 0x0355) /* ch 0, port 5, pin 5 */
 
#define ADCBufMSP432_P6_0_A15   ((15 << 10) | 0x0360) /* ch 15, port 6, pin 0 */
 
#define ADCBufMSP432_P6_1_A14   ((14 << 10) | 0x0361) /* ch 14, port 6, pin 1 */
 
#define ADCBufMSP432_P8_2_A23   ((23 << 10) | 0x0382) /* ch 23, port 8, pin 2 */
 
#define ADCBufMSP432_P8_3_A22   ((22 << 10) | 0x0383) /* ch 22, port 8, pin 3 */
 
#define ADCBufMSP432_P8_4_A21   ((21 << 10) | 0x0384) /* ch 21, port 8, pin 4 */
 
#define ADCBufMSP432_P8_5_A20   ((20 << 10) | 0x0385) /* ch 20, port 8, pin 5 */
 
#define ADCBufMSP432_P8_6_A19   ((19 << 10) | 0x0386) /* ch 19, port 8, pin 6 */
 
#define ADCBufMSP432_P8_7_A18   ((18 << 10) | 0x0387) /* ch 18, port 8, pin 7 */
 
#define ADCBufMSP432_P9_0_A17   ((17 << 10) | 0x0390) /* ch 17, port 9, pin 0 */
 
#define ADCBufMSP432_P9_1_A16   ((16 << 10) | 0x0391) /* ch 16, port 9, pin 1 */
 

Typedefs

typedef enum ADCBufMSP432_Reference_Source ADCBufMSP432_Reference_Source
 ADCMSP432 reference source These fields are used by ADCBufMSP432_HWAttrs to specify the reference voltage for each channel. More...
 
typedef enum ADCBufMSP432_Sampling_Duration ADCBufMSP432_Sampling_Duration
 ADCMSP432 sampling duration These fields define the MSP432 ADC sampling duration (sample and hold time) in the pulse width unit. User can specify the differnt sampling duration in the ADCBufMSP432_ParamsExtension when opening the ADC. More...
 
typedef enum ADCBufMSP432_Timer_Reference_Source ADCBufMSP432_Timer_Reference_Source
 ADCMSP432 timer trigger source These fields are used by ADCBufMSP432_HWAttrs to specify the Timer Capture for each channel. More...
 
typedef struct ADCBufMSP432_ParamsExtension ADCBufMSP432_ParamsExtension
 MSP432 specfic extension to ADCBuf_Params. More...
 
typedef struct ADCBufMSP432_Channels ADCBufMSP432_Channels
 ADCMSP432 Channel setting These fields define channel-specific settings: GPIO and reference voltage. These settings happen when ADCBuf_convert() is called. More...
 
typedef struct ADCBufMSP432_HWAttrs ADCBufMSP432_HWAttrs
 ADCBufMSP432 Hardware attributes These fields are populated by PinMux tool but user is allowed to change for different channels setting. More...
 
typedef struct ADCBufMSP432_Object ADCBufMSP432_Object
 ADCBufMSP432 Object. More...
 

Enumerations

enum  ADCBufMSP432_Reference_Source {
  ADCBufMSP432_VREFPOS_AVCC_VREFNEG_VSS = ADC_VREFPOS_AVCC_VREFNEG_VSS,
  ADCBufMSP432_VREFPOS_INTBUF_VREFNEG_VSS = ADC_VREFPOS_INTBUF_VREFNEG_VSS,
  ADCBufMSP432_VREFPOS_EXTPOS_VREFNEG_EXTNEG = ADC_VREFPOS_EXTPOS_VREFNEG_EXTNEG,
  ADCBufMSP432_VREFPOS_EXTBUF_VREFNEG_EXTNEG = ADC_VREFPOS_EXTBUF_VREFNEG_EXTNEG
}
 ADCMSP432 reference source These fields are used by ADCBufMSP432_HWAttrs to specify the reference voltage for each channel. More...
 
enum  ADCBufMSP432_Sampling_Duration {
  ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_4 = ADC_PULSE_WIDTH_4,
  ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_8 = ADC_PULSE_WIDTH_8,
  ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_16 = ADC_PULSE_WIDTH_16,
  ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_32 = ADC_PULSE_WIDTH_32,
  ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_64 = ADC_PULSE_WIDTH_64,
  ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_96 = ADC_PULSE_WIDTH_96,
  ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_128 = ADC_PULSE_WIDTH_128,
  ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_192 = ADC_PULSE_WIDTH_192
}
 ADCMSP432 sampling duration These fields define the MSP432 ADC sampling duration (sample and hold time) in the pulse width unit. User can specify the differnt sampling duration in the ADCBufMSP432_ParamsExtension when opening the ADC. More...
 
enum  ADCBufMSP432_Timer_Reference_Source {
  ADCBufMSP432_TIMERA0_CAPTURECOMPARE1 = 0,
  ADCBufMSP432_TIMERA0_CAPTURECOMPARE2 = 1,
  ADCBufMSP432_TIMERA1_CAPTURECOMPARE1 = 2,
  ADCBufMSP432_TIMERA1_CAPTURECOMPARE2 = 3,
  ADCBufMSP432_TIMERA2_CAPTURECOMPARE1 = 4,
  ADCBufMSP432_TIMERA2_CAPTURECOMPARE2 = 5,
  ADCBufMSP432_TIMERA3_CAPTURECOMPARE1 = 6
}
 ADCMSP432 timer trigger source These fields are used by ADCBufMSP432_HWAttrs to specify the Timer Capture for each channel. More...
 

Variables

const ADCBuf_FxnTable ADCBufMSP432_fxnTable
 

Macro Definition Documentation

#define ADCBufMSP432_P4_0_A13   ((13 << 10) | 0x0340) /* ch 13, port 4, pin 0 */
#define ADCBufMSP432_P4_1_A12   ((12 << 10) | 0x0341) /* ch 12, port 4, pin 1 */
#define ADCBufMSP432_P4_2_A11   ((11 << 10) | 0x0342) /* ch 11, port 4, pin 2 */
#define ADCBufMSP432_P4_3_A10   ((10 << 10) | 0x0343) /* ch 10, port 4, pin 3 */
#define ADCBufMSP432_P4_4_A9   ((9 << 10) | 0x0344) /* ch 9, port 4, pin 4 */
#define ADCBufMSP432_P4_5_A8   ((8 << 10) | 0x0345) /* ch 8, port 4, pin 5 */
#define ADCBufMSP432_P4_6_A7   ((7 << 10) | 0x0346) /* ch 7, port 4, pin 6 */
#define ADCBufMSP432_P4_7_A6   ((6 << 10) | 0x0347) /* ch 6, port 4, pin 7 */
#define ADCBufMSP432_P5_0_A5   ((5 << 10) | 0x0350) /* ch 5, port 5, pin 0 */
#define ADCBufMSP432_P5_1_A4   ((4 << 10) | 0x0351) /* ch 4, port 5, pin 1 */
#define ADCBufMSP432_P5_2_A3   ((3 << 10) | 0x0352) /* ch 3, port 5, pin 2 */
#define ADCBufMSP432_P5_3_A2   ((2 << 10) | 0x0353) /* ch 2, port 5, pin 3 */
#define ADCBufMSP432_P5_4_A1   ((1 << 10) | 0x0354) /* ch 1, port 5, pin 4 */
#define ADCBufMSP432_P5_5_A0   ((0 << 10) | 0x0355) /* ch 0, port 5, pin 5 */
#define ADCBufMSP432_P6_0_A15   ((15 << 10) | 0x0360) /* ch 15, port 6, pin 0 */
#define ADCBufMSP432_P6_1_A14   ((14 << 10) | 0x0361) /* ch 14, port 6, pin 1 */
#define ADCBufMSP432_P8_2_A23   ((23 << 10) | 0x0382) /* ch 23, port 8, pin 2 */
#define ADCBufMSP432_P8_3_A22   ((22 << 10) | 0x0383) /* ch 22, port 8, pin 3 */
#define ADCBufMSP432_P8_4_A21   ((21 << 10) | 0x0384) /* ch 21, port 8, pin 4 */
#define ADCBufMSP432_P8_5_A20   ((20 << 10) | 0x0385) /* ch 20, port 8, pin 5 */
#define ADCBufMSP432_P8_6_A19   ((19 << 10) | 0x0386) /* ch 19, port 8, pin 6 */
#define ADCBufMSP432_P8_7_A18   ((18 << 10) | 0x0387) /* ch 18, port 8, pin 7 */
#define ADCBufMSP432_P9_0_A17   ((17 << 10) | 0x0390) /* ch 17, port 9, pin 0 */
#define ADCBufMSP432_P9_1_A16   ((16 << 10) | 0x0391) /* ch 16, port 9, pin 1 */

Typedef Documentation

ADCMSP432 reference source These fields are used by ADCBufMSP432_HWAttrs to specify the reference voltage for each channel.

ADCMSP432 sampling duration These fields define the MSP432 ADC sampling duration (sample and hold time) in the pulse width unit. User can specify the differnt sampling duration in the ADCBufMSP432_ParamsExtension when opening the ADC.

ADCMSP432 timer trigger source These fields are used by ADCBufMSP432_HWAttrs to specify the Timer Capture for each channel.

MSP432 specfic extension to ADCBuf_Params.

To use non-default MSP432 specific parameters when calling ADCBuf_open(), a pointer to an instance of this struct must be specified in ADCBuf_Params::custom. Alternatively, these values can be set using the control function after calling ADCBuf_open().

ADCMSP432 Channel setting These fields define channel-specific settings: GPIO and reference voltage. These settings happen when ADCBuf_convert() is called.

ADCBufMSP432 Hardware attributes These fields are populated by PinMux tool but user is allowed to change for different channels setting.

A sample structure is shown below:

1  ADCBufMSP432_Channels adcBufMSP432Channels[] = {
2  {
3  .adcPin = ADCBufMSP432_P5_5_A0,
4  .refSource = ADCBufMSP432_VREFPOS_INTBUF_VREFNEG_VSS,
5  .refVoltage = 2500000
6  }
7  };
8  const ADCBufMSP432_HWAttrs adcbufMSP432HWAttrs[] = {
9  {
10  .intPriority = ~0,
11  .channelSetting = adcBufMSP432Channels,
12  .adcTimerTriggerSource = ADCBufMSP432_TIMERA0_CAPTURECOMPARE2
13 
14  }
15 };

ADCBufMSP432 Object.

The application must not access any member variables of this structure!

Enumeration Type Documentation

ADCMSP432 reference source These fields are used by ADCBufMSP432_HWAttrs to specify the reference voltage for each channel.

Enumerator
ADCBufMSP432_VREFPOS_AVCC_VREFNEG_VSS 
ADCBufMSP432_VREFPOS_INTBUF_VREFNEG_VSS 
ADCBufMSP432_VREFPOS_EXTPOS_VREFNEG_EXTNEG 
ADCBufMSP432_VREFPOS_EXTBUF_VREFNEG_EXTNEG 

ADCMSP432 sampling duration These fields define the MSP432 ADC sampling duration (sample and hold time) in the pulse width unit. User can specify the differnt sampling duration in the ADCBufMSP432_ParamsExtension when opening the ADC.

Enumerator
ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_4 
ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_8 
ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_16 
ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_32 
ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_64 
ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_96 
ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_128 
ADCBufMSP432_SAMPLING_DURATION_PULSE_WIDTH_192 

ADCMSP432 timer trigger source These fields are used by ADCBufMSP432_HWAttrs to specify the Timer Capture for each channel.

Enumerator
ADCBufMSP432_TIMERA0_CAPTURECOMPARE1 
ADCBufMSP432_TIMERA0_CAPTURECOMPARE2 
ADCBufMSP432_TIMERA1_CAPTURECOMPARE1 
ADCBufMSP432_TIMERA1_CAPTURECOMPARE2 
ADCBufMSP432_TIMERA2_CAPTURECOMPARE1 
ADCBufMSP432_TIMERA2_CAPTURECOMPARE2 
ADCBufMSP432_TIMERA3_CAPTURECOMPARE1 

Variable Documentation

const ADCBuf_FxnTable ADCBufMSP432_fxnTable
Copyright 2016, Texas Instruments Incorporated