Esempio n. 1
0
void msp430_spi_a0_init()
{
    /**Configure Pins for SPI
     * Set P2.7, P3.3 and P3.4 as Secondary Module Function.
     * */
    GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P2,
        GPIO_PIN7
    );
    GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P3,
        GPIO_PIN3 + GPIO_PIN4
    );
    //Initialize Master
    USCI_A_SPI_initMasterParam param = {0};
    param.selectClockSource = USCI_A_SPI_CLOCKSOURCE_SMCLK;
    param.clockSourceFrequency = UCS_getSMCLK();
    param.desiredSpiClock = 8000000;
    param.msbFirst = USCI_A_SPI_MSB_FIRST;
    param.clockPhase = USCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT;
    param.clockPolarity = USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW;
    USCI_A_SPI_initMaster(USCI_A0_BASE, &param);

    //Enable SPI module
    USCI_A_SPI_enable(USCI_A0_BASE);

    //Enable Receive interrupt
    USCI_A_SPI_clearInterrupt(USCI_A0_BASE,
                              USCI_A_SPI_RECEIVE_INTERRUPT);
    USCI_A_SPI_enableInterrupt(USCI_A0_BASE,
                               USCI_A_SPI_RECEIVE_INTERRUPT);
}
Esempio n. 2
0
t_uint8 _Device_Uart_Module_1_Enable(t_uint32 baud_rate){

    //setUSCI_X TXD
    GPIO_setAsPeripheralModuleFunctionInputPin( USART_Module_1_TX_PORT, USART_Module_1_TX_PIN );
    //setUSCI_X RXD
    GPIO_setAsPeripheralModuleFunctionInputPin( USART_Module_1_RX_PORT, USART_Module_1_RX_PIN );

    if ( STATUS_FAIL == USCI_A_UART_init(UART_Module_1_USCI_A_BASEADDRESS,
             USCI_A_UART_CLOCKSOURCE_SMCLK,
             UCS_getSMCLK(UCS_BASE),
             baud_rate,
             USCI_A_UART_NO_PARITY,
             USCI_A_UART_LSB_FIRST,
             USCI_A_UART_ONE_STOP_BIT,
             USCI_A_UART_MODE,
             USCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION )){
        return Func_Failure;
    }

    //Enable UART module for operation
    USCI_A_UART_enable(UART_Module_1_USCI_A_BASEADDRESS);

    //Enable Receive Interrupt
	USCI_A_UART_clearInterruptFlag(UART_Module_1_USCI_A_BASEADDRESS, USCI_A_UART_RECEIVE_INTERRUPT);
    USCI_A_UART_enableInterrupt(UART_Module_1_USCI_A_BASEADDRESS, USCI_A_UART_RECEIVE_INTERRUPT);


    //Enter LPM3, interrupts enabled
    //__bis_SR_register(LPM3_bits + GIE);
    __no_operation();
    Interrupt_UART_ReceiveData_ptr_fuc = Empty_UART_fun;
    SendingWhileTimeOutCount = 0;

    return Func_Success;
}
/*
 *  ======== MSP_EXP430F5529LP_initUART ======== */
void MSP_EXP430F5529LP_initUART(void)
{
    /* P4.4,5 = USCI_A1 TXD/RXD */
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P4,
                                               GPIO_PIN4 | GPIO_PIN5);

    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3,
                                               GPIO_PIN3 | GPIO_PIN4);

    /* Initialize the UART driver */
    UART_init();
}
Esempio n. 4
0
/**********************************************************************//**
 * @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
}
Esempio n. 5
0
void main (void)
{
    //Stop WDT
    WDT_hold(__MSP430_BASEADDRESS_WDT_A__);

    //P3.4,5 = USCI_A0 TXD/RXD
    GPIO_setAsPeripheralModuleFunctionInputPin(__MSP430_BASEADDRESS_PORT3_R__,
        GPIO_PORT_P3,
        GPIO_PIN4 + GPIO_PIN5
        );

    //Initialize USCI UART module
    if ( STATUS_FAIL == UART_init(__MSP430_BASEADDRESS_USCI_A0__,
             UART_CLOCKSOURCE_SMCLK,
             UCS_getSMCLK(__MSP430_BASEADDRESS_UCS__),
             BAUD_RATE,
             UART_NO_PARITY,
             UART_LSB_FIRST,
             UART_ONE_STOP_BIT,
             UART_MODE,
             UART_OVERSAMPLING_BAUDRATE_GENERATION
             )){
        return;
    }

    //Enable UART module for operation
    UART_enable(__MSP430_BASEADDRESS_USCI_A0__);

    //Enable Receive Interrupt
    UART_enableInterrupt(__MSP430_BASEADDRESS_USCI_A0__, UART_RECEIVE_INTERRUPT);

    //Enter LPM3, interrupts enabled
    __bis_SR_register(LPM3_bits + GIE);
    __no_operation();
}
/*
 *  ======== 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();
}
Esempio n. 7
0
void WheelADC_init()
{
	//	--------初始化ADC12--------
		GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,
					GPIO_PIN4);
		ADC12_A_init(ADC12_A_BASE,				// 初始化ADC12,
				ADC12_A_SAMPLEHOLDSOURCE_SC,
				ADC12_A_CLOCKSOURCE_ADC12OSC,
				ADC12_A_CLOCKDIVIDER_1);
		ADC12_A_enable(ADC12_A_BASE);			// 打开ADC12
		ADC12_A_setupSamplingTimer(ADC12_A_BASE,// 建立采样定时器控制采样保持时间,16个clock
				ADC12_A_CYCLEHOLD_64_CYCLES,
				ADC12_A_CYCLEHOLD_4_CYCLES,
				ADC12_A_MULTIPLESAMPLESDISABLE);
		ADC12_A_memoryConfigure(ADC12_A_BASE,
				ADC12_A_MEMORY_0,
				ADC12_A_INPUT_A4,
				ADC12_A_VREFPOS_AVCC,				// VREF+ = AVCC
				ADC12_A_VREFNEG_AVSS,				// VREF- = AVSS
				ADC12_A_ENDOFSEQUENCE);
		//Enable memory buffer 0 interrupt
		ADC12_A_clearInterrupt(ADC12_A_BASE,
				ADC12_A_IFG0);
		ADC12_A_enableInterrupt(ADC12_A_BASE,
		        ADC12IE0);
		 __delay_cycles(75);
}
Esempio n. 8
0
File: main.c Progetto: HclX/freertos
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 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
}
Esempio n. 10
0
void InitUart(uint32_t uartModuleBaseAdress,uint8_t uartPort,uint8_t pin1Uart,uint8_t pin2Uart,uint8_t pin3Uart,
		eUSCI_UART_Config uartConfiguration,uint8_t primaryModuleFunction)
{
	/* Selecting P1.2 and P1.3 in UART mode */
			    GPIO_setAsPeripheralModuleFunctionInputPin(uartPort,
			    		pin1Uart | pin2Uart | pin3Uart, primaryModuleFunction);
			    /* Setting DCO to 12MHz */
			    CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);
			    /* Configuring UART Module */
			    UART_initModule(uartModuleBaseAdress, &uartConfiguration);
			    /* Enable UART module */
			    UART_enableModule(uartModuleBaseAdress);
}
Esempio n. 11
0
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int spi_Open(void)
{
	GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,
			GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION);

    /* Configuring SPI in 3wire master mode */
	SPI_initMaster(EUSCI_B1_MODULE, &LIGHTspiConfig);

	/* Enable SPI module */
	SPI_enableModule(EUSCI_B1_MODULE);

    return 0;//NONOS_RET_OK;
}
/*
 *  ======== MSP_EXP430F5529LP_initI2C ========
 */
void MSP_EXP430F5529LP_initI2C(void)
{
    /*
     * 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_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P3,
        GPIO_PIN0 | GPIO_PIN1);

    I2C_init();
}
void main (void)
{
    //Stop WDT
    WDT_hold(__MSP430_BASEADDRESS_WDT_A__);

    //Assign I2C pins to USCI_B0
    GPIO_setAsPeripheralModuleFunctionInputPin(__MSP430_BASEADDRESS_PORT3_R__,
        GPIO_PORT_P3,
        GPIO_PIN1 + GPIO_PIN2
        );

    //Initialize Master
    I2C_masterInit(__MSP430_BASEADDRESS_USCI_B0__,
        I2C_CLOCKSOURCE_SMCLK,
        UCS_getSMCLK(__MSP430_BASEADDRESS_UCS__),
        I2C_SET_DATA_RATE_400KBPS
        );

    //Specify slave address
    I2C_setSlaveAddress(__MSP430_BASEADDRESS_USCI_B0__,
        SLAVE_ADDRESS
        );

    //Set Master in receive mode
    I2C_setMode(__MSP430_BASEADDRESS_USCI_B0__,
        I2C_RECEIVE_MODE
        );

    //Enable I2C Module to start operations
    I2C_enable(__MSP430_BASEADDRESS_USCI_B0__);

    //Enable master Receive interrupt
    I2C_enableInterrupt(__MSP430_BASEADDRESS_USCI_B0__,
        I2C_RECEIVE_INTERRUPT
        );

    while (1)
    {
        //Initiate command to receive a single character from Slave
        I2C_masterSingleReceiveStart(__MSP430_BASEADDRESS_USCI_B0__);

        //Enter low power mode 0 with interrupts enabled.
        //Wait until character is received.
        __bis_SR_register(LPM0_bits + GIE);
        __no_operation();
    }
}
Esempio n. 14
0
////------------------------------------------------------------------------------
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;
}
void msp430_i2c_init(void)
{
	unsigned long _smclk;
    if (i2c.enabled)
        return;
    /**Configure Pins for I2C
     * Set P3.0 and P3.1 as Secondary Module Function Input.
     * Select Port 3
     * Set Pin 0, 1 to input Secondary Module Function, (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL).
     * */
    GPIO_setAsPeripheralModuleFunctionInputPin(
            GPIO_PORT_P3,
            GPIO_PIN0 + GPIO_PIN1
            );
    _smclk = msp430_get_smclk_freq();
    USCI_B_I2C_initMasterParam param = {0};
    param.selectClockSource = USCI_B_I2C_CLOCKSOURCE_SMCLK;
    param.i2cClk = _smclk;
    param.dataRate = USCI_B_I2C_SET_DATA_RATE_400KBPS;
    USCI_B_I2C_initMaster(USCI_B0_BASE, &param);
    //Enable I2C Module to start operations
    USCI_B_I2C_enable(USCI_B0_BASE);

    USCI_B_I2C_clearInterrupt(USCI_B0_BASE,
            USCI_B_I2C_TRANSMIT_INTERRUPT +
            USCI_B_I2C_RECEIVE_INTERRUPT +
            USCI_B_I2C_NAK_INTERRUPT
            );
    //Enable master Receive interrupt
    USCI_B_I2C_enableInterrupt(USCI_B0_BASE,
            USCI_B_I2C_TRANSMIT_INTERRUPT +
            USCI_B_I2C_RECEIVE_INTERRUPT +
            USCI_B_I2C_NAK_INTERRUPT
            );

    /* Initialize struct. */
    i2c.state = STATE_WAITING;
    i2c.slave_reg = 0;
    i2c.data = 0;
    i2c.length = 0;
    i2c.enabled = 1;
}
Esempio n. 16
0
/*P3.4 P3.5 上位机通信*/
int UartPCInit(void){

	GPIO_setAsPeripheralModuleFunctionInputPin(
		GPIO_PORT_P3,
		GPIO_PIN4 + GPIO_PIN5
		);

	//Initialize UART module in auto baudrate detection multiprocessor mode
	//Baudrate = 9600, clock freq = 1.048MHz
	//UCBRx = 6, UCBRFx = 13, UCBRSx = 0, UCOS16 = 1
	USCI_A_UART_initParam param = {0};
	param.selectClockSource = USCI_A_UART_CLOCKSOURCE_SMCLK;
	param.clockPrescalar = 6;
	param.firstModReg = 13;
	param.secondModReg = 0;
	param.parity = USCI_A_UART_NO_PARITY;
	param.msborLsbFirst = USCI_A_UART_LSB_FIRST;
	param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT;
	param.uartMode = USCI_A_UART_AUTOMATIC_BAUDRATE_DETECTION_MODE;
	param.overSampling = USCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
	if(STATUS_FAIL == USCI_A_UART_init(USCI_A0_BASE, &param))
	{
		return 0;
	}

	//Enable UART module for operation
	USCI_A_UART_enable(USCI_A0_BASE);

	//Put UART to sleep/dormant mode toreceive break/sync first
//	USCI_A_UART_setDormant(USCI_A0_BASE);
//    Transmit Break
    USCI_A_UART_transmitBreak(USCI_A0_BASE);

//	Wait till ,odule is ready to transmit again
	//Enable Receive Interrupt
    //不使能
//	USCI_A_UART_clearInterrupt(USCI_A0_BASE,
//							   USCI_A_UART_RECEIVE_INTERRUPT);
//	USCI_A_UART_enableInterrupt(USCI_A0_BASE,
//								USCI_A_UART_RECEIVE_INTERRUPT);
	return 1;
}
/*
 *  ======== 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();
}
Esempio n. 18
0
void main (void)
{
    //Stop watchdog timer
    WDT_hold(__MSP430_BASEADDRESS_WDT_A__);

    //If clock signal from master stays low, it is not yet in SPI mode
    while ( GPIO_INPUT_PIN_LOW ==
            GPIO_getInputPinValue(__MSP430_BASEADDRESS_PORT3_R__,
                GPIO_PORT_P3,
                GPIO_PIN0
                )) ;

    //P3.5,4,0 option select
    GPIO_setAsPeripheralModuleFunctionInputPin(__MSP430_BASEADDRESS_PORT3_R__,
        GPIO_PORT_P3,
        GPIO_PIN0 + GPIO_PIN4 + GPIO_PIN5
        );

    //Initialize slave to MSB first, inactive high clock polarity and 3 wire SPI
    returnValue = SPI_slaveInit(__MSP430_BASEADDRESS_USCI_A0__,
        SPI_MSB_FIRST,
        SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT,
        SPI_CLOCKPOLARITY_INACTIVITY_HIGH
        );

    if (STATUS_FAIL == returnValue){
        return;
    }

    //Enable SPI Module
    SPI_enable(__MSP430_BASEADDRESS_USCI_A0__);

    //Enable Receive interrupt
    SPI_enableInterrupt(__MSP430_BASEADDRESS_USCI_A0__,
        SPI_RECEIVE_INTERRUPT
        );

    //Enter LPM4, enable interrupts
    __bis_SR_register(LPM4_bits + GIE);
}
void msp430_uart_init(unsigned long baud)
{
	unsigned long divider;
	unsigned long _smclk;

	_smclk = msp430_get_smclk_freq();

    /**Configure UART pins
     * Set P4.4 and P4.5 as Secondary Module Function Input.
     * Select Port 4
     * Set Pin 4, 5 to input Secondary Module Function, (UCA1TXD/UCA1SIMO, UCA1RXD/UCA1SOMI).
     **/
    GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P4,
        GPIO_PIN4 + GPIO_PIN5
        );

    divider=(_smclk<<3)/baud;   //fixed-point number: q3

    // Configure UART
    USCI_A_UART_initParam param = {0};
    param.selectClockSource = USCI_A_UART_CLOCKSOURCE_SMCLK;
    param.clockPrescalar = divider>>3;
    param.firstModReg = 0;
    param.secondModReg = (divider & 0x07);
    param.parity = USCI_A_UART_NO_PARITY;
    param.msborLsbFirst = USCI_A_UART_LSB_FIRST;
    param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT;
    param.uartMode = USCI_A_UART_MODE;
    param.overSampling = USCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;

    USCI_A_UART_init(USCI_A1_BASE, &param);
    USCI_A_UART_enable(USCI_A1_BASE);
    USCI_A_UART_clearInterrupt(USCI_A1_BASE,
    		                   USCI_A_UART_RECEIVE_INTERRUPT_FLAG);

    // Enable USCI_A1 RX interrupt
    USCI_A_UART_enableInterrupt(USCI_A1_BASE,
    		                    USCI_A_UART_RECEIVE_INTERRUPT); // Enable interrupt
}
int main(void)
{
    /* Halting WDT */
    WDT_A_holdTimer();
    Interrupt_enableSleepOnIsrExit();
    
    /* Initializing ADC (MCLK/1/1) */
    ADC14_enableModule();
    ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,
            0);

    /* Configuring ADC Memory (ADC_MEM0 A0/A1 Differential) in repeat mode
     * with use of external references */
    ADC14_configureSingleSampleMode(ADC_MEM0, true);
    ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_EXTPOS_VREFNEG_EXTNEG,
            ADC_INPUT_A0, true);

    /* Setting up GPIO pins as analog inputs (and references) */
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,
            GPIO_PIN6 | GPIO_PIN5 | GPIO_PIN4, GPIO_TERTIARY_MODULE_FUNCTION);

    /* Enabling sample timer in auto iteration mode and interrupts*/
    ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION);
    ADC14_enableInterrupt(ADC_INT0);

    /* Enabling Interrupts */
    Interrupt_enableInterrupt(INT_ADC14);
    Interrupt_enableMaster();

    /* Triggering the start of the sample */
    ADC14_enableConversion();
    ADC14_toggleConversionTrigger();

    /* Going to sleep */
    while (1)
    {
        PCM_gotoLPM0();
    }
}
Esempio n. 21
0
void Board_init(void)
{
    // Setup XT1 and XT2
  GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P5,
        GPIO_PIN2 + GPIO_PIN3 + 
        GPIO_PIN4 + GPIO_PIN5
          );

   GPIO_setOutputLowOnPin(
        GPIO_PORT_P1,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + 
        GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5
        );
   
    // Configure LED ports
    GPIO_setAsOutputPin(
        GPIO_PORT_P1,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + 
        GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5
        );
    
    GPIO_setOutputLowOnPin(
        GPIO_PORT_P8,
        GPIO_PIN1 + GPIO_PIN2
        );
    
    GPIO_setAsOutputPin(
        GPIO_PORT_P8,
        GPIO_PIN1 + GPIO_PIN2
        );
    
    // Configure button ports
    // Buttons on P1.7/P2.2 are inputs
    GPIO_setAsInputPin(
        GPIO_PORT_PA,
        GPIO_PIN7 + GPIO_PIN10
        );

    // Configure CapTouch ports
    GPIO_setOutputLowOnPin(
        GPIO_PORT_P1,
        GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + 
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6
        );
    GPIO_setAsOutputPin(
        GPIO_PORT_P1,
        GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + 
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6
        );
    
    GPIO_setOutputLowOnPin(
        GPIO_PORT_P6,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + 
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7
        );
    GPIO_setAsInputPin(
        GPIO_PORT_P6,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 + 
        GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7
        );

    // Configure Cma3000 ports
    // ACCEL_INT pin is input
    GPIO_setAsInputPin(
        GPIO_PORT_P2,
        GPIO_PIN5
        );
    
    // SCK
    GPIO_setOutputLowOnPin(
        GPIO_PORT_P2,
        GPIO_PIN7
        );
    GPIO_setAsOutputPin(
        GPIO_PORT_P2,
        GPIO_PIN7
        );
    
    // ACCEL_SIMO, ACCEL_CS, ACCEL_PWR to low
    GPIO_setOutputLowOnPin(
        GPIO_PORT_P3,
        GPIO_PIN3 + GPIO_PIN5 + GPIO_PIN6
        );
    
    // ACCEL_SOMI pin is input
    GPIO_setAsInputPin(
        GPIO_PORT_P3,
        GPIO_PIN4
        );
    
    // ACCEL_SIMO, ACCEL_CS, ACCEL_PWR as outp
    GPIO_setAsOutputPin(
        GPIO_PORT_P3,
        GPIO_PIN3 + GPIO_PIN5 + GPIO_PIN6
        );

    // Configure Dogs102x6 ports
    // LCD_C/D, LCD_RST
    GPIO_setOutputLowOnPin(
        GPIO_PORT_P5,
        GPIO_PIN6 + GPIO_PIN7
        );

    GPIO_setAsOutputPin(
        GPIO_PORT_P5,
        GPIO_PIN6 + GPIO_PIN7
        );
    
    // LCD_CS, LCD_BL_EN
    GPIO_setOutputLowOnPin(
        GPIO_PORT_P7,
        GPIO_PIN4 + GPIO_PIN6
        );
   
    GPIO_setAsOutputPin(
        GPIO_PORT_P7,
        GPIO_PIN4 + GPIO_PIN6
        );
    
    // SIMO, SCK
    GPIO_setOutputLowOnPin(
        GPIO_PORT_P4,
        GPIO_PIN1 + GPIO_PIN3
        );
    
    // SOMI pin is input
    GPIO_setAsInputPin(
        GPIO_PORT_P4,
        GPIO_PIN2
        );
    
    GPIO_setAsOutputPin(
        GPIO_PORT_P4,
        GPIO_PIN1 + GPIO_PIN3 
        );


    // Configure SDCard ports
    // SD_CS to high
    GPIO_setOutputHighOnPin(
        GPIO_PORT_P3,
        GPIO_PIN7
        );
    GPIO_setAsOutputPin(
        GPIO_PORT_P3,
        GPIO_PIN7
        );

    // Configure Wheel ports
    // A5 ADC input
    GPIO_setAsInputPin(
        GPIO_PORT_P6,
        GPIO_PIN5
        );
    
    // POT_PWR
    GPIO_setOutputLowOnPin(
        GPIO_PORT_P8,
        GPIO_PIN0
        );
    GPIO_setAsOutputPin(
        GPIO_PORT_P8,
        GPIO_PIN0
        );

    // Configure unused ports for low power
    GPIO_setOutputLowOnPin(
        GPIO_PORT_P2,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN3 + 
        GPIO_PIN4 + GPIO_PIN6
        );
    GPIO_setAsOutputPin(
        GPIO_PORT_P2,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN3 + 
        GPIO_PIN4 + GPIO_PIN6
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_P3,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2
        );
    GPIO_setAsOutputPin(
        GPIO_PORT_P3,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_P4,
        GPIO_PIN0 + GPIO_PIN6 + GPIO_PIN7
        );
    GPIO_setAsOutputPin(
        GPIO_PORT_P4,
        GPIO_PIN0 + GPIO_PIN6 + GPIO_PIN7
        );
    

    GPIO_setOutputLowOnPin(
        GPIO_PORT_P5,
        GPIO_PIN1
        );
    GPIO_setAsOutputPin(
        GPIO_PORT_P5,
        GPIO_PIN1
        );

    GPIO_setOutputLowOnPin(
        GPIO_PORT_P6,
        GPIO_PIN6 + GPIO_PIN7
        );
    GPIO_setAsOutputPin(
        GPIO_PORT_P6,
        GPIO_PIN6 + GPIO_PIN7
        );

   GPIO_setOutputLowOnPin(
        GPIO_PORT_P7,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + 
        GPIO_PIN3 + GPIO_PIN5+ GPIO_PIN7
        );
    GPIO_setAsOutputPin(
        GPIO_PORT_P7,
        GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + 
        GPIO_PIN3 + GPIO_PIN5+ GPIO_PIN7
        );
}
Esempio n. 22
0
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
	);
}
Esempio n. 23
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
Esempio n. 24
0
void clock_init(clock_speed_t speed) {
  // Turn on XT1 crystal
#ifndef USE_DRIVERLIB
  P5SEL |= BIT4;

  UCSCTL6 |= XCAP_3;                          // Internal load cap of 12pF

  do {                                        // Wait until XT1 stabilizes
    UCSCTL7 &= ~(XT1LFOFFG + DCOFFG);         // Clear XT1 fault flag
                                              //
                                              // The DCO fault flag is also cleared,
                                              // since it is supposed to be faulty at startup
                                              // and thus OFIFG will continue to be set unless
                                              // we clear it...
    SFRIFG1 &= ~OFIFG;                        // Clear oscillator fault flag
  }  while (SFRIFG1 & OFIFG);                 // Re-test oscillator fault flag

  UCSCTL6 &= ~XT1DRIVE_3;                     // Decrease XT1 drive as it is stabilized
#else
  GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN4);
  UCS_turnOnLFXT1(XT1DRIVE_0, UCS_XCAP_3);
#endif

  // Set the FLL reference select to XT1 (external 32KHz clock),
  // and set the FLL reference divider to 1
#ifndef USE_DRIVERLIB
  UCSCTL3 = SELREF__XT1CLK | FLLREFDIV_0;

  // Set the MCLK source to DCOCLKDIV
  UCSCTL4 = (UCSCTL4 & ~SELM_7) | SELM__DCOCLKDIV;

  // Set the SMCLK source to DCOCLKDIV
  UCSCTL4 = (UCSCTL4 & ~SELS_7) | SELS__DCOCLKDIV;
#else
  UCS_initClockSignal(
       UCS_FLLREF,
       UCS_XT1CLK_SELECT,
       UCS_CLOCK_DIVIDER_1);
#endif

  // Initialize the FLL
#ifndef USE_DRIVERLIB
  __bis_SR_register(SCG0);    // Disable the FLL control loop

  UCSCTL0 = 0x0000;           // Set lowest possible DCOx, MODx

  uint16_t ratio;
  switch (speed) {
    case CLKSPEED_16MHZ:
      clock_speed = 16000000;

      ratio = clock_speed/XT1_FREQ;

      UCSCTL1 = DCORSEL_6;
      UCSCTL2 = FLLD_1 | (ratio - 1); // FLLD doesn't really matter, since we feed MCLK and SMCLK off DCOCLKDIV and not DCOCLK
      break;
    case CLKSPEED_1MHZ:
      clock_speed = 1000000;

      ratio = clock_speed/XT1_FREQ;

      UCSCTL1 = DCORSEL_2;
      UCSCTL2 = FLLD_1 | (ratio - 1); // FLLD doesn't really matter, since we feed MCLK and SMCLK off DCOCLKDIV and not DCOCLK
      break;
  }

  __bic_SR_register(SCG0);    // Enable the FLL control loop

  do {                                      // Wait until DCO stabilizes
    UCSCTL7 &= ~(DCOFFG);                     // Clear DCO fault flag
    SFRIFG1 &= ~OFIFG;                        // Clear oscillator fault flag
  }  while (SFRIFG1 & OFIFG);                 // Re-test oscillator fault flag

  // Worst-case settling time for the DCO when the DCO range bits have been
  // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
  // UG for optimization.
  while (ratio--)
    __delay_cycles(32*32);
