예제 #1
0
static void prvSetupHardware( void )
{
extern void FPU_enableModule( void );
	
	/* The clocks are not configured here, but inside main_full() and
	main_blinky() as the full demo uses a fast clock and the blinky demo uses
	a slow clock. */

	/* Stop the watchdog timer. */
	MAP_WDT_A_holdTimer();
	
	/* Ensure the FPU is enabled. */
	FPU_enableModule();

	/* Selecting P1.2 and P1.3 in UART mode and P1.0 as output (LED) */
	MAP_GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION );
	MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 );
	MAP_GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 );

	/* Enable S2 and LED2 */
	MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN0 );
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0);
	MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN1 );
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1);
	MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN2 );
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2);

	MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN4);
	MAP_GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN4, GPIO_HIGH_TO_LOW_TRANSITION);
	MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN4);
	MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN4);
	MAP_Interrupt_enableInterrupt(INT_PORT1);

}
int main(void)
{
    /* Halting WDT  */
    MAP_WDT_A_holdTimer();

    /* Selecting P1.2 and P1.3 in UART mode and P1.0 as output (LED) */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
             GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);

    /* Setting DCO to 48MHz (upping Vcore) */
    MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
    CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);

    /* Configuring UART Module */
    MAP_UART_initModule(EUSCI_A0_MODULE, &uartConfig);

    /* Enable UART module */
    MAP_UART_enableModule(EUSCI_A0_MODULE);

    /* Enabling interrupts */
    MAP_UART_enableInterrupt(EUSCI_A0_MODULE, EUSCI_A_UART_RECEIVE_INTERRUPT);
    MAP_Interrupt_enableInterrupt(INT_EUSCIA0);
    MAP_Interrupt_enableSleepOnIsrExit();

    while(1)
    {
        MAP_UART_transmitData(EUSCI_A0_MODULE, TXData);

        MAP_Interrupt_enableSleepOnIsrExit();
        MAP_PCM_gotoLPM0InterruptSafe();
    }
}
예제 #3
0
파일: DWire.cpp 프로젝트: DelfiSpace/DWire
void DWire::_resetBus( void ) 
{
    /* Reset buffers */
    *pTxBufferIndex = 0;
    *pTxBufferSize = 0;
    *pRxBufferIndex = 0;
    *pRxBufferSize = 0;

    /* Reset the module */
    MAP_I2C_disableModule( module );

    /* Perform bus clear according to I2C-bus Specification and User Manual 
     * (UM10204) section 3.1.16 
     */
    if (this->isMaster( )) 
    {
        MAP_GPIO_setOutputLowOnPin( modulePort, moduleSCL );
        for (uint_fast8_t i = 0; i < 9; i++) 
        {
            MAP_GPIO_setAsOutputPin( modulePort, moduleSCL );
            this->_I2CDelay( );
            MAP_GPIO_setAsInputPin( modulePort, moduleSCL );
            this->_I2CDelay( );
        }
        MAP_GPIO_setAsPeripheralModuleFunctionInputPin( modulePort,
                moduleSCL, GPIO_PRIMARY_MODULE_FUNCTION );
    }

    /* Re-enable the module */
    MAP_I2C_enableModule( module );
}
예제 #4
0
파일: main.c 프로젝트: AriZuu/blink-test
void testInitIO()
{
  /*
   * Configure LED pins as output.
   */
  MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
  GPIO_setOutputHighOnPin(GPIO_PORT_P1, 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
}
예제 #6
0
//-----------------------------------------------------------------------
int RF_Init(void)
{
	int err = 0;

	//Setting RGB LED as output
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
	GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);
	GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);

	//Set P6.1 to be the pin interupt
	MAP_GPIO_setAsInputPin(GPIO_PORT_P6, GPIO_PIN1);
	MAP_GPIO_clearInterruptFlag(GPIO_PORT_P6, GPIO_PIN1);
	MAP_GPIO_enableInterrupt(GPIO_PORT_P6, GPIO_PIN1);

	//Enable the gpio interupt
	MAP_Interrupt_enableInterrupt(INT_PORT6);
	MAP_Interrupt_enableMaster();

    /* Initial values for nRF24L01+ library config variables */
    rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit
    rf_addr_width      = (uint8_t)PACKET_SIZE;
    rf_speed_power     = RF24_SPEED_MIN | RF24_POWER_MAX;
    rf_channel     	   = 120;

    msprf24_init();  // All RX pipes closed by default
    msprf24_set_pipe_packetsize(0, (uint8_t)PACKET_SIZE);
    msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs

    // Transmit to 'rad01' (0x72 0x61 0x64 0x30 0x31)
    msprf24_standby();
    user = msprf24_current_state();
    memcpy(addr, "\xDE\xAD\xBE\xEF\x01", 5);
