1 / 16

UART

UART. 下載. uart1 echo.rar. Baudrate 計算. 1000000/19200=52.08  0x34 UBR0  0x34 UBR1  0 U1BR0 = 0x34; // 1MHz 19200 U1BR1 = 0x00; // 1MHz 19200 U1MCTL = 0x6B; // 1MHz 19200 modulation. RS-232 接線. MSP430 實驗板. PC. 7 Seg LED. uart1. uart0.

judah
Download Presentation

UART

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UART

  2. 下載 • uart1 echo.rar

  3. Baudrate計算 • 1000000/19200=52.08  0x34 • UBR0  0x34 • UBR1  0 • U1BR0 = 0x34; // 1MHz 19200 • U1BR1 = 0x00; // 1MHz 19200 • U1MCTL = 0x6B; // 1MHz 19200 modulation

  4. RS-232接線 MSP430 實驗板 PC 7 Seg LED uart1 uart0

  5. 開啟超級終端機

  6. 設定終端機

  7. 若有存檔,第二次可直接開啟19200

  8. for (;;) • { • while (!(U1TCTL & TXEPT)); // Confirm no TXing before --> LPM3 • _DINT(); // Disable interrupts for flag test • _NOP(); • U1TXBUF = 't'; // char to TXBUF0

  9. 睡眠狀態 • if (!(U1TCTL & SSEL0)) • _BIS_SR(LPM0_bits + GIE); // RX'ing char, LPM, int's active • else • _BIS_SR(LPM3_bits + GIE); // Enter LPM3, int's active

  10. 中斷程式--接收 • #pragma vector=USART1RX_VECTOR • __interrupt void usart1_rx (void) • { • if ((IFG2 & URXIFG1)) // Test URXIFG0 • { • while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready? • U1TXBUF = U1RXBUF; // RXBUF0 to TXBUF0 • _BIC_SR_IRQ(LPM3_bits); // Exit LPM3 after reti • U1TCTL |= SSEL0; // SSEL0 = 1, no RX activity • } else // Start edge • { • U1TCTL &= ~URXSE; // Clear URXS signal • U1TCTL |= URXSE; // Re-enable edge detect • _BIC_SR_IRQ(SCG1 + SCG0); // DCO reamins on after reti • U1TCTL &= ~SSEL0; // SSEL0= 0, RX activity • } • }

  11. Baudrate計算 • 1000000/38400=26.04  0x1A • UBR0  0x1A • UBR1  0 • U1BR0 = 0x1A; // 1MHz 38400 • U1BR1 = 0x00; // 1MHz 19200 • U1MCTL = 0x6B; // 1MHz 19200 modulation

  12. 發送一串文字 • U1TXBUF = 't'; // char to TXBUF0 • while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready? • U1TXBUF = 'e'; // char to TXBUF0 • while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready? • U1TXBUF = 's'; // char to TXBUF0 • while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready? • U1TXBUF = 't'; // char to TXBUF0 • while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready? • U1TXBUF = ' '; // char to TXBUF0 • while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?

  13. Baudrate計算 • 1000000/115200=8.58  8 • UBR0  0x8 • UBR1  0 • U1BR0 = 8; // 1MHz 115200 • U1BR1 = 0x00; // 1MHz 19200 • U1MCTL = 0x6B; // 1MHz 19200 modulation

  14. 接收副程式 • char recv_uart1( void ) • { • if ((IFG2 & URXIFG1)) // Test URXIFG0 • { • return U1RXBUF; • } • return 0; • }

  15. 利用接收副程式接收資料 • temp=0; • while(temp==0) • { • temp=recv_uart1(); • } • U1TXBUF = temp; // char to TXBUF0 • while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?

  16. 檢查是否輸入1 • while(temp==0) • { • temp=recv_uart1(); • } • U1TXBUF = temp; // char to TXBUF0 • while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready? • if (temp==0x31){ • }

More Related