#else
  switch (speed) {
    case CLKSPEED_16MHZ:
      clock_speed = 16000000;
      break;
    case CLKSPEED_1MHZ:
      clock_speed = 1000000;
      break;
  }

  UCS_initFLLSettle(clock_speed/1000, clock_speed/XT1_FREQ);
#endif
}
Esempio n. 25
0
void InitReservoirLevelPins(){
	GPIO_setAsPeripheralModuleFunctionInputPin( SENSOR_LEVEL_PORT, SENSOR_LEVEL_PIN );
}
/*
@@********************* 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;
}
void main(void)
{
    //Stop Watchdog Timer
    WDT_A_hold(WDT_A_BASE);

       PowerLevel_3();
   Clk_MCLK_24M_SMCLK_3M_ACLK_32768Hz();
    //Enable A/D channel inputs
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,
                                               GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 +
                                               GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 +
                                               GPIO_PIN6 + GPIO_PIN7
                                               );

    //Initialize the ADC12_A Module
    /*
     * Base address of ADC12_A Module
     * Use internal ADC12_A bit as sample/hold signal to start conversion
     * USE MODOSC 5MHZ Digital Oscillator as clock source
     * Use default clock divider of 1
     */
    ADC12_A_init(ADC12_A_BASE,
                 ADC12_A_SAMPLEHOLDSOURCE_SC,
                 ADC12_A_CLOCKSOURCE_ADC12OSC,
                 ADC12_A_CLOCKDIVIDER_1
                 );

    ADC12_A_enable(ADC12_A_BASE);

    /*
     * Base address of ADC12_A Module
     * For memory buffers 0-7 sample/hold for 256 clock cycles
     * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
     * Enable Multiple Sampling
     */
    ADC12_A_setupSamplingTimer(ADC12_A_BASE,
                               ADC12_A_CYCLEHOLD_256_CYCLES,
                               ADC12_A_CYCLEHOLD_4_CYCLES,
                               ADC12_A_MULTIPLESAMPLESENABLE);

    //Configure Memory Buffers
    /*
     * Base address of the ADC12_A Module
     * Configure memory buffer 0
     * Map input A0 to memory buffer 0
     * Vref+ = AVcc
     * Vref- = AVss
     * Memory buffer 0 is not the end of a sequence
     */
    ADC12_A_configureMemoryParam param0 = {0};
    param0.memoryBufferControlIndex = ADC12_A_MEMORY_0;
    param0.inputSourceSelect = ADC12_A_INPUT_A0;
    param0.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    param0.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    param0.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
    ADC12_A_configureMemory(ADC12_A_BASE,&param0);

    /*
     * Base address of the ADC12_A Module
     * Configure memory buffer 1
     * Map input A1 to memory buffer 1
     * Vref+ = AVcc
     * Vref- = AVss
     * Memory buffer 1 is not the end of a sequence
     *
     */
    ADC12_A_configureMemoryParam param1 = {0};
    param1.memoryBufferControlIndex = ADC12_A_MEMORY_1;
    param1.inputSourceSelect = ADC12_A_INPUT_A1;
    param1.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    param1.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    param1.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
    ADC12_A_configureMemory(ADC12_A_BASE,&param1);
    /*
     * Base address of the ADC12_A Module
     * Configure memory buffer 2
     * Map input A2 to memory buffer 2
     * Vref+ = AVcc
     * Vref- = AVss
     * Memory buffer 2 is not the end of a sequence
     */
    ADC12_A_configureMemoryParam param2 = {0};
    param2.memoryBufferControlIndex = ADC12_A_MEMORY_2;
    param2.inputSourceSelect = ADC12_A_INPUT_A2;
    param2.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    param2.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    param2.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
    ADC12_A_configureMemory(ADC12_A_BASE,&param2);
    /*
     * Base address of the ADC12_A Module
     * Configure memory buffer 3
     * Map input A3 to memory buffer 3
     * Vr+ = AVcc
     * Vr- = AVss
     * Memory buffer 3 IS the end of a sequence
     */
    ADC12_A_configureMemoryParam param3 = {0};
    param3.memoryBufferControlIndex = ADC12_A_MEMORY_3;
    param3.inputSourceSelect = ADC12_A_INPUT_A3;
    param3.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    param3.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    param3.endOfSequence = ADC12_A_ENDOFSEQUENCE;
    ADC12_A_configureMemory(ADC12_A_BASE,&param3);

    //Enable memory buffer 3 interrupt
    ADC12_A_clearInterrupt(ADC12_A_BASE,
                           ADC12IFG3);
    ADC12_A_enableInterrupt(ADC12_A_BASE,
                            ADC12IE3);

    //Enable/Start first sampling and conversion cycle
    /*
     * Base address of ADC12_A Module
     * Start the conversion into memory buffer 0
     * Use the repeated sequence of channels
     */
    ADC12_A_startConversion(ADC12_A_BASE,
                            ADC12_A_MEMORY_0,
                            ADC12_A_REPEATED_SEQOFCHANNELS);

    //Enter LPM0, Enable interrupts
    __bis_SR_register(LPM0_bits + GIE);
    //For debugger
    __no_operation();
}
Esempio n. 28
0
 static inline void _uart0_gpio_init(void){
     GPIO_setAsPeripheralModuleFunctionInputPin(
         uC_PORTSEL_UART0,
         (uC_PINSEL_UART0_TX | uC_PINSEL_UART0_RX)
     );
 }
