Part Number: MSP432P401R
Tool/software: Code Composer Studio
I want to read multiple ADC values simultaneously using the DriverLib provided in MSP432 SDK.
I edited the adc14_multiple_channel_no_repeat.c for repeating the same operation repeatedly.
All I changed in the example code was the
MAP_ADC14_configureMultiSequenceMode(ADC_MEM0, ADC_MEM7, false);
to
MAP_ADC14_configureMultiSequenceMode(ADC_MEM0, ADC_MEM7, true);
I think that is all the change to be made to the example code.
I have added the full code below.
/* --COPYRIGHT--,BSD * Copyright (c) 2017, Texas Instruments Incorporated * All rights reserved. * * 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. * --/COPYRIGHT--*/ /******************************************************************************* * MSP432 ADC14 - Multiple Channel Sample without Repeat * * Description: In this code example, the feature of being able to scan multiple * ADC channels is demonstrated by the user a the DriverLib APIs. Conversion * memory registers ADC_MEM0 - ADC_MEM7 are configured to read conversion * results from A0-A7 respectively. Conversion is enabled and then sampling is * toggled using a software toggle. Repeat mode is not enabled and sampling only * occurs once (and it is expected that the user pauses the debugger to observe * the results). Once the final sample has been taken, the interrupt for * ADC_MEM7 is triggered and the result is stored in the resultsBuffer buffer. * * MSP432P401 * ------------------ * /|\| | * | | | * --|RST P5.5 |<--- A0 (Analog Input) * | P5.4 |<--- A1 (Analog Input) * | P5.3 |<--- A2 (Analog Input) * | P5.2 |<--- A3 (Analog Input) * | P5.1 |<--- A4 (Analog Input) * | P5.0 |<--- A5 (Analog Input) * | P4.7 |<--- A6 (Analog Input) * | P4.6 |<--- A7 (Analog Input) * | | * | | * ******************************************************************************/ /* DriverLib Includes */ #include <ti/devices/msp432p4xx/driverlib/driverlib.h> /* Standard Includes */ #include <stdint.h> #include <string.h> static uint16_t resultsBuffer[8]; int main(void) { /* Halting WDT */ MAP_WDT_A_holdTimer(); MAP_Interrupt_enableSleepOnIsrExit(); /* Zero-filling buffer */ memset(resultsBuffer, 0x00, 8); //![Simple REF Example] /* Setting reference voltage to 2.5 and enabling reference */ MAP_REF_A_setReferenceVoltage(REF_A_VREF2_5V); MAP_REF_A_enableReferenceVoltage(); //![Simple REF Example] /* Initializing ADC (MCLK/1/1) */ MAP_ADC14_enableModule(); MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1, 0); /* Configuring GPIOs for Analog In */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5 | GPIO_PIN4 | GPIO_PIN3 | GPIO_PIN2 | GPIO_PIN1 | GPIO_PIN0, GPIO_TERTIARY_MODULE_FUNCTION); MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P4, GPIO_PIN7 | GPIO_PIN6, GPIO_TERTIARY_MODULE_FUNCTION); /* Configuring ADC Memory (ADC_MEM0 - ADC_MEM7 (A0 - A7) with no repeat) * with internal 2.5v reference */ MAP_ADC14_configureMultiSequenceMode(ADC_MEM0, ADC_MEM7, true); MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_INTBUF_VREFNEG_VSS, ADC_INPUT_A0, false); MAP_ADC14_configureConversionMemory(ADC_MEM1, ADC_VREFPOS_INTBUF_VREFNEG_VSS, ADC_INPUT_A1, false); MAP_ADC14_configureConversionMemory(ADC_MEM2, ADC_VREFPOS_INTBUF_VREFNEG_VSS, ADC_INPUT_A2, false); MAP_ADC14_configureConversionMemory(ADC_MEM3, ADC_VREFPOS_INTBUF_VREFNEG_VSS, ADC_INPUT_A3, false); MAP_ADC14_configureConversionMemory(ADC_MEM4, ADC_VREFPOS_INTBUF_VREFNEG_VSS, ADC_INPUT_A4, false); MAP_ADC14_configureConversionMemory(ADC_MEM5, ADC_VREFPOS_INTBUF_VREFNEG_VSS, ADC_INPUT_A5, false); MAP_ADC14_configureConversionMemory(ADC_MEM6, ADC_VREFPOS_INTBUF_VREFNEG_VSS, ADC_INPUT_A6, false); MAP_ADC14_configureConversionMemory(ADC_MEM7, ADC_VREFPOS_INTBUF_VREFNEG_VSS, ADC_INPUT_A7, false); /* Enabling the interrupt when a conversion on channel 7 (end of sequence) * is complete and enabling conversions */ MAP_ADC14_enableInterrupt(ADC_INT7); /* Enabling Interrupts */ MAP_Interrupt_enableInterrupt(INT_ADC14); MAP_Interrupt_enableMaster(); /* Setting up the sample timer to automatically step through the sequence * convert. */ MAP_ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION); /* Triggering the start of the sample */ MAP_ADC14_enableConversion(); MAP_ADC14_toggleConversionTrigger(); /* Going to sleep */ while (1) { MAP_PCM_gotoLPM0(); } } /* This interrupt is fired whenever a conversion is completed and placed in * ADC_MEM7. This signals the end of conversion and the results array is * grabbed and placed in resultsBuffer */ void ADC14_IRQHandler(void) { uint64_t status; status = MAP_ADC14_getEnabledInterruptStatus(); MAP_ADC14_clearInterruptFlag(status); if(status & ADC_INT7) { MAP_ADC14_getMultiSequenceResult(resultsBuffer); } }
This seems correct but the ADC is not continuously reading all the pins and some pins such as P5.4 does not even show sampling even when a given input.
And the results are shown only in the first two indices of the resultsBuffer[ ] and not on anything else.
Am I doing something wrong? I am new to MSP432.
Thank you.
Viswanath.