Exemplo n.º 1
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;
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
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();
}
Exemplo n.º 4
0
void Setup1msTimer(void)
{
    //Start timer in continuous mode sourced by SMCLK
    //Timer_A_initContinuousModeParam initUpParam = {0};
    Timer_A_initUpModeParam initUpParam = {0};

    initUpParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
    initUpParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
    initUpParam.timerInterruptEnable_TAIE =
    		TIMER_A_TAIE_INTERRUPT_DISABLE;
    initUpParam.timerClear = TIMER_A_DO_CLEAR;
    initUpParam.startTimer = false;
    Timer_A_initUpMode(TIMER_A1_BASE, &initUpParam);

    //Initiaze compare mode
    Timer_A_clearCaptureCompareInterrupt(TIMER_A1_BASE,
    		TIMER_A_CAPTURECOMPARE_REGISTER_0);

    Timer_A_initCompareModeParam initCompParam = {0};
    initCompParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_0;
    initCompParam.compareInterruptEnable =
    		TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
    initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE;
    initCompParam.compareValue = UCS_getSMCLK()/1e3;
    Timer_A_initCompareMode(TIMER_A1_BASE, &initCompParam);

    Timer_A_startCounter(TIMER_A1_BASE,TIMER_A_UP_MODE);
}
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();
    }
}
void clock_init(void)
{
//	UCSCTL1 = DCORSEL_5; // 0x0050
	//UCSCTL1 = DCORSEL_1;
//	UCSCTL2 = 0x01F9;
//	UCSCTL3 = 0x0020;
//	UCSCTL4 = 0x0233;
//	UCSCTL5 = 0x0040;
//	UCSCTL6 = 0x0100;

	//Set DCO FLL reference = REFO
	UCS_clockSignalInit(
			__MSP430_BASEADDRESS_UCS_RF__,
		UCS_FLLREF,
		UCS_REFOCLK_SELECT,
		UCS_CLOCK_DIVIDER_1
		);
	//Set ACLK = REFO
	UCS_clockSignalInit(
			__MSP430_BASEADDRESS_UCS_RF__,
		UCS_ACLK,
		UCS_REFOCLK_SELECT,
		UCS_CLOCK_DIVIDER_1
		);

	//Set Ratio and Desired MCLK Frequency  and initialize DCO
//	UCS_initFLLSettle(
//			__MSP430_BASEADDRESS_UCS_RF__,
//		1000, // 1000 khz
//		31   //  1000 kHz / 32.768 Khz (Crystal)
//		);

	_BIS_SR(SCG0);                  // Disable the FLL control loop
	UCS_initFLLSettle(
			__MSP430_BASEADDRESS_UCS_RF__,
			target_clock_speed_kHz, // 10000 khz
			(uint16_t) ((target_clock_speed_kHz * 1000) / 32768)   //  10000 kHz / 32.768 Khz  = 305(Crystal)
			);
	_BIC_SR(SCG0);                  // Enable the FLL control loop


	clock_speed = UCS_getSMCLK(__MSP430_BASEADDRESS_UCS_RF__);
	//unsigned long clockValueMCLK = UCS_getMCLK(__MSP430_BASEADDRESS_UCS_RF__);
	//unsigned long clockValueCLK = UCS_getACLK(__MSP430_BASEADDRESS_UCS_RF__);
}
Exemplo n.º 7
0
void clock_init(void)
{
//	UCSCTL1 = DCORSEL_5; // 0x0050
	//UCSCTL1 = DCORSEL_1;
//	UCSCTL2 = 0x01F9;
//	UCSCTL3 = 0x0020;
//	UCSCTL4 = 0x0233;
//	UCSCTL5 = 0x0040;
//	UCSCTL6 = 0x0100;

	//Set DCO FLL reference = REFO
	UCS_clockSignalInit(
			__MSP430_BASEADDRESS_UCS_RF__,
		UCS_FLLREF,
		UCS_REFOCLK_SELECT,
		UCS_CLOCK_DIVIDER_1
		);
	//Set ACLK = REFO
	UCS_clockSignalInit(
			__MSP430_BASEADDRESS_UCS_RF__,
		UCS_ACLK,
		UCS_REFOCLK_SELECT,
		UCS_CLOCK_DIVIDER_1
		);

	//Set Ratio and Desired MCLK Frequency  and initialize DCO
//	UCS_initFLLSettle(
//			__MSP430_BASEADDRESS_UCS_RF__,
//		1000, // 1000 khz
//		31   //  1000 kHz / 32.768 Khz (Crystal)
//		);

	UCS_initFLLSettle(
				__MSP430_BASEADDRESS_UCS_RF__,
			10000, // 10000 khz
			305   //  10000 kHz / 32.768 Khz (Crystal)
			);


	clock_speed = UCS_getSMCLK(__MSP430_BASEADDRESS_UCS_RF__);
	//unsigned long clockValueMCLK = UCS_getMCLK(__MSP430_BASEADDRESS_UCS_RF__);
	//unsigned long clockValueCLK = UCS_getACLK(__MSP430_BASEADDRESS_UCS_RF__);
}
Exemplo n.º 8
0
//*****************************************************************************
//
//! \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);
}