/* * ======== MSP_EXP430F5529LP_initWiFi ======== */ void MSP_EXP430F5529LP_initWiFi(void) { /* Configure EN & CS pins to disable CC3100 */ GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2); GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN6); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN2); GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN6); /* Configure SPI */ /* SPI CLK */ GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN2); /* MOSI/SIMO */ GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN0); /* MISO/SOMI */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3, GPIO_PIN1); /* Configure IRQ pin */ GPIO_setAsInputPinWithPullDownResistor(GPIO_PORT_P2, GPIO_PIN0); GPIO_selectInterruptEdge(GPIO_PORT_P2, GPIO_PIN0, GPIO_LOW_TO_HIGH_TRANSITION); /* Initialize SPI and WiFi drivers */ SPI_init(); WiFi_init(); }
/**********************************************************************//** * @brief Initializes the System * * @param none * * @return none *************************************************************************/ void SystemInit(void) { // Set the DCO to 8MHz (it's also the device's power-on setting). Do not change this frequency! // It impacts the cap touch scan window. CS_setDCOFreq(__MSP430_BASEADDRESS_CS__, CS_DCORSEL_0, CS_DCOFSEL_6); // Configure clock source and clock dividers. After this the clock configuration will be as follows: // ACLK=LFXT1/1=32,768Hz; SMCLK=DCOCLK/1=8MHz; and MCLK=DCOCLK/1=8MHz. CS_clockSignalInit(__MSP430_BASEADDRESS_CS__, CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_clockSignalInit(__MSP430_BASEADDRESS_CS__, CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_clockSignalInit(__MSP430_BASEADDRESS_CS__, CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // Set all GPIO to output low to minimize current draw by eliminating floating pins. GPIO_setOutputLowOnPin(GPIO_PORT_PA, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); GPIO_setOutputLowOnPin(GPIO_PORT_PB, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); GPIO_setOutputLowOnPin(GPIO_PORT_PJ, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); GPIO_setAsOutputPin(GPIO_PORT_PA, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); GPIO_setAsOutputPin(GPIO_PORT_PB, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); GPIO_setAsOutputPin(GPIO_PORT_PJ, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); // Configure the left button (S2) connected to P4.6. For this enable the internal pull-up resistor and // setup the pin interrupt to trigger on rising edges. GPIO_setAsInputPinWithPullUpresistor(GPIO_PORT_P4, GPIO_PIN5); GPIO_interruptEdgeSelect(GPIO_PORT_P4, GPIO_PIN5, GPIO_LOW_TO_HIGH_TRANSITION); GPIO_clearInterruptFlag(GPIO_PORT_P4, GPIO_PIN5); GPIO_enableInterrupt(GPIO_PORT_P4, GPIO_PIN5); // Configure the right button (S3) connected to P1.1. For this enable the internal pull-up resistor and // setup the pin interrupt to trigger on rising edges. GPIO_setAsInputPinWithPullUpresistor(GPIO_PORT_P1, GPIO_PIN1); GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN1, GPIO_LOW_TO_HIGH_TRANSITION); GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1); // CapSense Setup. GPIO pins P1.3-1.5 and P3.4-3.6 are used for capacitive touch so let's // switch them to inputs. // GPIO_setAsInputPin(GPIO_PORT_P1, GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5); GPIO_setAsInputPin(GPIO_PORT_P3, GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6); // Enable LFXT functionality on PJ.4 and PJ.5. For this we only need to configure PJ.4 to // LFXIN and the port module logic takes care of the rest. GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_PJ, GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION); // Disable the GPIO power-on default high-impedance mode to activate previously configured port settings PMM_unlockLPM5(__MSP430_BASEADDRESS_PMM_FRAM__); // Perform the required LFXT startup procedure now that all of the port pins are configured. CS_setExternalClockSource(__MSP430_BASEADDRESS_CS__, 32768, 0); CS_LFXTStart(__MSP430_BASEADDRESS_CS__, CS_LFXT_DRIVE0); // Initialize LCD driver and the context for the LCD Sharp96x96_LCDInit(); TA0_enableVCOMToggle(); GrContextInit(&sContext, &g_sharp96x96LCD); GrContextForegroundSet(&sContext, ClrBlack); GrContextBackgroundSet(&sContext, ClrWhite); onLED(); //blink LED1 }
void InitHardware(){ #ifdef __MSP430_HAS_PORT1_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT2_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT3_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P3, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P3, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT4_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT5_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT6_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P6, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P6, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT7_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P7, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P7, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT8_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P8, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT9_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P9, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P9, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORTJ_R__ GPIO_setOutputLowOnPin(GPIO_PORT_PJ, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_PJ, GPIO_ALL); #endif InitLED(); InitUserInputButtons(); InitBubbleSensor(); InitOcclusionSensor(); InitReservoirLevelPins(); InitMotor(); }
void sensorInit() { GPIO_setAsOutputPin(RED_LED_PORT, RED_LED_PIN); GPIO_setAsOutputPin(GREEN_LED_PORT, GREEN_LED_PIN); GPIO_setAsOutputPin(BLUE_LED_PORT, BLUE_LED_PIN); adcInitForSensor(); }
void gpio_init_remote_dev(event_handler_t sw1_handler, event_handler_t sw2_handler, event_handler_t sw3_handler, event_handler_t sw4_handler, event_handler_t sw5_handler, event_handler_t sw6_handler, event_handler_t sw7_handler) { // Switch init GPIO_setAsInputPinWithPullUpResistor(SW1_PORT, SW1_PIN); GPIO_setAsInputPinWithPullUpResistor(SW2_PORT, SW2_PIN); GPIO_setAsInputPinWithPullUpResistor(SW3_PORT, SW3_PIN); GPIO_setAsInputPinWithPullUpResistor(SW4_PORT, SW4_PIN); GPIO_setAsInputPinWithPullUpResistor(SW5_PORT, SW5_PIN); /* GPIO_setAsInputPinWithPullUpResistor(SW6_PORT, SW6_PIN); GPIO_setAsInputPinWithPullUpResistor(SW7_PORT, SW7_PIN); */ GPIO_selectInterruptEdge(SW1_PORT, SW1_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_selectInterruptEdge(SW2_PORT, SW2_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_selectInterruptEdge(SW3_PORT, SW3_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_selectInterruptEdge(SW4_PORT, SW4_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_selectInterruptEdge(SW5_PORT, SW5_PIN, GPIO_HIGH_TO_LOW_TRANSITION); /* GPIO_selectInterruptEdge(SW6_PORT, SW6_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_selectInterruptEdge(SW7_PORT, SW7_PIN, GPIO_HIGH_TO_LOW_TRANSITION); */ GPIO_clearInterrupt(SW1_PORT, SW1_PIN); GPIO_clearInterrupt(SW2_PORT, SW2_PIN); GPIO_clearInterrupt(SW3_PORT, SW3_PIN); GPIO_clearInterrupt(SW4_PORT, SW4_PIN); GPIO_clearInterrupt(SW5_PORT, SW5_PIN); /* GPIO_clearInterrupt(SW6_PORT, SW6_PIN); GPIO_clearInterrupt(SW7_PORT, SW7_PIN); */ GPIO_enableInterrupt(SW1_PORT, SW1_PIN); GPIO_enableInterrupt(SW2_PORT, SW2_PIN); GPIO_enableInterrupt(SW3_PORT, SW3_PIN); GPIO_enableInterrupt(SW4_PORT, SW4_PIN); GPIO_enableInterrupt(SW5_PORT, SW5_PIN); /* GPIO_enableInterrupt(SW6_PORT, SW6_PIN); GPIO_enableInterrupt(SW7_PORT, SW7_PIN); */ _sw1_event = event_add(sw1_handler); _sw2_event = event_add(sw2_handler); _sw3_event = event_add(sw3_handler); _sw4_event = event_add(sw4_handler); _sw5_event = event_add(sw5_handler); /* _sw6_event = event_add(sw6_handler); _sw7_event = event_add(sw7_handler); */ // LED init GPIO_setAsOutputPin(LED1_PORT, LED1_PIN); GPIO_setAsOutputPin(LED2_PORT, LED2_PIN); GPIO_setAsOutputPin(LED3_PORT, LED3_PIN); GPIO_setOutputLowOnPin(LED1_PORT, LED1_PIN); GPIO_setOutputLowOnPin(LED2_PORT, LED2_PIN); GPIO_setOutputLowOnPin(LED3_PORT, LED3_PIN); }
void led_init() { GPIO_setAsOutputPin(OUTPUT1_BASEADDRESS, OUTPUT1_PORT, OUTPUT1_PIN); GPIO_setAsOutputPin(OUTPUT2_BASEADDRESS, OUTPUT2_PORT, OUTPUT2_PIN); GPIO_setAsOutputPin(OUTPUT3_BASEADDRESS, OUTPUT3_PORT, OUTPUT3_PIN); led_off(1); led_off(2); led_off(3); }
/** Initialise LED Dial, setting GPIO parameters */ void initialiseLedDial() { //GPIO 2.7 GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN7); //GPIO 5.1, 5.2, 5.3 GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN1|GPIO_PIN2|GPIO_PIN3); //GPIO 8.0 GPIO_setAsOutputPin(GPIO_PORT_P8, GPIO_PIN0); }
//***************************************************************************** // Initialize GPIO //***************************************************************************** void initGPIO(void) { // Set pin P1.0 to output direction and turn LED off GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); // Red LED (LED1) GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Set pin P4.7 to output direction and turn LED off GPIO_setAsOutputPin( GPIO_PORT_P4, GPIO_PIN7 ); // Green LED (LED2) GPIO_setOutputLowOnPin( GPIO_PORT_P4, GPIO_PIN7 ); // // Set P2.1 as input with pull-up resistor (for push button S1) // // configure interrupt on low-to-high transition // // and then clear flag and enable the interrupt // GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P2, GPIO_PIN1 ); // GPIO_selectInterruptEdge ( GPIO_PORT_P2, GPIO_PIN1, GPIO_LOW_TO_HIGH_TRANSITION ); // GPIO_clearInterrupt ( GPIO_PORT_P2, GPIO_PIN1 ); // GPIO_enableInterrupt ( GPIO_PORT_P2, GPIO_PIN1 ); // // Set P1.1 as input with pull-up resistor (for push button S2) // // configure interrupt on low-to-high transition // // and then clear flag and enable the interrupt // GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P1, GPIO_PIN1 ); // GPIO_selectInterruptEdge ( GPIO_PORT_P1, GPIO_PIN1, GPIO_LOW_TO_HIGH_TRANSITION ); // GPIO_clearInterrupt ( GPIO_PORT_P1, GPIO_PIN1 ); // GPIO_enableInterrupt ( GPIO_PORT_P1, GPIO_PIN1 ); // // Connect pins to clock crystals // GPIO_setAsPeripheralModuleFunctionInputPin( // GPIO_PORT_P5, // GPIO_PIN5 + // XOUT on P5.5 // GPIO_PIN4 + // XIN on P5.4 // GPIO_PIN3 + // XT2OUT on P5.3 // GPIO_PIN2 // XT2IN on P5.2 // ); // When running this lab exercise, you will need to pull the JP8 jumper and // use a jumper wire to connect signal from P1.3 (on boosterpack pinouts) to // JP8.2 (bottom pin) of LED1 jumper ... this lets the TA0.2 signal drive // LED1 directly (without having to use interrupts) GPIO_setAsPeripheralModuleFunctionOutputPin( GPIO_PORT_P1, GPIO_PIN3 ); // // Output the ACLK and MCLK signals to their respective pins - which allows you to // // watch them with a logic analyzer (ACLK on P1.0, SMCLK on P2.2, MCLK on P7.7) // GPIO_setAsPeripheralModuleFunctionOutputPin( // GPIO_PORT_P1, // GPIO_PIN0 // ACLK on P1.0 (Shared with LED1 on jumper JP8) // ); // GPIO_setAsPeripheralModuleFunctionOutputPin( // GPIO_PORT_P2, // GPIO_PIN2 // SMCLK on P2.2 (Boosterpack - Right side (J5) pin 2) // ); }
/* * This function drives all the I/O's as output-low, to avoid floating inputs * (which cause extra power to be consumed). This setting is compatible with * TI FET target boards, the F5529 Launchpad, and F5529 Experimenters Board; * but may not be compatible with custom hardware, which may have components * attached to the I/Os that could be affected by these settings. So if using * other boards, this function may need to be modified. */ void initPorts(void) { #ifdef __MSP430_HAS_PORT1_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT2_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT3_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P3, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P3, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT4_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT5_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT6_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P6, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P6, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT7_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P7, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P7, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT8_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P8, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT9_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P9, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P9, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORTJ_R__ GPIO_setOutputLowOnPin(GPIO_PORT_PJ, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_PJ, GPIO_ALL); #endif }
void InitMotor(){ GPIO_setAsOutputPin( MOTOR_COIL_A1_PORT, MOTOR_COIL_A1_PIN ); GPIO_setAsOutputPin( MOTOR_COIL_A2_PORT, MOTOR_COIL_A2_PIN ); GPIO_setAsOutputPin( MOTOR_COIL_B1_PORT, MOTOR_COIL_B1_PIN ); GPIO_setAsOutputPin( MOTOR_COIL_B2_PORT, MOTOR_COIL_B2_PIN ); GPIO_setAsOutputPin( MOTOR_ENABLE_PORT, MOTOR_ENABLE_PIN ); GPIO_setOutputLowOnPin( MOTOR_COIL_A1_PORT, MOTOR_COIL_A1_PIN ); GPIO_setOutputLowOnPin( MOTOR_COIL_A2_PORT, MOTOR_COIL_A2_PIN ); GPIO_setOutputLowOnPin( MOTOR_COIL_B1_PORT, MOTOR_COIL_B1_PIN ); GPIO_setOutputLowOnPin( MOTOR_COIL_B2_PORT, MOTOR_COIL_B2_PIN ); GPIO_setOutputLowOnPin( MOTOR_ENABLE_PORT, MOTOR_ENABLE_PIN ); }
void HAL_LCD_PortInit(void) { // LCD_SCK GPIO_setAsPeripheralModuleFunctionOutputPin(LCD_SCK_PORT, LCD_SCK_PIN, GPIO_PRIMARY_MODULE_FUNCTION); // LCD_MOSI GPIO_setAsPeripheralModuleFunctionOutputPin(LCD_MOSI_PORT, LCD_MOSI_PIN, GPIO_PRIMARY_MODULE_FUNCTION); // LCD_RST GPIO_setAsOutputPin(LCD_RST_PORT, LCD_RST_PIN); // LCD_RS GPIO_setAsOutputPin(LCD_DC_PORT, LCD_DC_PIN); // LCD_CS GPIO_setAsOutputPin(LCD_CS_PORT, LCD_CS_PIN); }
//------------------------------------------------------------------------------ int InitLight(void) { int err = 0; memset(leds, 0, sizeof(leds)); // Set P1.0 to output direction to drive red LED GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0); // Configure SysTick SysTick_enableModule(); SysTick_setPeriod(16000); // with a 68 MHz clock, this period is 1 ms SysTick_enableInterrupt(); // MAP_Interrupt_enableSleepOnIsrExit(); MAP_Interrupt_enableMaster(); initStrip(); // ***** HAVE YOU SET YOUR NUM_LEDS DEFINE IN WS2812.C? ****** // set strip color red fillStrip(0xFF, 0x00, 0x00, 0x00); // show the strip showStrip(); // gradually fill for ever and ever u_int numLEDs = 7; gradualFill(numLEDs, 0x0F, 0x00, 0x00, 0x00); // red return err; }
void config_DS4_LED(void){ GPIO_setAsOutputPin( // config P1.0 (DS4 LED) GPIO as output GPIO_PORT_P1, GPIO_PIN0 ); activate_GPIO_config(); }
void main (void) { //Stop WDT WDT_hold(__MSP430_BASEADDRESS_WDT_A__); //Set P1.0 to output direction GPIO_setAsOutputPin(__MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 ); //Start timer in continuous mode sourced by SMCLK Timer_startContinousMode( __MSP430_BASEADDRESS_T1A3__, TIMER_CLOCKSOURCE_SMCLK, TIMER_CLOCKSOURCE_DIVIDER_1, TIMER_TAIE_INTERRUPT_DISABLE, TIMER_DO_CLEAR ); //Initiaze compare mode Timer_initCompare(__MSP430_BASEADDRESS_T1A3__, TIMER_CAPTURECOMPARE_REGISTER_0, TIMER_CAPTURECOMPARE_INTERRUPT_ENABLE, TIMER_OUTPUTMODE_OUTBITVALUE, COMPARE_VALUE ); //Enter LPM0, enable interrupts __bis_SR_register(LPM0_bits + GIE); //For debugger __no_operation(); }
void main (void) { //Watchdog mode -> reset after expired time; WDT is clocked by ACLK //Set Watchdog Timer timeout 1s - SET BREAKPOINT HERE WDT_watchdogTimerInit(__MSP430_BASEADDRESS_WDT_A__, WDT_CLOCKSOURCE_ACLK, WDT_CLOCKDIVIDER_32K); //Set P1.0 to output direction GPIO_setAsOutputPin(__MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 ); //Toggle P1.0 GPIO_toggleOutputOnPin( __MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 ); //Enter LPM3 __bis_SR_register(LPM3_bits + GIE); //For debugger __no_operation(); }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer // Set pin P1.0 to output direction and initialize low GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Set switch 2 (S2) as input button (connected to P1.1) GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P2, GPIO_PIN1 ); while(1) { // Read pin P1.1 which is connected to push button 2 usiButton1 = GPIO_getInputPinValue ( GPIO_PORT_P2, GPIO_PIN1 ); if ( usiButton1 == GPIO_INPUT_PIN_LOW ) { // If button is down, turn on LED GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 ); } else { // If button is up, turn off LED GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); } } }
void main (void) { //Stop watchdog timer WDT_hold(__MSP430_BASEADDRESS_WDT_A__); //Set P1.x to output direction GPIO_setAsOutputPin(__MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 ); //Set all P1 pins HI GPIO_setOutputHighOnPin( __MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 ); //Enter LPM4 w/interrupt __bis_SR_register(LPM4_bits + GIE); //For debugger __no_operation(); }
//***************************************************************************** void initGPIO(void) { // Set pin P1.0 to output direction and turn off LED GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); __delay_cycles( HALF_SECOND ); }
void buttonInit(void){ GPIO_setCallback(Board_BUTTON0, gpioButton0); GPIO_enableInt(Board_BUTTON0); /* Configure RGB LED pins */ GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN4 | GPIO_PIN6); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN6); /* Set RGB LED to red */ P2OUT |= BIT6; P2OUT &= ~BIT4; P5OUT &= ~BIT6; /* Setup Button */ GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P5,GPIO_PIN1); GPIO_clearInterruptFlag(GPIO_PORT_P5, GPIO_PIN1); GPIO_enableInterrupt(GPIO_PORT_P5, GPIO_PIN1); GPIO_interruptEdgeSelect(GPIO_PORT_P5, GPIO_PIN1, GPIO_HIGH_TO_LOW_TRANSITION); Interrupt_enableInterrupt(INT_PORT5); }
void msp430_i2c_disable(void) { if (!i2c.enabled) return; USCI_B_I2C_disable(USCI_B0_BASE); GPIO_setAsOutputPin( GPIO_PORT_P3, GPIO_PIN0 + GPIO_PIN0 ); GPIO_setOutputHighOnPin( GPIO_PORT_P3, GPIO_PIN0 + GPIO_PIN0 ); i2c.enabled = 0; return; }
////------------------------------------------------------------------------------ Fd_t spi_Open(void) { /* Selecting P9.5 P9.6 and P9.7 in SPI mode */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION); /* CS setup. */ GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN6); GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN6); /* Configuring SPI in 3wire master mode */ SPI_initMaster(EUSCI_B1_MODULE, &SDspiConfig); /* Enable SPI module */ SPI_enableModule(EUSCI_B1_MODULE); return 0;//NONOS_RET_OK; }
__LINK_C error_t hw_gpio_configure_pin(pin_id_t pin_id, cc430_gpio_mode_t mode) { // TODO check if already configured (return EALREADY) if(mode == GPIO_MODE_OUTPUT || mode == GPIO_MODE_OUTPUT_FULL_DRIVE_STRENGTH) { GPIO_setAsOutputPin(pin_id.port, pin_id.pin); if(mode == GPIO_MODE_OUTPUT_FULL_DRIVE_STRENGTH) GPIO_setDriveStrength(pin_id.port, pin_id.pin, GPIO_FULL_OUTPUT_DRIVE_STRENGTH); } else if(mode ==GPIO_MODE_INPUT) GPIO_setAsInputPin(pin_id.port, pin_id.pin); else if(mode == GPIO_MODE_INPUT_PULL_UP) GPIO_setAsInputPinWithPullUpResistor(pin_id.port, pin_id.pin); else if(mode == GPIO_MODE_INPUT_PULL_DOWN) GPIO_setAsInputPinWithPullDownResistor(pin_id.port, pin_id.pin); return SUCCESS; }
void main(void) { //Stop watchdog timer WDT_A_hold(WDT_A_BASE); //Set P1.0 to output direction GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); //Enable P1.4 internal resistance as pull-Up resistance GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P1, GPIO_PIN4 ); //P1.4 interrupt enabled GPIO_enableInterrupt( GPIO_PORT_P1, GPIO_PIN4 ); //P1.4 Hi/Lo edge GPIO_selectInterruptEdge( GPIO_PORT_P1, GPIO_PIN4, GPIO_HIGH_TO_LOW_TRANSITION ); //P1.4 IFG cleared GPIO_clearInterrupt( GPIO_PORT_P1, GPIO_PIN4 ); //Enter LPM4 w/interrupt __bis_SR_register(LPM4_bits + GIE); //For debugger __no_operation(); }
static void prvSetupHardware( void ) { /* Stop Watchdog timer. */ WDT_A_hold( __MSP430_BASEADDRESS_WDT_A__ ); /* Set all GPIO pins to output and low. */ GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setOutputLowOnPin( GPIO_PORT_P3, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setOutputLowOnPin( GPIO_PORT_P4, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setOutputLowOnPin( GPIO_PORT_PJ, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15 ); GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P3, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P4, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_PJ, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15 ); /* Configure P2.0 - UCA0TXD and P2.1 - UCA0RXD. */ GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN0 ); GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN0 ); GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P2, GPIO_PIN1, GPIO_SECONDARY_MODULE_FUNCTION ); GPIO_setAsPeripheralModuleFunctionOutputPin( GPIO_PORT_P2, GPIO_PIN0, GPIO_SECONDARY_MODULE_FUNCTION ); /* Set PJ.4 and PJ.5 for LFXT. */ GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_PJ, GPIO_PIN4 + GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION ); /* 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_0 ); /* Disable the GPIO power-on default high-impedance mode. */ PMM_unlockLPM5(); }
void main (void) { //Initialize WDT module in timer interval mode, //with SMCLK as source at an interval of 32 ms. WDT_intervalTimerInit(__MSP430_BASEADDRESS_WDT_A__, WDT_CLOCKSOURCE_SMCLK, WDT_CLOCKDIVIDER_32K); //Enable Watchdog Interupt SFR_enableInterrupt(__MSP430_BASEADDRESS_SFR__, WDTIE); //Set P1.0 to output direction GPIO_setAsOutputPin(__MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 ); //Enter LPM0, enable interrupts __bis_SR_register(LPM0_bits + GIE); //For debugger __no_operation(); }
//***************************************************************************** // //! \brief Initializes USCI_B1 with SPI mode. //! //! CLK: 1MHZ. //! ClockPhase: USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT. //! ClockPolarity: USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW //! MSB_first //! //! The Seeting is specified to Sharp96 communication. // //***************************************************************************** void msp430_spi_b1_init() { // Configure SPI PORT GPIO_setAsPeripheralModuleFunctionOutputPin(LCD_SPI_PORT, LCD_SPI_SI_PIN + LCD_SPI_SO_PIN + LCD_SPI_CLK_PIN); // Configure LCD_SPI_CS_PIN as output pin GPIO_setAsOutputPin(LCD_SPI_CS_PORT, LCD_SPI_CS_PIN); msp430_spi_b1_clearCS(); USCI_B_SPI_initMasterParam spiMasterParams= { USCI_B_SPI_CLOCKSOURCE_SMCLK, UCS_getSMCLK(), 8000000, USCI_B_SPI_MSB_FIRST, USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT, USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW }; USCI_B_SPI_initMaster(LCD_USCI_BASE, &spiMasterParams); USCI_B_SPI_enable(LCD_USCI_BASE); }
LED::LED(const Pin& pin, const bool is_on) : pin_(pin) { GPIO_setAsOutputPin(pin_.port, pin_.pin); set(is_on); }
void initGPIO(void){ // Set pin P1.0 to output direction and initialize low GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); }
void main (void) { //Stop Watchdog Timer WDT_hold(__MSP430_BASEADDRESS_WDT_A__); //P6.0 ADC option select GPIO_setAsPeripheralModuleFunctionOutputPin(__MSP430_BASEADDRESS_PORT6_R__, GPIO_PORT_P6, GPIO_PIN0); GPIO_setAsOutputPin( __MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 ); //Initialize the ADC12 Module /* * Base address of ADC12 Module * Use internal ADC12 bit as sample/hold signal to start conversion * USE MODOSC 5MHZ Digital Oscillator as clock source * Use default clock divider of 1 */ ADC12_init(__MSP430_BASEADDRESS_ADC12_PLUS__, ADC12_SAMPLEHOLDSOURCE_SC, ADC12_CLOCKSOURCE_ADC12OSC, ADC12_CLOCKDIVIDER_1); ADC12_enable(__MSP430_BASEADDRESS_ADC12_PLUS__); /* * Base address of ADC12 Module * For memory buffers 0-7 sample/hold for 64 clock cycles * For memory buffers 8-15 sample/hold for 4 clock cycles (default) * Disable Multiple Sampling */ ADC12_setupSamplingTimer(__MSP430_BASEADDRESS_ADC12_PLUS__, ADC12_CYCLEHOLD_64_CYCLES, ADC12_CYCLEHOLD_4_CYCLES, ADC12_MULTIPLESAMPLESDISABLE); //Configure Memory Buffer /* * Base address of the ADC12 Module * Configure memory buffer 0 * Map input A0 to memory buffer 0 * Vref+ = AVcc * Vr- = AVss * Memory buffer 0 is not the end of a sequence */ ADC12_memoryConfigure(__MSP430_BASEADDRESS_ADC12_PLUS__, ADC12_MEMORY_0, ADC12_INPUT_A0, ADC12_VREFPOS_AVCC, ADC12_VREFNEG_AVSS, ADC12_NOTENDOFSEQUENCE); //Enable memory buffer 0 interrupt ADC12_enableInterrupt(__MSP430_BASEADDRESS_ADC12_PLUS__, ADC12IE0); while (1) { //Enable/Start sampling and conversion /* * Base address of ADC12 Module * Start the conversion into memory buffer 0 * Use the single-channel, single-conversion mode */ ADC12_startConversion(__MSP430_BASEADDRESS_ADC12_PLUS__, ADC12_MEMORY_0, ADC12_SINGLECHANNEL); //LPM0, ADC12_ISR will force exit __bis_SR_register(LPM0_bits + GIE); //for Debugger __no_operation(); } }
void InitLED(){ //Set P1.0 to output direction GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); GPIO_setAsOutputPin( GPIO_PORT_P4, GPIO_PIN7 ); }