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();
    }
}
int main(void)
{
    /* Halting WDT  */
    MAP_WDT_A_holdTimer();

    /* Selecting P1.2 and P1.3 in UART mode */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
            GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);

    /* Setting DCO to 12MHz */
    CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);

    /* 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();
    MAP_Interrupt_enableMaster();   

    while(1)
    {
        MAP_PCM_gotoLPM0();
    }
}
int main(void)
{
    /* Halting WDT  */
    MAP_WDT_A_holdTimer();
    MAP_Interrupt_enableSleepOnIsrExit();
    resPos = 0;

    /* Setting up clocks
     * MCLK = MCLK = 3MHz
     * ACLK = REFO/4 = 32Khz */
    MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);

    /* Initializing ADC (MCLK/1/1) */
    MAP_ADC14_enableModule();
    MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,
            0);

    /* Configuring GPIOs (5.5 A0) */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5,
    GPIO_TERTIARY_MODULE_FUNCTION);

    /* Configuring ADC Memory */
    MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true);
    MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,
    ADC_INPUT_A0, false);

    /* Configuring Timer_A in continuous mode and sourced from ACLK */
    MAP_Timer_A_configureContinuousMode(TIMER_A0_MODULE, &continuousModeConfig);

    /* Configuring Timer_A0 in CCR1 to trigger at 16000 (0.5s) */
    MAP_Timer_A_initCompare(TIMER_A0_MODULE, &compareConfig);

    /* Configuring the sample trigger to be sourced from Timer_A0  and setting it
     * to automatic iteration after it is triggered*/
    MAP_ADC14_setSampleHoldTrigger(ADC_TRIGGER_SOURCE1, false);

    /* Enabling the interrupt when a conversion on channel 1 is complete and
     * enabling conversions */
    MAP_ADC14_enableInterrupt(ADC_INT0);
    MAP_ADC14_enableConversion();

    /* Enabling Interrupts */
    MAP_Interrupt_enableInterrupt(INT_ADC14);
    MAP_Interrupt_enableMaster();

    /* Starting the Timer */
    MAP_Timer_A_startCounter(TIMER_A0_MODULE, TIMER_A_CONTINUOUS_MODE);

    /* Going to sleep */
    while (1)
    {
        MAP_PCM_gotoLPM0();
    }
}
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();
        
    }
}
int main(void)
{
    /* Disabling the Watchdog */
    MAP_WDT_A_holdTimer();
    xferIndex_0 = 0;
    xferIndex_1 = 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);

    /* eUSCI I2C Slave Configuration */

    /* Slave Address 1 (0x48) */
    MAP_I2C_initSlave(EUSCI_B0_MODULE, SLAVE_ADDRESS_1,
            EUSCI_B_I2C_OWN_ADDRESS_OFFSET0,
            EUSCI_B_I2C_OWN_ADDRESS_ENABLE);

    /* Slave Address 1 (0x49) */
    MAP_I2C_initSlave(EUSCI_B0_MODULE, SLAVE_ADDRESS_2,
            EUSCI_B_I2C_OWN_ADDRESS_OFFSET1,
            EUSCI_B_I2C_OWN_ADDRESS_ENABLE);

    /* Set in receive mode */
    MAP_I2C_setMode(EUSCI_B0_MODULE, EUSCI_B_I2C_RECEIVE_MODE);

    /* Enable the module and enable interrupts */
    MAP_I2C_enableModule(EUSCI_B0_MODULE);
    MAP_I2C_clearInterruptFlag(EUSCI_B0_MODULE,
    EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_RECEIVE_INTERRUPT1);
    MAP_I2C_enableInterrupt(EUSCI_B0_MODULE,
        EUSCI_B_I2C_RECEIVE_INTERRUPT0 | EUSCI_B_I2C_RECEIVE_INTERRUPT1);
    MAP_Interrupt_enableSleepOnIsrExit();
    MAP_Interrupt_enableInterrupt(INT_EUSCIB0);
    MAP_Interrupt_enableMaster();

    /* Sleeping while not in use */
    while (1)
    {
        MAP_PCM_gotoLPM0();
    }
}
Beispiel #6
0
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();
}
int main(void)
{
    volatile uint32_t ii;

    /* Disabling the Watchdog */
    MAP_WDT_A_holdTimer();

    /* 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);
    sendStopCondition = false;
    sendToSlaveAddress2 = false;

    /* Initializing I2C Master to SMCLK at 400kbs with no autostop */
    MAP_I2C_initMaster(EUSCI_B0_MODULE, &i2cConfig);

    /* Specify slave address. For start we will do our first slave address */
    MAP_I2C_setSlaveAddress(EUSCI_B0_MODULE, SLAVE_ADDRESS_1);

    /* Set Master in receive mode */
    MAP_I2C_setMode(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_MODE);

    /* Enable I2C Module to start operations */
    MAP_I2C_enableModule(EUSCI_B0_MODULE);

    /* Enable and clear the interrupt flag */
    MAP_I2C_clearInterruptFlag(EUSCI_B0_MODULE,
            EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);

    //Enable master Receive interrupt
    MAP_I2C_enableInterrupt(EUSCI_B0_MODULE,
            EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);
    MAP_Interrupt_enableInterrupt(INT_EUSCIB0);
    
    while (1)
    {

        /* Load Byte Counter */
        TXByteCtr = 4;

        /* Making sure the last transaction has been completely sent out */
        while (MAP_I2C_masterIsStopSent(EUSCI_B0_MODULE) == EUSCI_B_I2C_SENDING_STOP);

        /* Sending the initial start condition for appropriate
         *   slave addresses */
        if(sendToSlaveAddress2)
        {
            MAP_I2C_setSlaveAddress(EUSCI_B0_MODULE, SLAVE_ADDRESS_2);
        }
        else
        {
            MAP_I2C_setSlaveAddress(EUSCI_B0_MODULE, SLAVE_ADDRESS_1);
        }

        MAP_I2C_masterSendMultiByteStart(EUSCI_B0_MODULE, TXData++);

        while(sendStopCondition == false)
        {
            /* Go to sleep while data is being transmitted */
            MAP_Interrupt_enableSleepOnIsrExit();
            MAP_PCM_gotoLPM0InterruptSafe();
        }

        sendStopCondition = false;
    }
}