1849 views|0 replies

2015

Posts

0

Resources
The OP
 

msp430f5529 simple uart source program (use the serial port assistant to send and receive replies) [Copy link]

The MCU source program is as follows:

  1. /*****What to send with the serial assistant and what to reply****/
  2. #include "msp430f5529.h"
  3. // ACLK = REFO = 32768Hz, MCLK = SMCLK = default DCO/2 = 1048576Hz
  4. // P3.4,5——USCI_A0 TXD/RXD;P9.4,5——USCI_A2 TXD/RXD;P10.4,5——USCI_A3 TXD/RXD;
  5. void main(void)
  6. {
  7. WDTCTL = WDTPW + WDTHOLD; // Stop WDT
  8. P4SEL |=BIT4+BIT5 ; // P5.6,7 = USCI_A1 TXD/RXD
  9. UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
  10. UCA1CTL1 |= UCSSEL_2; // SMCLK
  11. UCA1BR0 = 9; // 1MHz 115200 (see User's Guide)
  12. UCA1BR1 = 0; // 1MHz 115200
  13. UCA1MCTL |= UCBRS_1 + UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0
  14. UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
  15. UCA1IE |= UCRXIE; // Enable USCI_A1 RX interrupt
  16. __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
  17. }
  18. // Echo back RXed character, confirm TX buffer is ready first, confirm the send buffer is ready before sending data
  19. #pragma vector=USCI_A1_VECTOR
  20. __interrupt void USCI_A1_ISR(void)
  21. {
  22. switch(__even_in_range(UCA1IV,4))
  23. {
  24. case 0:break; // Vector 0 - no interrupt
  25. case 2: // Vector 2 - RXIFG
  26. while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX buffer ready? UCTXIFG(USCI Transmit Interrupt Flag)
  27. //Wait for data to be sent and then set UCTXIFG to 1 to exit the loop
  28. UCA1TXBUF = UCA1RXBUF; // TX -> RXed character
  29. break;
  30. case 4:break; // Vector 4 - TXIFG
  31. default: break;
  32. }
  33. }
  34. // UCTXIFG = 0x02, UCA1IFG & UCTXIFG, when the UCTXIFG bit of UCA1IFG is 1, it means that UCA1TXBUF is empty.
  35. //Break out of the while loop; when the UCTXIFG bit is 0, UCA1TXBUF is not empty, so stop in the loop.
This post is from Microcontroller MCU
 

Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list