//this interrupt is triggered once each second and prints result from ADC conversion and clears interrupt flag void timer_A_ISR(){ //Timers_A_ISR runs at 1 Hz //Turn light to signal timer interrupt is working MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0); Timer_A_clearCaptureCompareInterrupt(TIMER_A0_MODULE,TIMER_A_CAPTURECOMPARE_REGISTER_0); printf("%f \n",(ADC_result/1023.0)*3.3*100.0);//(float)ADC_result);// also try 100.0 as a fix!!! (ADC_result/1023.0)*198.0); // 150F/2.5V = 60F per V. Thus, 150+(3.3-2.5)*60 = 198 // This conversion is necessary because 0-2.5 V corresponds to 0-150F // On the microncontroller, 0-3.3 V corresponds to 0-1023 binary // And the result of the ADC is a binary value //Turn off LED's MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0); }
void initI2CModule(void) { unsigned int flags = EUSCI_B_I2C_TRANSMIT_INTERRUPT0 | EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_TRANSMIT_INTERRUPT1 | EUSCI_B_I2C_RECEIVE_INTERRUPT1 | EUSCI_B_I2C_STOP_INTERRUPT | EUSCI_B_I2C_NAK_INTERRUPT; #if 0 /* Select Port B1 for I2C - Set Pin 4, 5 to input Primary Module Function, * (UCB1SIMO/UCB1SDA, UCB1SOMI/UCB1SCL). */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN4 + GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION); /* eUSCI I2C Slave Configuration */ I2C_initSlave(EUSCI_B1_BASE, SLAVE_ADDRESS, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); I2C_initSlave(EUSCI_B1_BASE, 0xC, EUSCI_B_I2C_OWN_ADDRESS_OFFSET1, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); I2C_setMode(EUSCI_B1_BASE, EUSCI_B_I2C_RECEIVE_MODE); /* Enable the module and enable interrupts */ I2C_enableModule(EUSCI_B1_BASE); MAP_I2C_clearInterruptFlag(EUSCI_B1_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0); MAP_I2C_enableInterrupt(EUSCI_B1_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0); MAP_Interrupt_enableInterrupt(INT_EUSCIB1); #else /* eUSCI I2C Slave Configuration */ I2C_initSlave(EUSCI_B0_BASE, SLAVE_ADDRESS, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); #if 1 I2C_initSlave(EUSCI_B0_BASE, 0xC, EUSCI_B_I2C_OWN_ADDRESS_OFFSET1, EUSCI_B_I2C_OWN_ADDRESS_ENABLE); #endif /* Select Port B2 for I2C - Set Pin 6, 7 to input Primary Module Function */ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); /* Define the SMbus alert pin */ MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN0); MAP_GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN0); I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_MODE); /* Enable the module and enable interrupts */ I2C_enableModule(EUSCI_B0_BASE); MAP_I2C_clearInterruptFlag(EUSCI_B0_BASE, flags); MAP_Interrupt_setPriority(INT_EUSCIB0, configMAX_SYSCALL_INTERRUPT_PRIORITY); MAP_I2C_enableInterrupt(EUSCI_B0_BASE, flags); MAP_Interrupt_enableInterrupt(INT_EUSCIB0); #endif }
void I2C_AlertDone() { #if 0 I2C_initSlave(EUSCI_B0_BASE, 0xC, EUSCI_B_I2C_OWN_ADDRESS_OFFSET1, EUSCI_B_I2C_OWN_ADDRESS_DISABLE); #endif MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN0); }
/* * ======== WiFiCC3100_deAssertCS ======== * Deassert the CC3100 chip select pin. */ static void WiFiCC3100_deAssertCS() { WiFiCC3100_HWAttrs const *hwAttrs = wifiHandle->hwAttrs; #if defined(MSP430WARE) || defined(MSP432WARE) MAP_GPIO_setOutputHighOnPin(hwAttrs->csPort, hwAttrs->csPin); #else GPIOPinWrite(hwAttrs->csPort, hwAttrs->csPin, hwAttrs->csPin); #endif Log_print0(Diags_USER2, "SPI CS deasserted, end of transfer."); }
/* * ======== CC3100_enable ======== * SimpleLink Host Driver API to toggle the CC3100 device enable pin. */ void CC3100_enable() { WiFiCC3100_HWAttrs const *hwAttrs = wifiHandle->hwAttrs; #if defined(MSP430WARE) || defined(MSP432WARE) MAP_GPIO_setOutputHighOnPin(hwAttrs->enPort, hwAttrs->enPin); #else GPIOPinWrite(hwAttrs->enPort, hwAttrs->enPin, hwAttrs->enPin); #endif Log_print0(Diags_USER2, "CC3100 has been enabled."); }
/* EUSCI A0 UART ISR - Echos data back to PC host */ void euscia0_isr(void) { uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_MODULE); MAP_UART_clearInterruptFlag(EUSCI_A0_MODULE, status); if(status & EUSCI_A_UART_RECEIVE_INTERRUPT) { RXData = MAP_UART_receiveData(EUSCI_A0_MODULE); if(RXData != TXData) // Check value { MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); while(1); // Trap CPU } TXData++; MAP_Interrupt_disableSleepOnIsrExit(); } }
/* * ======== MSP_EXP432P401R_initWiFi ======== */ void MSP_EXP432P401R_initWiFi(void) { /* Configure EN & CS pins to disable CC3100 */ MAP_GPIO_setAsOutputPin(GPIO_PORT_P3, GPIO_PIN0); MAP_GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN1); MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P3, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN1); /* Configure CLK, MOSI & MISO for SPI0 (EUSCI_B0) */ MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1, GPIO_PIN5 | GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION); MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); /* Configure IRQ pin */ MAP_GPIO_setAsInputPinWithPullDownResistor(GPIO_PORT_P2, GPIO_PIN5); MAP_GPIO_interruptEdgeSelect(GPIO_PORT_P2, GPIO_PIN5, GPIO_LOW_TO_HIGH_TRANSITION); /* Initialize SPI and WiFi drivers */ MSP_EXP432P401R_initDMA(); SPI_init(); WiFi_init(); }
int main(void) { WDT_A_holdTimer(); //Configure Timer unsigned int dcoFrequency = 3E+6; MAP_CS_setDCOFrequency(dcoFrequency); MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // ( 1Mhz / 64 ) / (Period = 15625) = 1 second //////////////////////////////////////////////////////////////////////////////////////////////////// // Buttons init //////////////////////////////////////////////////////////////////////////////////////////////////// // Set switch 1 (S1) as input button (connected to P1.1) MAP_GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P1, GPIO_PIN1 ); // Set switch 2 (S2) as input button (connected to P1.4) MAP_GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P1, GPIO_PIN4 ); //////////////////////////////////////////////////////////////////////////////////////////////////// // Timer A 0 and PWM on 2.4 //////////////////////////////////////////////////////////////////////////////////////////////////// GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION); //writes 0's in PXSEL registers for pins 1.2 and 1.3 // Set Timer A period (PWM signal period) TA0CCR0 = 10000 ; // i think i wrote this wring, his example he showed in class is is 10000 // Set Duty cycle TA0CCR1 = 0 ; //inital DutyCycle of 0% (we don't want the motor to move unless we push button // Set output mode to Reset/Set TA0CCTL1 = OUTMOD_7 ; // Macro which is equal to 0x00e0, defined in msp432p401r.h // Initialize Timer A TA0CTL = TASSEL__SMCLK | MC__UP | TACLR ; // this bitwise or’s multiple settings at the same time (this just sets different bits in the register to set these functionalities/settings) //Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_UP_MODE); //////////////////////////////////////////////////////////////////////////////////////////////////// // Timer A 2 and PWM on P5.6 //////////////////////////////////////////////////////////////////////////////////////////////////// GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P5, GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION); //writes 0's in PXSEL registers for pins 1.2 and 1.3 // Set Timer A period (PWM signal period) TA2CCR0 = 10000 ; // i think i wrote this wring, his example he showed in class is is 10000 // Set Duty cycle TA2CCR1 = 0 ; //inital DutyCycle of 0% (we don't want the motor to move unless we push button // Set output mode to Reset/Set TA2CCTL1 = OUTMOD_7 ; // Macro which is equal to 0x00e0, defined in msp432p401r.h // Initialize Timer A TA2CTL = TASSEL__SMCLK | MC__UP | TACLR ; // this bitwise or’s multiple settings at the same time (this just sets different bits in the register to set these functionalities/settings) //Does this start the timer?? (is next line necessary?) //Timer_A_startCounter(TIMER_A1_MODULE, TIMER_A_UP_MODE); ///////////////////////////////////////////////////////////////////////////////////////////////////// //Set LED's as outputs and turn off MAP_GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0); MAP_GPIO_setAsOutputPin(GPIO_PORT_P2,GPIO_PIN0); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0); int countedges1 = 1; int countedges2 = 1; while(1){ //infinite loop //////////////////////////////////////////////////////////////////////////////////////////////////// // Turn one direction //////////////////////////////////////////////////////////////////////////////////////////////////// if(GPIO_INPUT_PIN_LOW == MAP_GPIO_getInputPinValue ( GPIO_PORT_P1, GPIO_PIN1 )){ //stop timer 2 Timer_A_stopTimer(TIMER_A2_MODULE); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN6); //start timer 1 Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_UP_MODE); TA0CCR1 = 1000 * countedges1; //increse Duty Cycle by 10% (period is 10000) if (TA0CCR1 > TA0CCR0){ //if Dutcy Cycle = 100%, go back to 0% TA0CCR1 = 0; }//end nested if if (countedges1>11){ countedges1 = 0; } countedges1++; while(GPIO_INPUT_PIN_LOW == MAP_GPIO_getInputPinValue ( GPIO_PORT_P1, GPIO_PIN1 )){ MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0); }//end nested while MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0); }//end switch 1 if else{ //the button is not being pushed so do not spin motor (DutyCycle = 0); TA0CCR1 = 0; } //////////////////////////////////////////////////////////////////////////////////////////////////// // Turn other direction //////////////////////////////////////////////////////////////////////////////////////////////////// if(GPIO_INPUT_PIN_LOW == MAP_GPIO_getInputPinValue ( GPIO_PORT_P1, GPIO_PIN4 )){ //stop timer 1 Timer_A_stopTimer(TIMER_A0_MODULE); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN4); //start timer 2 Timer_A_startCounter(TIMER_A2_MODULE, TIMER_A_UP_MODE); TA2CCR1 = countedges2 * 1000; //increse Duty Cycle by 10% (period is 10000) if (TA2CCR1 > TA2CCR0){ //if Dutcy Cycle = 100%, go back to 0% TA2CCR1 = 0; }//end nested if if (countedges2>11){ countedges2 = 0; } countedges2++; while(GPIO_INPUT_PIN_LOW == MAP_GPIO_getInputPinValue ( GPIO_PORT_P1, GPIO_PIN4 )){ MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0); }//end nested while MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0); }//end switch 2 if else{ //the button is not being pushed so do not spin motor (DutyCycle = 0) TA2CCR1 = 0; } }//end while }//end main