Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

Memory -> DMA -> UART

Quartus 4.2 | NIOSII 1.1 | EP1S25 DSP-Board | Win2k

Hi there,

i got the DMA working with HAL to send data from memory to memory. My next wish is to send data from memory to the UART. My UART receives 8bit, so i just tried to send one byte but it makes me a headache http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/blink.gif Why can´t i just set the destinationadress to the UART instead of another part of the memory?

Has anyone experience with that? Do i have to implement a kind of sleep-function while sending data because of the lowspeed of the UART(9600bps)?

Some ideas would be nice!

Happy easter & nice egg-searching!

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    int fdterm; // FILEDESCRIPTOR RETURNED BY OPEN

    int i; // for for();

    FILE * fpterm; // FILE pointer returned by fdopen

    int uart1_rxcount = 0; //counts received data from uart

    alt_u8 uart1_rxbuffer[5]; //stores received data from uart

    int pattern=0xF;//data to fill memory

    unsigned int *p = (unsigned int*)(0x00010000);//Startadress

    unsigned int *j = (unsigned int*)(0x00010100);//Destinationadress

    //DMA_BASE= 0x00020880 //UART_BASE = 0x00020820

    int main(void)

    {

    //Write to memory something

    for (i=0; i<5; i++)

    {

    IOWR_32DIRECT(p/*+i*/, 0, pattern);//writes pattern from memory to memory+5

    }

    //to open the uart-channel in read/write-modus

    // fdterm = open("/dev/uart1", O_RDWR | O_NONBLOCK | O_NOCTTY);

    // fpterm = fdopen(fdterm,"rw+");

    // fprintf(fpterm,"UART1 STARTED\r\n"); // check initial output

    //printf("JTAG STARTED\r\n");

    IOWR_ALTERA_AVALON_DMA_CONTROL(DMA_BASE, 0x0); // dma transfer disabled

    //Send some words

    IOWR_ALTERA_AVALON_DMA_STATUS(DMA_BASE, 0);

    IOWR_ALTERA_AVALON_DMA_RADDRESS(DMA_BASE, (int)p); //Pointer to memory

    IOWR_ALTERA_AVALON_DMA_WADDRESS(DMA_BASE, (int)j); //Pointer to your device

    IOWR_ALTERA_AVALON_DMA_LENGTH(DMA_BASE, 4); //Sending words (1 word == 4 bytes)

    IOWR_ALTERA_AVALON_DMA_CONTROL(DMA_BASE, 0x0CC); //See description of dma control register

    return 0;

    }

    This is the code which copies from p (memory) to j(memory). Why can´t i copy from p(memory) to j(uart)?

    I hope there is no huge thinking mistake http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif

    thanks for help!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    According to the views, my problem seems to be too difficult or too easy...

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Have you tried setting the WCON bit in the control register? The RCON and WCON bits in the DMA control register are for when you have constant read/write addresses. In your case, you have a constant write address: txdata of the UART.

    I would also set the DMA to perform byte transfers only, but that&#39;s just me...

    Best of luck and I hope this helps!

    - slacker
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    thanks for your answer, i´m on it...

    i´m also trying to use the small-driver-option for the preprocessor...

    the mode for the DMA was just a test, originally it was set on byte-transfer-only...

    Regards, Max