void ADCInit(void)
{
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,
                                               GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 +
                                               GPIO_PIN3
                                               );

    //Initialize the ADC12_A Module
    /*
     * Base address of ADC12_A Module
     * Use internal ADC12_A bit as sample/hold signal to start conversion
     * USE MODOSC 5MHZ Digital Oscillator as clock source
     * Use default clock divider of 1
     */
    ADC12_A_init(ADC12_A_BASE,
                 ADC12_A_SAMPLEHOLDSOURCE_SC,
                 ADC12_A_CLOCKSOURCE_ADC12OSC,
                 ADC12_A_CLOCKDIVIDER_1
                 );

    ADC12_A_enable(ADC12_A_BASE);

    /*
     * Base address of ADC12_A Module
     * For memory buffers 0-7 sample/hold for 256 clock cycles
     * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
     * Enable Multiple Sampling
     */
    ADC12_A_setupSamplingTimer(ADC12_A_BASE,
                               ADC12_A_CYCLEHOLD_256_CYCLES,
                               ADC12_A_CYCLEHOLD_4_CYCLES,
                               ADC12_A_MULTIPLESAMPLESENABLE);

    //Configure Memory Buffers
    /*
     * Base address of the ADC12_A Module
     * Configure memory buffer 0
     * Map input A0 to memory buffer 0
     * Vref+ = AVcc
     * Vref- = AVss
     * Memory buffer 0 is not the end of a sequence
     */
    ADC12_A_configureMemoryParam param0 = {0};
    param0.memoryBufferControlIndex = ADC12_A_MEMORY_0;
    param0.inputSourceSelect = ADC12_A_INPUT_A0;
    param0.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    param0.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    param0.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
    ADC12_A_configureMemory(ADC12_A_BASE,&param0);

    /*
     * Base address of the ADC12_A Module
     * Configure memory buffer 1
     * Map input A1 to memory buffer 1
     * Vref+ = AVcc
     * Vref- = AVss
     * Memory buffer 1 is not the end of a sequence
     *
     */
    ADC12_A_configureMemoryParam param1 = {0};
    param1.memoryBufferControlIndex = ADC12_A_MEMORY_1;
    param1.inputSourceSelect = ADC12_A_INPUT_A1;
    param1.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    param1.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    param1.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
    ADC12_A_configureMemory(ADC12_A_BASE,&param1);
    /*
     * Base address of the ADC12_A Module
     * Configure memory buffer 2
     * Map input A2 to memory buffer 2
     * Vref+ = AVcc
     * Vref- = AVss
     * Memory buffer 2 is not the end of a sequence
     */
    ADC12_A_configureMemoryParam param2 = {0};
    param2.memoryBufferControlIndex = ADC12_A_MEMORY_2;
    param2.inputSourceSelect = ADC12_A_INPUT_A2;
    param2.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
    param2.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
    param2.endOfSequence = ADC12_A_ENDOFSEQUENCE;
    ADC12_A_configureMemory(ADC12_A_BASE,&param2);

    ADC12_A_startConversion(ADC12_A_BASE,
                            ADC12_A_MEMORY_0,
                            ADC12_A_REPEATED_SEQOFCHANNELS);
}
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;
}