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;
}
Beispiel #2
0
 static inline void _uart0_peripheral_init(void){
     USCI_A_UART_initParam param = {0};
     param.selectClockSource =   USCI_A_UART_CLOCKSOURCE_SMCLK;
     param.clockPrescalar =      _UART0_DIV_INT;
     param.firstModReg =         0;
     param.secondModReg =        (uint8_t)_UART0_BRS_VAL;
     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(uC_UART0_BASE, &param);
     USCI_A_UART_enable(uC_UART0_BASE);  
     USCI_A_UART_clearInterrupt(uC_UART0_BASE, USCI_A_UART_RECEIVE_INTERRUPT);
     USCI_A_UART_enableInterrupt(uC_UART0_BASE, USCI_A_UART_RECEIVE_INTERRUPT);
 }
/*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;
}
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
}