UART两个例程分析( 三 )


/* DriverLib Includes */#include /* Standard Includes */#include #include //定义不同大小的数据uint8_t TXData = http://www.kingceram.com/post/1;uint8_t RXData = 0;/* UART Configuration Parameter. These are the configuration parameters to* make the eUSCI A UART module to operate with a 115200 baud rate. These* values were calculated using the online calculator that TI provides* at:* http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html*///三个参数分别为13 0 37 8const eUSCI_UART_ConfigV1 uartConfig ={EUSCI_A_UART_CLOCKSOURCE_SMCLK,// SMCLK Clock Source13,// BRDIV = 130,// UCxBRF = 037,// UCxBRS = 37EUSCI_A_UART_NO_PARITY,// No ParityEUSCI_A_UART_MSB_FIRST,// MSB FirstEUSCI_A_UART_ONE_STOP_BIT,// One stop bitEUSCI_A_UART_MODE,// UART modeEUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION,// OversamplingEUSCI_A_UART_8_BIT_LEN// 8 bit data length};int main(void){//看门狗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 24MHz (upping Vcore) */FlashCtl_setWaitState(FLASH_BANK0, 1);FlashCtl_setWaitState(FLASH_BANK1, 1);MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_24);/* Configuring UART Module */MAP_UART_initModule(EUSCI_A2_BASE, &uartConfig);/* Enable UART module */MAP_UART_enableModule(EUSCI_A2_BASE);/* Enabling interrupts */MAP_UART_enableInterrupt(EUSCI_A2_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);MAP_Interrupt_enableInterrupt(INT_EUSCIA2);MAP_Interrupt_enableSleepOnIsrExit();while(1){MAP_UART_transmitData(EUSCI_A2_BASE, TXData);MAP_Interrupt_enableSleepOnIsrExit();MAP_PCM_gotoLPM0InterruptSafe();}}/* EUSCI A0 UART ISR - Echos data back to PC host */void EUSCIA2_IRQHandler(void){uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A2_BASE);if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG){RXData = MAP_UART_receiveData(EUSCI_A2_BASE);if(RXData != TXData)// Check value{MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);while(1);// Trap CPU}TXData++;MAP_Interrupt_disableSleepOnIsrExit();}}