Hey,
i want to read out some Voltages form the ADC, but I have a problem with the resultBuffer. When I use MAP_ADC14_getMultiSequenceResult(resultsBuffer) I geting only values when I put the MEMx from for the ADC on MEM0, MEM4, MEM8,... .
If I use e.g. MEM1 for A1 I don't get any results.
/*
* MSP432P401
* ------------------
* /|\| |
* | | |
* --|RST P5.4 |<--- A1 (Analog Input)
* | P5.2 |<--- A3 (Analog Input)
* | P5.0 |<--- A5 (Analog Input)
* | P4.5 |<--- A8 (Analog Input)
* | P4.3 |<--- A10 (Analog Input)
* | P4.0 |<--- A13 (Analog Input)
* | P9.1 |<--- A16 (Analog Input)
* | P8.7 |<--- A18 (Analog Input)
* | P8.6 |<--- A19 (Analog Input)
* | P8.4 |<--- A21 (Analog Input)
* | |
* | |
*
* Author: Timothy Logan
******************************************************************************/
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Standard Includes */
#include <stdint.h>
#include <string.h>
/* Timer_A Continuous Mode Configuration Parameter */
const Timer_A_UpModeConfig upModeConfig =
{
TIMER_A_CLOCKSOURCE_ACLK, // ACLK Clock Source
TIMER_A_CLOCKSOURCE_DIVIDER_1, // ACLK/1 = 32Khz
1000, // 2000= 1Hz 1000=2Hz
TIMER_A_TAIE_INTERRUPT_DISABLE, // Disable Timer ISR
TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE, // Disable CCR0
TIMER_A_DO_CLEAR // Clear Counter
};
/* Timer_A Compare Configuration Parameter */
const Timer_A_CompareModeConfig compareConfig =
{
TIMER_A_CAPTURECOMPARE_REGISTER_1, // Use CCR1
TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE, // Disable CCR interrupt
TIMER_A_OUTPUTMODE_SET_RESET, // Toggle output but
1000 // 1000 Period
};
static uint16_t resultsBuffer[30];
static float results[30];
int main(void)
{
/* Halting WDT */
MAP_WDT_A_holdTimer();
MAP_Interrupt_enableSleepOnIsrExit();
/* Zero-filling buffer */
memset(resultsBuffer, 0x00, 30);
memset(results, 0x00, 30);
/* Setting up clocks
* MCLK = MCLK = 3MHz
* ACLK = REFO = 32Khz */
MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
/* Setting reference voltage to 2.5 and enabling reference */
MAP_REF_A_setReferenceVoltage(REF_A_VREF2_5V);
MAP_REF_A_enableReferenceVoltage();
/* 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_P8,
GPIO_PIN7 | GPIO_PIN6 | GPIO_PIN4, GPIO_TERTIARY_MODULE_FUNCTION);
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P9,
GPIO_PIN1, GPIO_TERTIARY_MODULE_FUNCTION);
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P4,
GPIO_PIN5 |GPIO_PIN3| GPIO_PIN0 , GPIO_TERTIARY_MODULE_FUNCTION);
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,
GPIO_PIN4 | GPIO_PIN2 |GPIO_PIN0 , GPIO_TERTIARY_MODULE_FUNCTION);
/* Configuring ADC Memory (ADC_MEM0 - ADC_MEM30 (A1,3,5,8,10,13,16,18,19,21) with repeat)
*/
MAP_ADC14_configureMultiSequenceMode(ADC_MEM0, ADC_MEM30, true);
MAP_ADC14_configureConversionMemory(ADC_MEM0,
ADC_VREFPOS_INTBUF_VREFNEG_VSS,
ADC_INPUT_A1, false);
MAP_ADC14_configureConversionMemory(ADC_MEM4,
ADC_VREFPOS_INTBUF_VREFNEG_VSS,
ADC_INPUT_A3, false);
MAP_ADC14_configureConversionMemory(ADC_MEM8,
ADC_VREFPOS_AVCC_VREFNEG_VSS ,
ADC_INPUT_A5, false);
MAP_ADC14_configureConversionMemory(ADC_MEM12,
ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A8, false);
MAP_ADC14_configureConversionMemory(ADC_MEM16,
ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A10, false);
MAP_ADC14_configureConversionMemory(ADC_MEM20,
ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A13, false);
MAP_ADC14_configureConversionMemory(ADC_MEM24,
ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A16, false);
MAP_ADC14_configureConversionMemory(ADC_MEM28,
ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A18, false);
MAP_ADC14_configureConversionMemory(ADC_MEM29,
ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A19, false);
MAP_ADC14_configureConversionMemory(ADC_MEM30,
ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A21, false);
/* Configuring Timer_A in continuous mode and sourced from ACLK */
MAP_Timer_A_configureUpMode(TIMER_A0_BASE, &upModeConfig);
/* Configuring Timer_A0 in CCR1 to trigger at 16000 (0.5s) */
MAP_Timer_A_initCompare(TIMER_A0_BASE, &compareConfig);
/* Configuring the sample trigger to be sourced from Timer_A0 and setting it
* to automatic iteration after it is triggered*/
MAP_ADC14_setSampleHoldTrigger(ADC_TRIGGER_SOURCE1, false);
/* Enabling the interrupt when a conversion on channel 7 (end of sequence)
* is complete and enabling conversions */
MAP_ADC14_enableInterrupt(ADC_INT30);
MAP_ADC14_enableConversion();
MAP_ADC14_toggleConversionTrigger();
/* Enabling Interrupts */
MAP_Interrupt_enableInterrupt(INT_ADC14);
MAP_Interrupt_enableMaster();
/* Starting the Timer */
MAP_Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_UP_MODE);
/* Setting up the sample timer to automatically step through the sequence
* convert.
*/
MAP_ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION);
/* Going to sleep */
while (1)
{
MAP_PCM_gotoLPM0();
}
}
/* This interrupt is fired whenever a conversion is completed and placed in
* ADC_MEM30. 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_getMultiSequenceResult(resultsBuffer);
if(status & ADC_INT30)
{
for(j=0;j<10;j++)
{
results[j]= ((resultsBuffer[j]*3.3)/16384);
}
}
MAP_ADC14_toggleConversionTrigger();
MAP_ADC14_clearInterruptFlag(status);
}