A related question is a question created from another question. When the related question is created, it will be automatically linked to the original question.
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.
MSP430FR5994: LaunchPad code behavior I need help understanding.
I am coming up the learning curve on the MSP430FR5994 and ran into two problems neither of which I can explain and need some help to understand. The code is rather simple, it simply uses the BCL UART to respond with " hello world " whenever a character "a" is typed on the CCS's terminal (any character other than "a" is ignored). This code works (with many thanks to Bruce and Matt). However, I am puzzled that the code stops functioning when I comment out a P5IFG = 0x00; statement inside the initGPIO function. I highlighted the problem statement in yellow. As is, the code works. Comment out the statement and it stops. Moving the statement outside of the function and into the main function doesn't change the behavior. The statement needs to be in the initGPIO function for some reason. Any ideas as to what's happening?
1) The second problem is that Port5 interrupts from the two button on the Launchpad (P5.6 and P5.5) aren't being recognized when pressed. Did I lock up the port somehow? . Any help here would also be greatly appreciated.
uint8_t RXData = 0; // UART Receive byte int mode = 0; // mode selection variable int pingHost = 0; // ping request from PC GUI int noSDCard = 0; Calendar calendar; // Calendar used for RTC
void initClocks (void){
// Set DCO frequency to 8 MHz CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_6); //Set external clock frequency to 32.768 KHz CS_setExternalClockSource(32768, 0); //Set ACLK=LFXT CS_initClockSignal(CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); // Set SMCLK = DCO with frequency divider of 1 CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // Set MCLK = DCO with frequency divider of 1 CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); //Start XT1 with no time out CS_turnOnLFXT(CS_LFXT_DRIVE_3);
// Set PJ.4 and PJ.5 as Primary Module Function Input, LFXT. GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_PJ,GPIO_PIN4 + GPIO_PIN5,GPIO_PRIMARY_MODULE_FUNCTION);
// Setup P1.0 and P1.1 LED GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0); GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN1); //turn off leds GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN1);
// Setup P5.5 and P5.6 as input buttons GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P5,GPIO_PIN5); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P5,GPIO_PIN6); GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5,GPIO_PRIMARY_MODULE_FUNCTION); GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN6,GPIO_PRIMARY_MODULE_FUNCTION); GPIO_selectInterruptEdge(GPIO_PORT_P5,GPIO_PIN5,GPIO_HIGH_TO_LOW_TRANSITION); GPIO_selectInterruptEdge(GPIO_PORT_P5,GPIO_PIN6,GPIO_HIGH_TO_LOW_TRANSITION); //P5IE = 0x60; //enable interrupts on P5.5 and P5.6 GPIO_enableInterrupt(GPIO_PORT_P5,GPIO_PIN5); GPIO_enableInterrupt(GPIO_PORT_P5,GPIO_PIN6);
//enable interrupts // commenting out the function below causes the EUSCI_A_UART to stop working.EUSCI_A_UART uses P2.0 & P2.1 P5IFG = 0x00; //clear all Port 5 interrupt flags
// Disable the GPIO power-on default high-impedance mode // to activate previously configured port settings //PMM_unlockLPM5();
}
void Init_RTC() { //Setup Current Time for Calendar calendar.Seconds = 0x55; calendar.Minutes = 0x30; calendar.Hours = 0x04; calendar.DayOfWeek = 0x01; calendar.DayOfMonth = 0x30; calendar.Month = 0x04; calendar.Year = 0x2014;
// Initialize RTC with the specified Calendar above RTC_C_initCalendar(RTC_C_BASE,&calendar,RTC_C_FORMAT_BCD); RTC_C_setCalendarEvent(RTC_C_BASE,RTC_C_CALENDAREVENT_MINUTECHANGE); RTC_C_clearInterrupt(RTC_C_BASE,RTC_C_TIME_EVENT_INTERRUPT); RTC_C_enableInterrupt(RTC_C_BASE,RTC_C_TIME_EVENT_INTERRUPT);
> GPIO_selectInterruptEdge(GPIO_PORT_P5,GPIO_PIN5,GPIO_HIGH_TO_LOW_TRANSITION);
> GPIO_enableInterrupt(GPIO_PORT_P5,GPIO_PIN5);
Setting a P5IES bit can cause that P5IFG bit to be set. Also setting P5REN. [Ref UG (SLAU367O) Sec 12.2.6.2, 12.2.6] So as soon as you enable interrupts, you'll go to the ISR (with both IFGs set). You should call GPIO_clearInterrupt as the last thing before enabling, or just set P5IFG=0 as you're doing.
> switch (P5IFG)
This switch doesn't check for both bits being set (your case above); in that case it doesn't clear either IFG, and recurses forever through the ISR. For what you want to do, you should probably just check them individually.
----------------------------------------
> GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5,GPIO_PRIMARY_MODULE_FUNCTION);
> GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN6,GPIO_PRIMARY_MODULE_FUNCTION);
These set P5.5/.6 to alternate function (UCA2), just after setting them to GPIO (buttons). I think you don't want these lines.
----------------------------------------
Unsolicited:
> case 0x20: //P5.5 interrupt
> P5IFG &= ~BIT5; //clear IFG
> P1OUT |= BIT1; //Grn LED port 1.1
> _delay_cycles(80000); //wait
> P1OUT &= ~BIT1; //Turn Off LED
You're not explicitly de-bouncing, but you get that effect from the delay_cycles() call. What's missing: The IFG will be set (over and over) as the button bounces. You should clear the IFG after you're pretty sure the bouncing has stopped -- here, at the end of the "case", not the beginning. The symptom here will be that the button appears to be pushed twice.
----------------------------------------
Unsolicited:
Please don't post code with large blocks commented out. It makes it very difficult to scan, particularly without code tags.
I had left an enable interrupt in the initTimers() which caused the interrupts to be enabled prematurely. Thank you!!
You were right on the second issue. The
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,
GPIO_PIN6,GPIO_PRIMARY_MODULE_FUNCTION);
was indeed the cause of the problem. I expanded macro and it selected the wrong function module. I eliminated those two statements and cleaned up the handler per your suggestions. The code is much cleaner and is fully functional. Thank you very much!!