Part Number: MSP432P401M
Hello everyone,
I want to access ADC14MEM0 register and stored the value in variable. I tried this " curADCResult = ADC14MEM0" . But, it is showing that ADC14MEM0 is undefined.
How can I access ADC14MEM0 converted value??
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: MSP432P401M
Hello everyone,
I want to access ADC14MEM0 register and stored the value in variable. I tried this " curADCResult = ADC14MEM0" . But, it is showing that ADC14MEM0 is undefined.
How can I access ADC14MEM0 converted value??
Hi Sayali!
ADC14MEM0 definitely is a valid register name. If it is unknown, you may not have included the proper header file or your project was initially started for a different processor, including the wrong header file by itself. But I would expect more / other errors in this case. Do you use CCS? If not too long, would you upload your code or project?
Dennis
Hi Dennis,
I am using CCS Version: 7.0.0.00042. I have taken example code" adc14_single_conversion_repeat" from simplelink_msp432_sdk_1_20_00_45. I forgot to add driver library. when I added driver library ,I can easily access ADC14MEM0 value.
after that I just tried this code:-
void ADC14_IRQHandler(void)
{
curADCResult = MAP_ADC14_getResult(ADC_MEM0);
normalizedADCRes = ((float)curADCResult * 3.3) / 16383;
}
and defined variable:
static volatile uint16_t curADCResult;
static volatile float normalizedADCRes;
When I debug the code ADC14MEM0 register value is change continuously.But there is no chnages in curADCresult and normalized ADCRes.
Hello Sayali,
What input you have connected to P5.5... I have checked this code on Launchpad connecting 3V, GND etc signals with P5.5, it worked fine.
If you are running it in Free mode without connecting anything on P5.5, it shows you result as 0.
int main(void)
{
/* Halting the Watchdog */
MAP_WDT_A_holdTimer();
/* Initializing Variables */
curADCResult = 0;
/* Setting Flash wait state */
MAP_FlashCtl_setWaitState(FLASH_BANK0, 2);
MAP_FlashCtl_setWaitState(FLASH_BANK1, 2);
/* Setting DCO to 48MHz */
MAP_PCM_setPowerState(PCM_AM_LDO_VCORE1);
MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
/* Enabling the FPU for floating point operation */
MAP_FPU_enableModule();
MAP_FPU_enableLazyStacking();
/* Initializing ADC (MCLK/1/4) */
MAP_ADC14_enableModule();
MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_4,
0);
/* Configuring GPIOs (5.5 A0) */
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5,
GPIO_TERTIARY_MODULE_FUNCTION);
/* Configuring ADC Memory */
MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true);
MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A0, false);
/* Configuring Sample Timer */
MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION);
/* Enabling/Toggling Conversion */
MAP_ADC14_enableConversion();
MAP_ADC14_toggleConversionTrigger();
/* Enabling interrupts */
MAP_ADC14_enableInterrupt(ADC_INT0);
MAP_Interrupt_enableInterrupt(INT_ADC14);
MAP_Interrupt_enableMaster();
while (1)
{
MAP_PCM_gotoLPM0();
}
}
/* ADC Interrupt Handler. This handler is called whenever there is a conversion
* that is finished for ADC_MEM0.
*/
void ADC14_IRQHandler(void)
{
uint64_t status = MAP_ADC14_getEnabledInterruptStatus();
MAP_ADC14_clearInterruptFlag(status);
if (ADC_INT0 & status)
{
curADCResult = MAP_ADC14_getResult(ADC_MEM0);
ADC_RES[adc_cnt]= curADCResult;
adc_cnt++;
if (adc_cnt>15)
adc_cnt=0;
normalizedADCRes = (curADCResult * 3.3) / 16384;
MAP_ADC14_toggleConversionTrigger();
}
}
Regards,
Vikas Chola
Hi Vikas,
The output of sensor is connected to P8.4 i.e A19 pin of ADC.The range of ADC input is 0 to 3.3V. I run your code but still curADCresult value does not change.If conversion result is read in main code means I add this in main code without any interrupt:-
while (1)
{
ADCvar = ADC14->MEM[0]; // Read conversion result
__no_operation(); // SET BREAKPOINT HERE
}
The result in ADCvar variable changes continuously.
I am attaching the main.c file here:-
// MSP432P401M
/************************************************************************************************/
// SAYALI PATHAK
// 3 Feb 2017 (Created)
// 8 Feb 2017 (Changes)
#include "MSP432P401M.h"
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Standard Includes */
#include <stdint.h>
#include <string.h>
extern void init_uart(void);
extern void dev_init(void);
//Defining variables for inclinometer ADC conversions
//SAYALI PATHAK 8 Feb 2017
// uint16_t curADCResult;
// float normalizedADCRes;
static volatile uint16_t curADCResult;
uint32_t currentPowerState;
//Defining variables for inclinometer voltage to angel conversions
//SAYALI PATHAK 21 FEB 2017
unsigned char vsenseout;
unsigned char lAngle;
unsigned char readdata;
//*************************************************************************************
//Main code
int main(void)
{
//Stop watchdog timer
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD;
/* Initializing Variables */
curADCResult = 0;
// Configure GPIO
// P5->SEL1 |= BIT4 | BIT6 | BIT7; // Enable A/D channel A0
// P5->SEL0 |= BIT4 | BIT6 | BIT7; // and VeREF+ and VeREF-
P5->SEL1 |= BIT6 | BIT7; // VeREF+ and VeREF-
P5->SEL0 |= BIT6 | BIT7; // set as a secondary function (ADC Ref pin)
P8->SEL1 |= BIT6; //Enable A/D channel A19
P8->SEL0 |= BIT6; //set as a secondary function (ADC Ref pin)
//unused pin setup
P10->DIR |= (BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5); // set P10 as output direction
P10->REN |= BIT0 + BIT1 + BIT2 + BIT3; //enable pull-up/pull-down resistors on P10
P10->OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3); //Set P10 resistors to pull down
P1->DIR |= (BIT1 + BIT4 + BIT5 + BIT6 + BIT7);
P1->REN |= BIT1 + BIT4 + BIT5 + BIT6 + BIT7;
P1->OUT &= ~(BIT1 + BIT4 + BIT5 + BIT6 + BIT7);
P2->DIR |= (BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7);
P2->REN |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7;
P2->OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7);
P3->DIR |= (BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7);
P3->REN |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7;
P3->OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7);
P4->DIR |= (BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7);
P4->REN |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7;
P4->OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7);
P5->DIR |= (BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5);
P5->REN |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 ;
P5->OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5);
P6->DIR |= (BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7);
P6->REN |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7;
P6->OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7);
P7->DIR |= (BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7);
P7->REN |= BIT0 + BIT1 + BIT2 + BIT3 +BIT4 + BIT5 + BIT6 + BIT7;
P7->OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7);
P8->DIR |= BIT0 + BIT1 + BIT2 + BIT3 +BIT4 + BIT5 + BIT7;
P8->REN |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT7;
P8->OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT7);
P9->DIR |= (BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5);
P9->REN |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 ;
P9->OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5);
dev_init();
// Configure ADC14
// Turn on ADC14, set sampling time
ADC14->CTL0 = ADC14_CTL0_ON | ADC14_CTL0_SHP| ADC14_CTL0_SHT0_2 |ADC14_CTL0_SSEL_2 | ADC14_CTL0_PDIV_2 | ADC14_CTL0_CONSEQ_2 | ADC14_CTL0_MSC;
// Use sampling timer, 14-bit conversion results
ADC14->CTL1 = ADC14_CTL1_RES_3;
// Vr+ = VeREF+ (ext) and Vr-=VeREF-, A0
// ADC14->MCTL[0] = ADC14_MCTLN_VRSEL_14 | ADC14_MCTLN_INCH0 | ADC14_MCTLN_EOS ;
// Vr+ = VeREF+ (ext) and Vr-=VeREF-, A19
ADC14->MCTL[0] = ADC14_MCTLN_VRSEL_14 | ADC14_MCTLN_INCH0 |ADC14_MCTLN_INCH1 | ADC14_MCTLN_INCH4| ADC14_MCTLN_EOS ;
// Interrupt enable
ADC14->IER0 = ADC14_IER0_IE19;
// Enable conversions
ADC14->CTL0 |= ADC14_CTL0_ENC | ADC14_CTL0_SC ;
init_uart();
}
void ADC14_IRQHandler(void)
{
curADCResult = MAP_ADC14_getResult(ADC_MEM0);
// adcResult =ADC14->MEM[0];
// normalizedADCRes = ((float)curADCResult * 3.3) / 16383;
}
/*
* dev_init.c
*
* Created on: Mar 7, 2017
*
*/
#include "MSP432P401M.h"
uint32_t currentPowerState;
void init_32k(void)
{
// Configure GPIO
PJ->SEL0 |= BIT0 | BIT1; // set LFXT pin as second function
CS->KEY = CS_KEY_VAL ; // Unlock CS module for register access
CS->CTL2 |= CS_CTL2_LFXT_EN; // LFXT on
// Loop until XT1, XT2 & DCO fault flag is cleared
do
{
// Clear XT2,XT1,DCO fault flags
CS->CLRIFG |= CS_CLRIFG_CLR_DCOR_OPNIFG | CS_CLRIFG_CLR_HFXTIFG |
CS_CLRIFG_CLR_LFXTIFG | CS_CLRIFG_CLR_FCNTLFIFG;
SYSCTL->NMI_CTLSTAT &= ~ SYSCTL_NMI_CTLSTAT_CS_SRC;
} while ((SYSCTL->NMI_CTLSTAT | SYSCTL_NMI_CTLSTAT_CS_FLG)
&& (CS->IFG & CS_IFG_LFXTIFG)); // Test oscillator fault flag
// Select ACLK as LFXTCLK
CS->CTL1 = CS->CTL1 & ~(CS_CTL1_SELA_MASK | CS_CTL1_DIVA_MASK) | CS_CTL1_SELA_0;
// Enable LFXT fault interrupt
CS->IE |= CS_IE_LFXTIE;
CS->KEY = 0; // Lock CS module from unintended accesses
// Enable global interrupt
__enable_irq();
// Enable CS interrupt in NVIC module
NVIC->ISER[0] = 1 << ((CS_IRQn) & 31);
}
void error(void)
{
// while (1);
}
void init_48M(void)
{
/* Get current power state, if it's not AM0_LDO, error out */
currentPowerState = PCM->CTL0 & PCM_CTL0_CPM_MASK;
if (currentPowerState != PCM_CTL0_CPM_0)
error();
while ((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_1;
while ((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
if (PCM->IFG & PCM_IFG_AM_INVALID_TR_IFG)
error(); // Error if transition was not successful
if ((PCM->CTL0 & PCM_CTL0_CPM_MASK) != PCM_CTL0_CPM_1)
error(); // Error if device is not in AM1_LDO mode
/* Step 2: Configure Flash wait-state to 1 for both banks 0 & 1 */
FLCTL->BANK0_RDCTL = (FLCTL->BANK0_RDCTL & ~(FLCTL_BANK0_RDCTL_WAIT_MASK)) |
FLCTL_BANK0_RDCTL_WAIT_1;
FLCTL->BANK1_RDCTL = (FLCTL->BANK0_RDCTL & ~(FLCTL_BANK1_RDCTL_WAIT_MASK)) |
FLCTL_BANK1_RDCTL_WAIT_1 ;
/* Step 3: Configure HFXT to use 48MHz crystal, source to MCLK & SMCLK*/
PJ->SEL0 |= BIT2 | BIT3; // Configure PJ.2/3 for HFXT function
PJ->SEL1 &= ~(BIT2 | BIT3);
CS->KEY = CS_KEY_VAL ; // Unlock CS module for register access
CS->CTL2 |= CS_CTL2_HFXT_EN | CS_CTL2_HFXTFREQ_6 | CS_CTL2_HFXTDRIVE;
while(CS->IFG & CS_IFG_HFXTIFG)
CS->CLRIFG |= CS_CLRIFG_CLR_HFXTIFG;
/* Select MCLK & SMCLK = HFXT, no divider */
CS->CTL1 = CS->CTL1 & ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK | CS_CTL1_SELS_MASK | CS_CTL1_DIVHS_MASK) |
CS_CTL1_SELM__HFXTCLK | CS_CTL1_SELS__HFXTCLK| CS_CTL1_DIVS_2;
CS->KEY = 0; // Lock CS module from unintended accesses
}
void dev_init(void)
{
init_32k();
init_48M();
}
void CS_IRQHandler(void)
{
CS->KEY = CS_KEY_VAL ; // Unlock CS module for register access
// Loop until XT1, XT2 & DCO fault flag is cleared
do
{
// Clear XT2,XT1,DCO fault flags
CS->CLRIFG |= CS_CLRIFG_CLR_DCOR_OPNIFG | CS_CLRIFG_CLR_HFXTIFG |
CS_CLRIFG_CLR_LFXTIFG | CS_CLRIFG_CLR_FCNTLFIFG;
SYSCTL->NMI_CTLSTAT &= ~ SYSCTL_NMI_CTLSTAT_CS_SRC;
} while ((SYSCTL->NMI_CTLSTAT | SYSCTL_NMI_CTLSTAT_CS_FLG)
&& (CS->IFG & CS_IFG_LFXTIFG)); // Test oscillator fault flag
CS->KEY = 0; // Lock CS module from unintended accesses
}
**Attention** This is a public forum