Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.86 KB | None | 0 0
  1. #include <in430.h>
  2. #include <intrinsics.h>
  3. #include <msp430f1611.h>
  4. #include <stdint.h>
  5.  
  6. void init();
  7.  
  8. int main(void) {
  9.     WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
  10.  
  11.     init();
  12.     U0TXBUF = '\n';
  13.     while(1) {
  14.         int i=0;
  15.         for(;i<10000;i++);
  16.     }
  17. }
  18.  
  19.  
  20. const char stringtosent[] = { "Hello World\r\n" };
  21. char recvBuffer[5];
  22.  
  23. inline void init() {
  24.     P3SEL |= 0x30;
  25.     U0CTL |= SWRST;
  26.     U0CTL |= CHAR; // 8-bit character
  27.     U0TCTL |= SSEL1;
  28.     BCSCTL2 |= SELS;
  29.     ME1 |= UTXE0 | URXE0; // Enabled USART0 TXD RXD
  30.  
  31.     // Ustawienia dla 115200
  32.     U0BR0 = 0x40;
  33.     U0BR1 = 0x00;
  34.     U0MCTL = 0x4A;
  35.     U0CTL &= ~SWRST; // Wylaczenie software reset
  36.  
  37.     // DMA0 transmiting
  38.     DMACTL0 |= DMA0TSEL_4; // transmit trigger transmit
  39.     DMA0SA = (unsigned int)stringtosent; // Source block address
  40.     DMA0DA = (unsigned int)&U0TXBUF; // Dest single address
  41.     DMA0SZ = sizeof stringtosent-1; // Block size
  42.     DMA0CTL |= DMASRCINCR_3 + DMASRCBYTE + DMADSTBYTE + DMALEVEL + DMAIE; // increment source, byte in, byte out, level triggered
  43.  
  44.     // DMA1 recv
  45.     DMACTL0 |= DMA1TSEL_3; // recv trigger recv
  46.     DMA1SA = (unsigned int)&U0RXBUF; // Source block address
  47.     DMA1DA = (unsigned int)recvBuffer; // Dest single address
  48.     DMA1SZ = sizeof recvBuffer-1; // Block size
  49.     DMA1CTL |= DMADSTINCR_3 + DMASRCBYTE + DMADSTBYTE + DMALEVEL + DMAIE + DMAEN; // increment source, byte in, byte out, level triggered
  50.  
  51.     _EINT();
  52. }
  53.  
  54. #pragma vector=DACDMA_VECTOR
  55. __interrupt void dmaisr(void)
  56. {
  57.     if (DMA1CTL & DMAIFG) {
  58.         DMA1CTL &= ~DMAIFG;
  59.         DMA0SA = (unsigned int)recvBuffer; // Source block address
  60.         DMA0DA = (unsigned int)&U0TXBUF; // Dest single address
  61.         DMA0SZ = sizeof recvBuffer-1; // Block size
  62.         DMA0CTL |= DMAEN;
  63.     }
  64.     if(DMA0CTL & DMAIFG) {
  65.         DMA0CTL &= ~DMAIFG;
  66.         DMA1CTL |= DMAEN; // Enable read again
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement