Adding ADC Channels to TI-RTOS with the MSP432 Launchpad
Hardware:
SimpleLink MSP432P401R LaunchPad
Software:
TI-RTOS for MSPx - v2.20.00.06
With my Hearing Guard System since I am collecting data from an audio source I require an ADC input on the MSP432 However due to using multiple Booster Packs such as the 430BOOST-SHARP96430BOOST-SHARP96 LCD DLP-790ABP and the BOOSTXL-CC2650MABOOSTXL-CC2650MA as well as possibly others I need to more ADC channels than the 2(ADC0 and ADC1 that are defined in TI-RTOS This took a bit of researching and mainly trial and error but I was able to finally crack the code with how to enable the ADC channels for the MSP432 in TI-RTOS
For this exercises, I am going to use the "adcsinglechannel_MSP_EXP432P401R_TI" example found in the TI-RTOS for MSPx v2.20.00.06 package. This can be added to Code Composer Studio via Resource Explorer.
The first thing that is needed is add the the extra ADC channels to the Enum of ADC Channels in the MSP_EXP432P401R.h file:
Example for up to 9 channels:
/*!
* @def MSP_EXP432P401R_ADCName
* @brief Enum of ADC channels on the MSP_EXP432P401R dev board
*/
typedef enum MSP_EXP432P401R_ADCName {
MSP_EXP432P401R_ADC0 = 0,
MSP_EXP432P401R_ADC1,
MSP_EXP432P401R_ADC2,
MSP_EXP432P401R_ADC3,
MSP_EXP432P401R_ADC4,
MSP_EXP432P401R_ADC5,
MSP_EXP432P401R_ADC6,
MSP_EXP432P401R_ADC7,
MSP_EXP432P401R_ADC8,
MSP_EXP432P401R_ADCCOUNT
}MSP_EXP432P401R_ADCName;
Then, in the MSP_EXP432P401R.c file, add the ADC channels to the ADC configuration Structure.
NOTE; Each channel requires a configuration.
/* ADC objects */
ADCMSP432_Object adcMSP432Objects[MSP_EXP432P401R_ADCCOUNT];
/* ADC configuration structure */
const ADCMSP432_HWAttrs adcMSP432HWAttrs[MSP_EXP432P401R_ADCCOUNT] = {
{
.channel = ADC_INPUT_A0,
.gpioPort = GPIO_PORT_P5,
.gpioPin = GPIO_PIN5,
.gpioMode = GPIO_TERTIARY_MODULE_FUNCTION,
.refVoltage = REF_A_VREF2_5V,
.resolution = ADC_14BIT
},
{
.channel = ADC_INPUT_A1,
.gpioPort = GPIO_PORT_P5,
.gpioPin = GPIO_PIN4,
.gpioMode = GPIO_TERTIARY_MODULE_FUNCTION,
.refVoltage = REF_A_VREF1_45V,
.resolution = ADC_8BIT
},
{
.channel = ADC_INPUT_A2,
.gpioPort = GPIO_PORT_P5,
.gpioPin = GPIO_PIN3,
.gpioMode = GPIO_TERTIARY_MODULE_FUNCTION,
.refVoltage = REF_A_VREF2_5V,
.resolution = ADC_14BIT
},
{
.channel = ADC_INPUT_A3,
.gpioPort = GPIO_PORT_P5,
.gpioPin = GPIO_PIN2,
.gpioMode = GPIO_TERTIARY_MODULE_FUNCTION,
.refVoltage = REF_A_VREF2_5V,
.resolution = ADC_14BIT
},
{
.channel = ADC_INPUT_A4,
.gpioPort = GPIO_PORT_P5,
.gpioPin = GPIO_PIN1,
.gpioMode = GPIO_TERTIARY_MODULE_FUNCTION,
.refVoltage = REF_A_VREF2_5V,
.resolution = ADC_14BIT
},
{
.channel = ADC_INPUT_A5,
.gpioPort = GPIO_PORT_P5,
.gpioPin = GPIO_PIN0,
.gpioMode = GPIO_TERTIARY_MODULE_FUNCTION,
.refVoltage = REF_A_VREF2_5V,
.resolution = ADC_14BIT
},
{
.channel = ADC_INPUT_A6,
.gpioPort = GPIO_PORT_P4,
.gpioPin = GPIO_PIN7,
.gpioMode = GPIO_TERTIARY_MODULE_FUNCTION,
.refVoltage = REF_A_VREF2_5V,
.resolution = ADC_14BIT
},
{
.channel = ADC_INPUT_A7,
.gpioPort = GPIO_PORT_P4,
.gpioPin = GPIO_PIN6,
.gpioMode = GPIO_TERTIARY_MODULE_FUNCTION,
.refVoltage = REF_A_VREF2_5V,
.resolution = ADC_14BIT
},
{
.channel = ADC_INPUT_A8,
.gpioPort = GPIO_PORT_P4,
.gpioPin = GPIO_PIN5,
.gpioMode = GPIO_TERTIARY_MODULE_FUNCTION,
.refVoltage = REF_A_VREF2_5V,
.resolution = ADC_14BIT
}
};
Below this, there are defines for each channel to the ADC_config array.
const ADC_Config ADC_config[] = {
{
.fxnTablePtr = &ADCMSP432_fxnTable,
.object = &adcMSP432Objects[0],
.hwAttrs = &adcMSP432HWAttrs[0]
},
{
.fxnTablePtr = &ADCMSP432_fxnTable,
.object = &adcMSP432Objects[1],
.hwAttrs = &adcMSP432HWAttrs[1]
},
{
.fxnTablePtr = &ADCMSP432_fxnTable,
.object = &adcMSP432Objects[2],
.hwAttrs = &adcMSP432HWAttrs[2]
},
{
.fxnTablePtr = &ADCMSP432_fxnTable,
.object = &adcMSP432Objects[3],
.hwAttrs = &adcMSP432HWAttrs[3]
},
{
.fxnTablePtr = &ADCMSP432_fxnTable,
.object = &adcMSP432Objects[4],
.hwAttrs = &adcMSP432HWAttrs[4]
},
{
.fxnTablePtr = &ADCMSP432_fxnTable,
.object = &adcMSP432Objects[5],
.hwAttrs = &adcMSP432HWAttrs[5]
},
{
.fxnTablePtr = &ADCMSP432_fxnTable,
.object = &adcMSP432Objects[6],
.hwAttrs = &adcMSP432HWAttrs[6]
},
{
.fxnTablePtr = &ADCMSP432_fxnTable,
.object = &adcMSP432Objects[7],
.hwAttrs = &adcMSP432HWAttrs[7]
},
{
.fxnTablePtr = &ADCMSP432_fxnTable,
.object = &adcMSP432Objects[8],
.hwAttrs = &adcMSP432HWAttrs[8]
},
{NULL, NULL, NULL}
};
Still in the MSP_EXP432P401R.c, I found I had to add an GPIOMSP432 entry for the ADC channel I wanted to use; in this case ADC8 (A8).
GPIO_PinConfig gpioPinConfigs[] = {
/* Input pins */
/* MSP_EXP432P401R_S1 */
GPIOMSP432_P1_1 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
/* MSP_EXP432P401R_S2 */
GPIOMSP432_P1_4 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
/* Output pins */
/* MSP_EXP432P401R_LED1 */
GPIOMSP432_P1_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* MSP_EXP432P401R_LED_RED */
GPIOMSP432_P2_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/*
* MSP_EXP432P401R_LED_GREEN & MSP_EXP432P401R_LED_BLUE are used for
* PWM examples. Uncomment the following lines if you would like to control
* the LEDs with the GPIO driver.
*/
/* MSP_EXP432P401R_LED_GREEN */
//GPIOMSP432_P2_1 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* MSP_EXP432P401R_LED_BLUE */
//GPIOMSP432_P2_2 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW
GPIOMSP432_P4_5 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING
};
Now, this these defined, the values that will be used in the code can be added to the Board.h file.
#define Board_ADC0 MSP_EXP432P401R_ADC0 #define Board_ADC1 MSP_EXP432P401R_ADC1 #define Board_ADC2 MSP_EXP432P401R_ADC2 #define Board_ADC3 MSP_EXP432P401R_ADC3 #define Board_ADC4 MSP_EXP432P401R_ADC4 #define Board_ADC5 MSP_EXP432P401R_ADC5 #define Board_ADC6 MSP_EXP432P401R_ADC6 #define Board_ADC7 MSP_EXP432P401R_ADC7 #define Board_ADC8 MSP_EXP432P401R_ADC8
Now, in the adcsinglechannel.c file, the new ADC values can be used to send or received data from. In this instance, I am using ADC 8 (A*) from the MSP432 Header to input the data from my microphone circuit, so I changed task1 to read from A8 vs A1. This is just raw data and is not formatted as will be case in the final product.
/*
* ======== taskFxn1 ========
* Open a ADC handle and get a array of sampling results after
* calling several conversions.
*/
Void taskFxn1(UArg arg0, UArg arg1)
{
uint16_t i;
ADC_Handle adc;
ADC_Params params;
int_fast16_t res;
ADC_Params_init(¶ms);
adc = ADC_open(Board_ADC8, ¶ms);
if (adc == NULL) {
System_abort("Error initializing ADC channel 8\n");
}
else {
System_printf("ADC channel 8 initialized\n");
}
for (i = 0; i < ADC_SAMPLE_COUNT; i++) {
res = ADC_convert(adc, &adcValue1[i]);
if (res == ADC_STATUS_SUCCESS) {
System_printf("ADC channel 8 convert result (%d): 0x%x\n", i,
adcValue1[i]);
}
else {
System_printf("ADC channel 8 convert failed (%d)\n", i);
}
System_flush();
}
ADC_close(adc);
}
When this is run, the output will look something like the following:
[CORTEX_M4_0] Starting the ADC Single Channel example System provider is set to SysMin. Halt the target to view any SysMin contents in ROV. ADC channel 0 initialized ADC channel 0 convert result: 0x219 ADC channel 8 initialized ADC channel 8 convert result (0): 0x2431 ADC channel 8 convert result (1): 0x242f ADC channel 8 convert result (2): 0x241b ADC channel 8 convert result (3): 0x2423 ADC channel 8 convert result (4): 0x245e ADC channel 8 convert result (5): 0x2432 ADC channel 8 convert result (6): 0x242c ADC channel 8 convert result (7): 0x240b ADC channel 8 convert result (8): 0x241e ADC channel 8 convert result (9): 0x2441
Video showing the use of ADC8 (A8) on the MSP432 with TI-RTOS for my Hearing Guard System:
