Part Number: MSP432P401R
Tool/software: Code Composer Studio
Hi there,
I am creating a system that can control each LED on MSP432P401R and record how long each LED is on. So far I have found a way to control each LED with BTN1, but I still have to apply systick to record the time duration. I think it has something to do with SysTick_getValue() but when I tried to apply it into my system it just didn't work.
I have copied my code down below, please help me out! Thanks!
Keith.
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
int count = 0;
void delay_ms(uint16_t ms);
int main(void)
{
/* Stop Watchdog */
MAP_WDT_A_holdTimer();
/* Configuring P1.0 as output and P1.1 (switch) as input */
MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
/* Configuring P1.1 as an input and enabling interrupts */
MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
MAP_GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN1,
GPIO_HIGH_TO_LOW_TRANSITION);
MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1);
SysTick_enableModule();
SysTick_setPeriod(30000); /* Frequency of MCLK is 3MHz, therefore the counter rolls over every 0.01sec */
MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);
MAP_Interrupt_enableInterrupt(INT_PORT1);
/* Enabling MASTER interrupts */
MAP_Interrupt_enableMaster();
while (1)
{
}
}
void PORT1_IRQHandler(void)
{
uint32_t status;
uint32_t start, end, a, b, c, d; /* a, b, c, d represent the time duration for each LED */
start=0; /* the start value has to be initialized otherwise there will be an error for the first channel 1 calculation */
status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P1);
MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, status);
if (status & GPIO_PIN1)
{
count++;
if (count == 1)
{
end = SysTick_getValue();
a = end - start;
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2,
GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
delay_ms(500);
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
start = SysTick_getValue();
}
if (count == 2)
{
end = SysTick_getValue();
a = end - start;
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2,
GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
delay_ms(500);
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0);
start = SysTick_getValue();
}
if (count == 3)
{
end = SysTick_getValue();
a = end - start;
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2,
GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
delay_ms(500);
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1);
start = SysTick_getValue();
}
if (count == 4)
{
end = SysTick_getValue();
a = end - start;
count = 0;
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2,
GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
delay_ms(500);
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN2);
start = SysTick_getValue();
}
}
}
void delay_ms(uint16_t ms)
{
uint16_t delay;
volatile uint32_t i;
for (delay = ms; delay > 0; delay--)
{
for (i = 300; i > 0; i--)
{
}
}
}