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.

MSP432P401R: Priority interrupts MSP432P401R

Part Number: MSP432P401R


hello everybody. I'm in trouble with set priority for GPIO_PORT1 higher than ADC14. I want to read ADC at P5.5. and when an interrupt occurs at P1.0 (high to low ) I will send 0xffff though USCIA0 . 
I tried but the results were not as expected Here is my code : 

// My Code

#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
#include <stdbool.h>
/* Statics */
static uint16_t curADCResult1[10000];
static volatile uint16_t i = 0;
static volatile uint16_t curADCResult;
static volatile float normalizedADCRes;
uint_fast8_t voltage = 0;
const eUSCI_UART_Config uartConfig =
{
EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
78, // BRDIV = 78
2, // UCxBRF = 2
0, // UCxBRS = 0
EUSCI_A_UART_NO_PARITY, // No Parity
EUSCI_A_UART_LSB_FIRST, // MSB First
EUSCI_A_UART_ONE_STOP_BIT, // One stop bit
EUSCI_A_UART_MODE, // UART mode
EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION // Oversampling
};
void ADC14Config(void);
int main(void)
{
/* Halting the Watchdog */
MAP_WDT_A_holdTimer();
/* P1.2 & P1.3 for UART. P1.0 for output */
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
MAP_GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0);
/* P1.0 for interrupt */
MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1);
MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);
MAP_Interrupt_setPriority(INT_PORT1,0x20);
MAP_Interrupt_enableInterrupt(INT_PORT1);
/* Initializing Variables */
curADCResult = 0;

/* Setting Flash wait state */
MAP_FlashCtl_setWaitState(FLASH_BANK0, 2);
MAP_FlashCtl_setWaitState(FLASH_BANK1, 2);

/* Setting DCO to 12MHz */
MAP_PCM_setPowerState(PCM_AM_LDO_VCORE1);
MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);

/* Enabling the FPU for floating point operation */
MAP_FPU_enableModule();
MAP_FPU_enableLazyStacking();
/* ADC14 configure */
ADC14Config();
/* USCIA0 configure */
UART_initModule(EUSCI_A0_BASE, &uartConfig);
UART_enableModule(EUSCI_A0_BASE);
/* Enabling interrupt for ADC14*/
MAP_ADC14_enableInterrupt(ADC_INT0);
MAP_Interrupt_enableInterrupt(INT_ADC14);
MAP_Interrupt_setPriority(INT_ADC14,0x40);
MAP_Interrupt_enableMaster();

while (1)
{
MAP_PCM_gotoLPM0();
}

}

//![Single Sample Result]
/* ADC Interrupt Handler. This handler is called whenever there is a conversion
* that is finished for ADC_MEM0.
*/

void ADC14Config(void)
{
MAP_ADC14_enableModule();
/* Initializing ADC (MCLK/1/1) */
MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,
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_AUTOMATIC_ITERATION);

/* Enabling/Toggling Conversion */
MAP_ADC14_enableConversion();
MAP_ADC14_toggleConversionTrigger();
}
void ADC14_IRQHandler(void)
{
uint64_t status = MAP_ADC14_getEnabledInterruptStatus();
MAP_ADC14_clearInterruptFlag(status);

if (ADC_INT0 & status)
{ ADC14_getMultiSequenceResult(curADCResult1);
curADCResult = MAP_ADC14_getResult(ADC_MEM0);
normalizedADCRes = (curADCResult * 3.3) / 16384;
UART_transmitData(EUSCI_A0_BASE,curADCResult>>8);
UART_transmitData(EUSCI_A0_BASE,curADCResult & 0xff);

if(normalizedADCRes > 1.5)
GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
else
GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);

}
}

void PORT1_IRQHandler(void)
{
uint32_t status;
status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P1);
MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, status);

UART_transmitData(EUSCI_A0_BASE,0xff);
UART_transmitData(EUSCI_A0_BASE,0xff);
GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);

}

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

Hope you repply to me .

thanks in advance

best regards!

 

  • Hello Than,

    The function initialization of the interrupt priority is correct. Noiw the priority means that when both ADC and GPIO interrupt occur at the same time which one is processed first. Please note that the USCI is working at a very slow rate of 115200 bps. Hence the data transmission delay itself would cause a skew since the data will take longer to transmit during which multiple interrupts may happen.
  • Hello Amit Ashara, thanks for your repply. But my problem is when I press P1.1 ( high to low transition) GPIO interrupt configured doesnt occur. whether when MCU is processing PORT1_IRQHandler , an ADC14Interrupt occurs would cause the data have not transmitted ??
  • Hello Than,

    Well that was not clear in your first post. Now, if you put a breakpoint on the interrupt handler and you press the P1.1 GPIO Switch, does the code execution halt at the breakpoint?

    If no, then remove the priority function and then try.
    If yes, then the interrupt handler is working as expected. What you need to make sure is whether the UART pins are toggling as expected using a scope or a logic analyzer
  • I'll try it, thank you for your help. It's very helpful for any beginer like me.
    Regards.

**Attention** This is a public forum