/* * ======== 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(); }
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); }
//***************************************************************************** // 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) // ); }
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) { //Stop WDT WDT_hold(__MSP430_BASEADDRESS_WDT_A__); //P2.2 and P2.3 output //P2.2 and P2.3 options select GPIO_setAsPeripheralModuleFunctionOutputPin(__MSP430_BASEADDRESS_PORT2_R__, GPIO_PORT_P2, GPIO_PIN2 + GPIO_PIN3 ); //Start timer Timer_startUpMode( __MSP430_BASEADDRESS_T1A3__, TIMER_CLOCKSOURCE_SMCLK, TIMER_CLOCKSOURCE_DIVIDER_1, TIMER_PERIOD, TIMER_TAIE_INTERRUPT_DISABLE, TIMER_CCIE_CCR0_INTERRUPT_DISABLE, TIMER_DO_CLEAR ); //Initialize compare mode to generate PWM1 Timer_initCompare(__MSP430_BASEADDRESS_T1A3__, TIMER_CAPTURECOMPARE_REGISTER_1, TIMER_CAPTURECOMPARE_INTERRUPT_DISABLE, TIMER_OUTPUTMODE_RESET_SET, DUTY_CYCLE1 ); //Initialize compare mode to generate PWM2 Timer_initCompare(__MSP430_BASEADDRESS_T1A3__, TIMER_CAPTURECOMPARE_REGISTER_2, TIMER_CAPTURECOMPARE_INTERRUPT_ENABLE, TIMER_OUTPUTMODE_RESET_SET, DUTY_CYCLE2 ); //Enter LPM0 __bis_SR_register(LPM0_bits); //For debugger __no_operation(); }
/* * ======== MSP_EXP430F5529LP_initSPI ======== */ void MSP_EXP430F5529LP_initSPI(void) { /* USCIB1 */ /* * NOTE: TI-RTOS examples configure USCIB0 as either SPI or I2C. Thus, * a conflict occurs when the I2C & SPI drivers are used simultaneously in * an application. Modify the pin mux settings in this file and resolve the * conflict before running your the application. */ GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P4, GPIO_PIN3 | GPIO_PIN2 | GPIO_PIN1); /* SOMI/MISO */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P4, GPIO_PIN2); /* CLK and SIMO/MOSI */ GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P4, GPIO_PIN3 | GPIO_PIN1); SPI_init(); }
void main (void) { //Stop WDT WDT_hold(__MSP430_BASEADDRESS_WDT_A__); //Select CBOUT function on P1.6/CBOUT and set P1.6 output direction GPIO_setAsPeripheralModuleFunctionOutputPin(__MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN6 ); //Initialize the Comparator B module /* * Base Address of Comparator B, * Pin CB0 to Positive(+) Terminal, * Reference Voltage to Negative(-) Terminal, * Normal Power Mode, * Output Filter On with minimal delay, * Non-Inverted Output Polarity */ COMPB_init(__MSP430_BASEADDRESS_COMPB__, COMPB_INPUT0, COMPB_INPUT1, COMPB_POWERMODE_NORMALMODE, COMPB_FILTEROUTPUT_DLYLVL1, COMPB_NORMALOUTPUTPOLARITY ); //Allow power to Comparator module COMPB_enable(__MSP430_BASEADDRESS_COMPB__); //delay for the reference to settle __delay_cycles(75); //Enter LPM4 __bis_SR_register(LPM4_bits); //For debug __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); }
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
/** * RIC * Configure eUSCI A0 in UART mode with RX ringbuffer */ int uart_a0_init(event_handler_t uart_a0_rx_cmdline_handler) { /* * Short: A0_UART,1MHz-DCO-SMCLK/9600-N-1,normal * Connection: P2.0 (TX) - Isolation Block * P2.1 (RX) - Isolation Block * * Clock Source: SMCLK * Clock Rate: DCO 1MHz * * Baud Rate: 9600 baud/s * Parity: none * Stop Bits: 1 * Flow Control: none * Bit Order: LSB first * UART Mode: normal * */ int status = -1; // eUSCI A0 as UART device on P2.0 (TX) and P2.1 (RX) GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN0, GPIO_SECONDARY_MODULE_FUNCTION); GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN1, GPIO_SECONDARY_MODULE_FUNCTION); // configure parameters EUSCI_A_UART_initParam eUSCI_initParam = { EUSCI_A_UART_CLOCKSOURCE_SMCLK, // selectClockSource 6, // clockPrescalar UCBRx 8, // firstModReg UCBRFx 0x20, // secondModReg UCBRSx EUSCI_A_UART_NO_PARITY, EUSCI_A_UART_LSB_FIRST, EUSCI_A_UART_ONE_STOP_BIT, EUSCI_A_UART_MODE, EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION }; /* Initialize the ring buffers */ rb_attr_t rx_rbf_attr = { sizeof(_uart_a0_rx_rbmem[0]), ARRAY_SIZE( _uart_a0_rx_rbmem), _uart_a0_rx_rbmem }; rb_attr_t tx_rbf_attr = { sizeof(_uart_a0_tx_rbmem[0]), ARRAY_SIZE( _uart_a0_tx_rbmem), _uart_a0_tx_rbmem }; if (ring_buffer_init(&_uart_a0_rx_ringbuffer_id, &rx_rbf_attr) == 0 && ring_buffer_init(&_uart_a0_tx_ringbuffer_id, &tx_rbf_attr) == 0) { // ring buffers have been initialized successfully, continue to // register the events associated with UART RX and TX _uart_a0_rx_ev = event_add(uart_a0_rx_cmdline_handler); _uart_a0_tx_start_ev = event_add(uart_a0_tx_start_handler); _uart_a0_tx_rdy_ev = event_add(uart_a0_tx_rdy_handler); _uart_a0_tx_interrupt_pending_ev = event_add( uart_a0_tx_interrupt_pending); // write parameters to module and activate it EUSCI_A_UART_init(EUSCI_A0_BASE, &eUSCI_initParam); EUSCI_A_UART_enable(EUSCI_A0_BASE); EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT); // we need this order: module enable, then interrupt enable status = 0; } return status; }
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 initClocks() { // Set core power mode PMM_setVCore(PMM_CORE_LEVEL_3); // Configure pins for crystals GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P5, GPIO_PIN4+GPIO_PIN2 ); GPIO_setAsPeripheralModuleFunctionOutputPin( GPIO_PORT_P5, GPIO_PIN5+GPIO_PIN3 ); // Inform the system of the crystal frequencies UCS_setExternalClockSource( XT1_FREQ, // Frequency of XT1 in Hz. XT2_FREQ // Frequency of XT2 in Hz. ); // Initialize the crystals UCS_turnOnXT2( // used to be UCS_XT2Start in previous driverlib version UCS_XT2_DRIVE_4MHZ_8MHZ ); UCS_turnOnLFXT1( //used to be UCS_LFXT1Start in previous driverlib version UCS_XT1_DRIVE_0, UCS_XCAP_3 ); UCS_initClockSignal( UCS_FLLREF, // The reference for Frequency Locked Loop UCS_XT2CLK_SELECT, // Select XT2 UCS_CLOCK_DIVIDER_4 // The FLL reference will be 1 MHz (4MHz XT2/4) ); // Start the FLL and let it settle // This becomes the MCLCK and SMCLK automatically UCS_initFLLSettle( MCLK_FREQ_KHZ, MCLK_FLLREF_RATIO ); // Optional: set SMCLK to something else than full speed UCS_initClockSignal( UCS_SMCLK, UCS_DCOCLKDIV_SELECT, UCS_CLOCK_DIVIDER_1 ); // Set auxiliary clock UCS_initClockSignal( UCS_ACLK, UCS_XT1CLK_SELECT, UCS_CLOCK_DIVIDER_1 ); }
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); // ( 3Mhz / 64 ) / (Period = 46875) = 1 second //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); //////////////////////////////////////////////////////////////////////////////////////////////////// // ADC INITILIZATION P5.5 //////////////////////////////////////////////////////////////////////////////////////////////////// /* Initializing ADC */ MAP_ADC14_enableModule(); GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION); //writes 0's in PXSEL registers for pins 1.2 and 1.3 MAP_ADC14_setResolution(ADC_10BIT); // initialize to use a 10 Bit ADC MAP_ADC14_initModule(ADC_CLOCKSOURCE_SMCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,0); /* Configuring ADC Memory */ MAP_ADC14_configureSingleSampleMode(ADC_MEM0, false); //put results in this 16 bit register location to hold results, false means we are manually triggering MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false); //pin 5.5 is tied to channel 0 (A0) /* Configuring Sample Timer */ MAP_ADC14_enableSampleTimer(ADC_MANUAL_ITERATION); //Timer A setup MAP_Timer_A_configureUpMode(TIMER_A0_MODULE, &upConfig0); Interrupt_enableInterrupt(INT_TA0_0); Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_UP_MODE); /* Enabling/Toggling Conversion */ MAP_ADC14_enableConversion(); MAP_ADC14_toggleConversionTrigger(); //////////////////////////////////////////////////////////////////////////////////////////////////// // END ADC //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // 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 = DUTY_CYCLE * 10000; //inital DutyCycle of 0%.. Duty_Cycle is macro // 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_A2_MODULE, TIMER_A_UP_MODE); //////////////////////////////////////////////////////////////////////////////////////////////////// // END Timer A 2 and PWM on 5.6 //////////////////////////////////////////////////////////////////////////////////////////////////// Interrupt_enableMaster() ; while(1){ while(MAP_ADC14_isBusy()==0){ // poll the busy flag. we have a conversion going bc we already triggerted it above, so we are waiting for the conversion to be done, when it is, we are going to call the get result function. this just returns the 16 bit value rsults ADC_result = (uint16_t)MAP_ADC14_getResult(ADC_MEM0); //just goes to memory location takes results and returns the 16 bit value... this just continues to get repopulted. MAP_ADC14_toggleConversionTrigger(); ////once we got the result we start a new conversion and we go back to top and begin wiaitng until its dones again }//end nested while }//end inf while }//end main
/* @@********************* CYC_SYS_UART_Initialize *************************************** * Function : * Description : * Input parameters : * Output parameters: * Return : * Note : ****************************************************************************** */ uint8_t CYC_SYS_UART0_Initialize() { // Set the values UINT32 __IO lu32ACLKValue = 0; uint8_t lsReturnValue = SUCCESS; // Get Auxiliary Clock Source value lu32ACLKValue = UCS_getACLK(UCS_BASE); #ifdef TARGET_MSP430F5438A_EXPERIMENTER_BOARD //P3.4,5 = USCI_A0 TXD/RXD GPIO_setAsPeripheralModuleFunctionOutputPin( GPIO_PORT_P3, GPIO_PIN4 ); GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P3, GPIO_PIN5 ); #endif #ifdef TARGET_CYCLOPS_GAME //P3.3 = USCI_A0 TXD GPIO_setAsPeripheralModuleFunctionOutputPin( GPIO_PORT_P3, GPIO_PIN3 ); //P3.4 = USCI_A0 RXD GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P3, GPIO_PIN4 ); #endif /* Call the MSP43Ware function to initialize the UART port with the following configurations 1. PORT 0 2. Use SMCLK as Source 3. Value of SMCLK is 12MHz 4. Prescalar value to generate 57600 is 208 5. First stage modulator value is 5 6. Second stage modulator is ignored and value is set to 0 7. No Parity bits */ /*CHANGE THIS SO WE CAN SET ANY BAUD RATE WE WANT, DATA SHEET PG 907*/ USCI_UART_initAdvance ( UART_PORT_0_BASE_ADDRESS, USCI_UART_CLOCKSOURCE_SMCLK, BAUDRATE_CLK_PRESCALER, FIRST_STAGE_MODULATOR_VALUE, SECOND_STAGE_MODULATOR_VALUE, USCI_UART_NO_PARITY, USCI_UART_LSB_FIRST, USCI_UART_ONE_STOP_BIT, USCI_UART_MODE, USCI_UART_OVERSAMPLING_BAUDRATE_GENERATION ); //Enable UART module for operation USCI_UART_enable(USCI_A0_BASE); //Enable Receive Interrupt USCI_UART_clearInterruptFlag(USCI_A0_BASE, USCI_UART_RECEIVE_INTERRUPT ); USCI_UART_enableInterrupt(USCI_A0_BASE, USCI_UART_RECEIVE_INTERRUPT ); return lsReturnValue; }
uint8_t CYC_SYS_UART1_Initialize() { // Set the values UINT32 __IO lu32ACLKValue = 0; uint8_t lsReturnValue = SUCCESS; // Get Auxiliary Clock Source value lu32ACLKValue = UCS_getACLK(UCS_BASE); #ifdef TARGET_MSP430F5438A_EXPERIMENTER_BOARD //P3.4,5 = USCI_A0 TXD/RXD GPIO_setAsPeripheralModuleFunctionOutputPin( GPIO_PORT_P3, GPIO_PIN4 ); GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P3, GPIO_PIN5 ); #endif #ifdef TARGET_CYCLOPS_GAME //P3.3 = USCI_A0 TXD GPIO_setAsPeripheralModuleFunctionOutputPin( GPIO_PORT_P4, GPIO_PIN4 ); //P3.4 = USCI_A0 RXD GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P4, GPIO_PIN5 ); #endif /* Call the MSP43Ware function to initialize the UART port with the following configurations 1. PORT 1 2. Use SMCLK as Source 3. Value of SMCLK is 12MHz 4. Prescalar value to generate 57600 is 208 5. First stage modulator value is 5 6. Second stage modulator is ignored and value is set to 0 7. No Parity bits */ USCI_UART_initAdvance ( UART_PORT_1_BASE_ADDRESS, USCI_UART_CLOCKSOURCE_SMCLK, BAUDRATE_CLK_PRESCALER, FIRST_STAGE_MODULATOR_VALUE, SECOND_STAGE_MODULATOR_VALUE, USCI_UART_NO_PARITY, USCI_UART_LSB_FIRST, USCI_UART_ONE_STOP_BIT, USCI_UART_MODE, USCI_UART_OVERSAMPLING_BAUDRATE_GENERATION ); //Enable UART module for operation USCI_UART_enable(USCI_A1_BASE); //Enable Receive Interrupt USCI_UART_clearInterruptFlag(USCI_A1_BASE, USCI_UART_RECEIVE_INTERRUPT ); USCI_UART_enableInterrupt(USCI_A1_BASE, USCI_UART_RECEIVE_INTERRUPT ); GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN3); /*CTS line. Should be HIGH when we are processing received data. should be LOW when we are Ready to receive data*/ GPIO_setAsInputPin(GPIO_PORT_P4, GPIO_PIN0); /*RTS line. Should be LOW if it is OK to send data. Will be HIGH when it is not ok to send data*/ GPIO_setOutputLowOnPin(GPIO_PORT_P4,GPIO_PIN3 ); /*make it low because we are ready to receive data*/ return lsReturnValue; }
void main (void) { //Stop WDT WDT_hold(__MSP430_BASEADDRESS_WDT_A__); //Set DCO FLL reference = REFO UCS_clockSignalInit( __MSP430_BASEADDRESS_UCS__, UCS_FLLREF, UCS_REFOCLK_SELECT, UCS_CLOCK_DIVIDER_1 ); //VLO Clock Sources ACLK UCS_clockSignalInit( __MSP430_BASEADDRESS_UCS__, UCS_ACLK, UCS_REFOCLK_SELECT, UCS_CLOCK_DIVIDER_1 ); //Set Ratio and Desired MCLK Frequency and initialize DCO UCS_initFLLSettle( __MSP430_BASEADDRESS_UCS__, 1048, 32 ); //Setup Port Pins //P4.0 - P4.7 output //P4.0 - P4.7 Port Map functions GPIO_setAsPeripheralModuleFunctionOutputPin(__MSP430_BASEADDRESS_PORT4_R__, GPIO_PORT_P4, 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 PORTS- pass the port_mapping array, start @ P4MAP01, initialize //a single port, do not allow run-time reconfiguration of port mapping PMAP_configurePorts(__MSP430_BASEADDRESS_PORT_MAPPING__, (const unsigned char *)port_mapping, (unsigned char *)&P4MAP01, 1, PMAP_DISABLE_RECONFIGURATION ); //Start Up Down Timer Timer_startUpDownMode( __MSP430_BASEADDRESS_T0B7__, TIMER_CLOCKSOURCE_ACLK, TIMER_CLOCKSOURCE_DIVIDER_1, 256, TIMER_TAIE_INTERRUPT_DISABLE, TIMER_CCIE_CCR0_INTERRUPT_DISABLE, TIMER_SKIP_CLEAR ); //Generate PWM 1 Timer_initCompare(__MSP430_BASEADDRESS_T0B7__, TIMER_CAPTURECOMPARE_REGISTER_1, TIMER_CAPTURECOMPARE_INTERRUPT_DISABLE, TIMER_OUTPUTMODE_TOGGLE_SET, 192 ); //Generate PWM 2 Timer_initCompare(__MSP430_BASEADDRESS_T0B7__, TIMER_CAPTURECOMPARE_REGISTER_2, TIMER_CAPTURECOMPARE_INTERRUPT_DISABLE, TIMER_OUTPUTMODE_TOGGLE_SET, 128 ); //Generate PWM 3 Timer_initCompare(__MSP430_BASEADDRESS_T0B7__, TIMER_CAPTURECOMPARE_REGISTER_3, TIMER_CAPTURECOMPARE_INTERRUPT_DISABLE, TIMER_OUTPUTMODE_TOGGLE_SET, 96 ); //Generate PWM 4 Timer_initCompare(__MSP430_BASEADDRESS_T0B7__, TIMER_CAPTURECOMPARE_REGISTER_4, TIMER_CAPTURECOMPARE_INTERRUPT_DISABLE, TIMER_OUTPUTMODE_TOGGLE_SET, 64 ); //Generate PWM 5 Timer_initCompare(__MSP430_BASEADDRESS_T0B7__, TIMER_CAPTURECOMPARE_REGISTER_5, TIMER_CAPTURECOMPARE_INTERRUPT_DISABLE, TIMER_OUTPUTMODE_TOGGLE_SET, 32 ); //Generate PWM 6 Timer_initCompare(__MSP430_BASEADDRESS_T0B7__, TIMER_CAPTURECOMPARE_REGISTER_6, TIMER_CAPTURECOMPARE_INTERRUPT_DISABLE, TIMER_OUTPUTMODE_TOGGLE_SET, 16 ); //Enter LPM3 __bis_SR_register(LPM3_bits); //For debugger __no_operation(); }