Advertisement
Guest User

Untitled

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