Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <in430.h>
- #include <intrinsics.h>
- #include <msp430f1611.h>
- #include <stdint.h>
- void init();
- int main(void) {
- WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
- init();
- U0TXBUF = '\n';
- while(1) {
- int i=0;
- for(;i<10000;i++);
- }
- }
- const char stringtosent[] = { "Hello World\r\n" };
- char recvBuffer[5];
- inline void init() {
- P3SEL |= 0x30;
- U0CTL |= SWRST;
- U0CTL |= CHAR; // 8-bit character
- U0TCTL |= SSEL1;
- BCSCTL2 |= SELS;
- ME1 |= UTXE0 | URXE0; // Enabled USART0 TXD RXD
- // Ustawienia dla 115200
- U0BR0 = 0x40;
- U0BR1 = 0x00;
- U0MCTL = 0x4A;
- U0CTL &= ~SWRST; // Wylaczenie software reset
- // DMA0 transmiting
- DMACTL0 |= DMA0TSEL_4; // transmit trigger transmit
- DMA0SA = (unsigned int)stringtosent; // Source block address
- DMA0DA = (unsigned int)&U0TXBUF; // Dest single address
- DMA0SZ = sizeof stringtosent-1; // Block size
- DMA0CTL |= DMASRCINCR_3 + DMASRCBYTE + DMADSTBYTE + DMALEVEL + DMAIE; // increment source, byte in, byte out, level triggered
- // DMA1 recv
- DMACTL0 |= DMA1TSEL_3; // recv trigger recv
- DMA1SA = (unsigned int)&U0RXBUF; // Source block address
- DMA1DA = (unsigned int)recvBuffer; // Dest single address
- DMA1SZ = sizeof recvBuffer-1; // Block size
- DMA1CTL |= DMADSTINCR_3 + DMASRCBYTE + DMADSTBYTE + DMALEVEL + DMAIE + DMAEN; // increment source, byte in, byte out, level triggered
- _EINT();
- }
- #pragma vector=DACDMA_VECTOR
- __interrupt void dmaisr(void)
- {
- if (DMA1CTL & DMAIFG) {
- DMA1CTL &= ~DMAIFG;
- DMA0SA = (unsigned int)recvBuffer; // Source block address
- DMA0DA = (unsigned int)&U0TXBUF; // Dest single address
- DMA0SZ = sizeof recvBuffer-1; // Block size
- DMA0CTL |= DMAEN;
- }
- if(DMA0CTL & DMAIFG) {
- DMA0CTL &= ~DMAIFG;
- DMA1CTL |= DMAEN; // Enable read again
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement