Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void main() {
- ...
- // eUSCI_A0 support
- P1SEL1 &= ~(BIT4 | BIT5);
- P1SEL0 |= BIT4|BIT5;
- PMM_unlockLPM5();
- ...
- // MCLK, SMCLK are both at 16MHz running off DCO with FLL bound to XT1 crystal
- ...
- // Initialize eUSCI_A0
- EUSCI_A_UART_initParam ea0Init;
- ea0Init.uartMode = EUSCI_A_UART_MODE;
- ea0Init.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
- ea0Init.parity = EUSCI_A_UART_NO_PARITY;
- ea0Init.overSampling = EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
- ea0Init.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
- ea0Init.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
- uint32_t brDiv, brMod;
- brDiv = (16000000 << 4) / 115200;
- brMod = brDiv & 0xFFF0;
- brDiv >>= 8;
- brMod >>= 4;
- ea0Init.clockPrescalar = brDiv;
- ea0Init.firstModReg = brMod & 0x0F;
- ea0Init.secondModReg = brMod >> 4;
- EUSCI_A_UART_init(EUSCI_A0_BASE, &ea0Init);
- EUSCI_A_UART_enable(EUSCI_A0_BASE);
- EUSCI_A_UART_resetDormant(EUSCI_A0_BASE);
- EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_TRANSMIT_INTERRUPT | EUSCI_A_UART_RECEIVE_INTERRUPT);
- __enable_interrupt();
- ...
- }
- // ISR
- #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
- #pragma vector=USCI_A0_VECTOR
- __interrupt void USCI_A0_ISR(void)
- #elif defined(__GNUC__)
- void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
- #else
- #error Compiler not supported!
- #endif
- {
- switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
- {
- case USCI_NONE: break;
- case USCI_UART_UCRXIFG:
- P1OUT |= BIT0; // Switch on red LED when byte received; TX vector will switch it off, it should be a short flicker
- while(UCA0STATW&UCBUSY); // Busy-waits inside ISR is bad code, but this is a stupid simple example
- UCA0TXBUF = UCA0RXBUF;
- __no_operation();
- break;
- case USCI_UART_UCTXIFG:
- P1OUT &= ~BIT0;
- break;
- case USCI_UART_UCSTTIFG: break;
- case USCI_UART_UCTXCPTIFG: break;
- default: break;
- }
- }
Add Comment
Please, Sign In to add comment