//    addr[0] = 0xDE; addr[1] = 0xAD; addr[2] = 0xBE; addr[3] = 0xEF; addr[4] = 0x00;
    w_tx_addr(addr);
    w_rx_addr(0, addr);  // Pipe 0 receives auto-ack's, autoacks are sent back to the TX addr so the PTX node
                     // needs to listen to the TX addr on pipe#0 to receive them.
    msprf24_activate_rx();

	return err;
}
예제 #7
0
파일: Timers.c 프로젝트: AlexTunea23/msp432
void InitTimers(void)
{/* Configuring pins for peripheral/crystal HFXT*/
	    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
	            GPIO_PIN3 | GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION);

	    /* Configuring pins for peripheral/crystal LFXT*/
	    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
	            GPIO_PIN0 | GPIO_PIN1, GPIO_PRIMARY_MODULE_FUNCTION);
	//setSystemClock(CPU_FREQ);
	 //Configuring P1.0 and P1.5 as output */
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN5);
	MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN5);
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
	MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
	/* Configuring Timer_A1 and TimerA_0 for Up Mode */
	/* Enabling interrupts and starting the timer */


	MAP_Interrupt_enableSleepOnIsrExit();

	MAP_Interrupt_enableMaster();
}
예제 #8
0
/*
 *  ======== 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)
{
    uint32_t ii;

    /* Disabling the Watchdog  */
    MAP_WDT_A_holdTimer();
    xferIndex = 0;

    /* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function,
     *   (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL).
     */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
            GPIO_PIN6 + GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);

    /* Configuring GPIO P1.0 to be an input. As the GPIO is pulled up by the
     * master, when the port is set to an input the pull-up defaults and the
     * pin is high. When the interrupt is asserted, we set the GPIO to an
     * output low and cause the interrupt to occur.
     */
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN1);
    MAP_GPIO_setAsInputPin(GPIO_PORT_P1, GPIO_PIN0);

    /* eUSCI I2C Slave Configuration */
    MAP_I2C_initSlave(EUSCI_B0_MODULE, SLAVE_ADDRESS_1, EUSCI_B_I2C_OWN_ADDRESS_OFFSET0,
            EUSCI_B_I2C_OWN_ADDRESS_ENABLE);

    /* Enable the module and enable interrupts */
    MAP_I2C_enableModule(EUSCI_B0_MODULE);
    MAP_Interrupt_enableInterrupt(INT_EUSCIB0);

    /* Sleeping while not in use */
    while (1)
    {
        /* Delaying between transactions */
        for(ii=0;ii<4000;ii++);

        /* Initiating the read from the master by asserting our GPIO */
        MAP_I2C_enableInterrupt(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0);
        MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);

        MAP_Interrupt_enableSleepOnIsrExit();
        MAP_PCM_gotoLPM0InterruptSafe();
        
    }
}
예제 #10
0
파일: main.c 프로젝트: Eclo/FreeRTOS
static void prvSetupHardware( void )
{
extern void FPU_enableModule( void );
	
	/* The clocks are not configured here, but inside main_full() and
	main_blinky() as the full demo uses a fast clock and the blinky demo uses
	a slow clock. */

	/* Stop the watchdog timer. */
	MAP_WDT_A_holdTimer();
	
	/* Ensure the FPU is enabled. */
	FPU_enableModule();

	/* Selecting P1.2 and P1.3 in UART mode and P1.0 as output (LED) */
	MAP_GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION );
	MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 );
	MAP_GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 );
}
int main(void)
{
    volatile uint32_t ii;

    /* Halting the Watchdog */
    MAP_WDT_A_holdTimer();

    /* Configuring P1.0 as output */
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);

    while (1)
    {
        /* Delay Loop */
        for(ii=0;ii<5000;ii++)
        {
        }

        MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
    }
}
예제 #12
0
파일: main.c 프로젝트: howlanjo/Lab7_PRX
//------------------------------------------------------------------------------
int InitFunction(void)
{
	int err = NONE;

	MAP_WDT_A_holdTimer();

	/* Configuring P6.7 as an input. P1.0 as output and enabling interrupts */
//	MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
	//Setting RGB LED as output
	MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2);

	//Set P6.1 to be the pin interupt
	MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P6, GPIO_PIN1);
	MAP_GPIO_clearInterruptFlag(GPIO_PORT_P6, GPIO_PIN1);
	MAP_GPIO_enableInterrupt(GPIO_PORT_P6, GPIO_PIN1);
	MAP_Interrupt_enableInterrupt(INT_PORT6);

	MAP_Interrupt_enableMaster();

	return err;
}
예제 #13
0
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
예제 #14
0
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