Guest User

Untitled

a guest
Nov 19th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. void main() {
  2. ...
  3. // eUSCI_A0 support
  4. P1SEL1 &= ~(BIT4 | BIT5);
  5. P1SEL0 |= BIT4|BIT5;
  6. PMM_unlockLPM5();
  7. ...
  8. // MCLK, SMCLK are both at 16MHz running off DCO with FLL bound to XT1 crystal
  9. ...
  10. // Initialize eUSCI_A0
  11. EUSCI_A_UART_initParam ea0Init;
  12. ea0Init.uartMode = EUSCI_A_UART_MODE;
  13. ea0Init.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
  14. ea0Init.parity = EUSCI_A_UART_NO_PARITY;
  15. ea0Init.overSampling = EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
  16. ea0Init.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
  17. ea0Init.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
  18. uint32_t brDiv, brMod;
  19. brDiv = (16000000 << 4) / 115200;
  20. brMod = brDiv & 0xFFF0;
  21. brDiv >>= 8;
  22. brMod >>= 4;
  23. ea0Init.clockPrescalar = brDiv;
  24. ea0Init.firstModReg = brMod & 0x0F;
  25. ea0Init.secondModReg = brMod >> 4;
  26. EUSCI_A_UART_init(EUSCI_A0_BASE, &ea0Init);
  27. EUSCI_A_UART_enable(EUSCI_A0_BASE);
  28. EUSCI_A_UART_resetDormant(EUSCI_A0_BASE);
  29. EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_TRANSMIT_INTERRUPT | EUSCI_A_UART_RECEIVE_INTERRUPT);
  30.  
  31. __enable_interrupt();
  32. ...
  33. }
  34.  
  35. // ISR
  36. #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
  37. #pragma vector=USCI_A0_VECTOR
  38. __interrupt void USCI_A0_ISR(void)
  39. #elif defined(__GNUC__)
  40. void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
  41. #else
  42. #error Compiler not supported!
  43. #endif
  44. {
  45. switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
  46. {
  47. case USCI_NONE: break;
  48. case USCI_UART_UCRXIFG:
  49. P1OUT |= BIT0; // Switch on red LED when byte received; TX vector will switch it off, it should be a short flicker
  50. while(UCA0STATW&UCBUSY); // Busy-waits inside ISR is bad code, but this is a stupid simple example
  51. UCA0TXBUF = UCA0RXBUF;
  52. __no_operation();
  53. break;
  54. case USCI_UART_UCTXIFG:
  55. P1OUT &= ~BIT0;
  56. break;
  57. case USCI_UART_UCSTTIFG: break;
  58. case USCI_UART_UCTXCPTIFG: break;
  59. default: break;
  60. }
  61. }
Add Comment
Please, Sign In to add comment