Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #include "msp.h"
  2. void ClockSetup(void);
  3. void BT_UART_PIN_SETUP(void);
  4. char testing = 'a';
  5. char testing123[11] = {'H', 'E', 'L', 'L', 'O', ' ', 'W', 'O', 'R', 'L', 'D'};
  6. int enumerator = 0;
  7.  
  8. int main(void)
  9. {
  10. WDT_A->CTL = WDT_A_CTL_PW | // Stop watchdog timer
  11. WDT_A_CTL_HOLD;
  12. ClockSetup();
  13. BT_UART_PIN_SETUP();
  14. ClockSetup();
  15. // Enable global interrupt
  16. __enable_irq();
  17. //while (1){
  18. //EUSCI_A0->TXBUF = '0';
  19. //EUSCI_A1->TXBUF = '0';
  20. //EUSCI_A2->TXBUF = '0';
  21. //}
  22. }
  23.  
  24. void BT_UART_PIN_SETUP(){ //enable pins for UART comm
  25. // Baud Rate calculation
  26. // 12000000/(16*9600) = 78.125
  27. // Fractional portion = 0.125
  28. // User's Guide Table 21-4: UCBRSx = 0x10
  29. // UCBRFx = int ( (78.125-78)*16) = 2
  30.  
  31. P3->SEL0 |= (BIT3 + BIT2); // P3.2 RX
  32. P3->SEL1 &= ~(BIT3 + BIT3); // P3.3 TX
  33. // Configure UART
  34. EUSCI_A2->CTLW0 |= EUSCI_A_CTLW0_SWRST; // Put eUSCI in reset
  35. EUSCI_A2->CTLW0 = EUSCI_A_CTLW0_SWRST | // Remain eUSCI in reset
  36. EUSCI_B_CTLW0_SSEL__SMCLK; // Configure eUSCI clock source for SMCLK
  37. EUSCI_A2->BRW = 78; // 12000000/16/9600
  38. EUSCI_A2->MCTLW = (2 << EUSCI_A_MCTLW_BRF_OFS) |
  39. EUSCI_A_MCTLW_OS16;
  40. EUSCI_A2->CTLW0 &= ~EUSCI_A_CTLW0_SWRST; // Initialize eUSCI
  41. EUSCI_A2->IFG &= ~EUSCI_A_IFG_RXIFG; // Clear eUSCI RX interrupt flag
  42. EUSCI_A2->IE |= EUSCI_A_IE_RXIE; // Enable USCI_A1 RX interrupt
  43. // Enable eUSCIA1 interrupt in NVIC module
  44. NVIC->ISER[0] = 1 << ((EUSCIA2_IRQn) & 31);
  45. }
  46.  
  47. // UART interrupt service routine
  48. void EUSCIA2_IRQHandler(){
  49. //EUSCI_A2->TXBUF = 'A';
  50. EUSCI_A2->TXBUF = testing123[enumerator % 11];
  51.  
  52. enumerator = enumerator + 1;
  53.  
  54. EUSCI_A2->IFG &= ~EUSCI_A_IFG_RXIFG;
  55. }
  56.  
  57. void ClockSetup(void){
  58. CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
  59. CS->CTL0 = 0; // Reset tuning parameters
  60. CS->CTL0 = CS_CTL0_DCORSEL_3; // Set DCO to 12MHz (nominal, center of 8-16MHz range)
  61. CS->CTL1 = CS_CTL1_SELA_2 | // Select ACLK = REFO
  62. CS_CTL1_SELS_3 | // SMCLK = DCO
  63. CS_CTL1_SELM_3; // MCLK = DCO
  64. CS->KEY = 0; // Lock CS module from unintended accesses
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement