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!