hdarwin

msp430f5529lp_cscia1_uart.c

Aug 27th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <msp430f5529.h>
  2.  
  3. void main(void) {
  4.     WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
  5.     // MSP430x5xx and MSP430x6xx Family User's Guide 894 Page
  6.     // USCI Initialization and Reset
  7.     // The USCI is reset by a PUC or by setting the UCSWRST bit. After a PUC, the UCSWRST bit is
  8.     // automatically set, keeping the USCI in a reset condition.
  9.     // When set, the UCSWRST bit resets the UCRXIE,
  10.     // UCTXIE, UCRXIFG, UCRXERR, UCBRK, UCPE, UCOE, UCFE, UCSTOE, and UCBTOE bits, and sets
  11.     // the UCTXIFG bit. Clearing UCSWRST releases the USCI for operation.
  12.     UCA1CTL1 |= UCSWRST;        // USCI_A Reset
  13.     UCA1CTL0 = 0;           // 1 Stop bit, Parity disabled, LSB First select, 8-bit data
  14.     UCA1CTL1 |= UCSSEL__SMCLK;  // SMCLK 8Mhz - SMCLK drives high-speed peripherals.
  15.                     // It is kept alive during LPM0 but disabled in LPM3, LPM4, and LPM5.
  16.                     // LPM0 is the lowest power mode permissible during an active USB connection.
  17.     UCA1BR0 = 0x41;         // N=80000000/9600.0 = 833.3333333333334
  18.     UCA1BR1 = 0x03;         // INT(N) = 833 = 0x341
  19.     UCA1MCTL |= UCBRS_3;        // round(0.3333333333334*8) = round(2.6666666672) = 3
  20.     UCA1CTL1 &= ~UCSWRST;       // Initialize USCI_A
  21.     UCA1IE |= UCRXIE;       // Enable USCI_A1 RX interrupt
  22.     _EINT();
  23. }
  24.  
  25. #pragma vector=USCI_A1_VECTOR
  26. __interrupt void USCI_A1_ISR(void) {
  27.     if (UCA1IV & 0x04) {
  28.         while (!(UCA1IFG & UCTXIFG));
  29.         UCA1TXBUF = UCA1RXBUF;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment