Forum Discussion

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

Connecting a USB<->rs232(uart) module to the de-0 nano via GPIO

Hi, big newbie here. I was hoping you could all help me with my little problem(and answer some simple questions).

I am doing my final year project and want to send some polynomial coefficients from a file on my computer to my de-0 nano board and back into a new file(after calculating on the board) using a simple c++ program. To do this i bought a small USB<->rs232 module.

https://www.alteraforum.com/forum/attachment.php?attachmentid=6517

I wanted to install the module as a COM port on my computer(with the manufacters drivers) but after connecting it via a USB cable, the PC didn't detect it so I concluded that I probably have to supply power to it from the de-0(I thought the module would be supplied from the USB connection) but have no idea how to do this. On the schematic from the manufacturer I see that I can use the 3,3 V pin but after reading the de-0 nano manual I don't understand if the 3,3 V GPIO pin on the header is for supplying power TO or FROM the board.

https://www.alteraforum.com/forum/attachment.php?attachmentid=6514 https://www.alteraforum.com/forum/attachment.php?attachmentid=6515

My plan was to supply power to the board via the usb cable(the one supplied in the board box) and then to the module with a serial cable(from the GPIO) but after connecting the cable to the board the module still doesn't power up. Do I have to first program the GPIO power pin in VHDL? Also on the schematics the 3,3 V and GND pin on the module are not in line as in the de-0 so how can i possibly connect the devices(do I have to connect the corrent pins to each other with a cable I make myself)? The cable im trying to use:

https://www.alteraforum.com/forum/attachment.php?attachmentid=6518

Can I connect it to only some of the GPIO pins on the board(or do i have to find a cable with 40 pins to cover the whole header)? Thanks for all your help in advance!!

15 Replies

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

    Ok, so I'm starting to get a bit crazy:D Atm, I just want to send a 8 bit vector from my computer, "not" it, and send it back.

    So I started with creating a SOPC

    https://www.alteraforum.com/forum/attachment.php?attachmentid=6556

    And now I have no idea, do I use the new component option inside the SOPC(with the "not" logic, I attached the file but it's really simple) or outside the SOPC. I currently have something like this

    https://www.alteraforum.com/forum/attachment.php?attachmentid=6557

    Which shows me that I can connect the UART to the GPIO pins, but how do I then send the received data(from the uart) to my logic block? Reading the manual that came with the de-0 nano didn't really help as they just used the sopc to run simple C program on the de-0 nano while using the Jtag UART. So my main problem would be how can I access the converted UART data? Peering into the vhdl file generated by the SOPC builder there is about a million signals and my guess would be that one of them would be used as the converted data from the UART?

    --- Quote Start ---

    Based on the fact that you want to use the serial module (rather than JTAG).

    --- Quote End ---

    Well, since it's the more complicated idea maybe I can learn more from it:)

    Thanks for all the newbie info,

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

    --- Quote Start ---

    Since you comment you are a newbie, I'll provide some feedback on your design proposal and offer an alternative.

    Your project/proposal:

    What is the task? Are you responsible for the FPGA communications, or is that just a means-to-an-end? Is the main task related to the polynomial coefficients and whatever those coefficients are controlling?

    As far as the communications aspect goes, your solution would work fine, however, it may involve more work than is really necessary. Here's what you would do:

    1. Connect the two boards together.

    a) The serial board looks like some sort of FTDI breakout board with USB and a header. It should be receiving power from the USB port, so there should be *no* reason for you to connect power pins from that board to the DE0-nano.

    b) Check that your RS232 board output is 3.3V logic - not 5V logic (the DE0-nano cannot handle 5V signals).

    c) Connect the TX and RX pins from your serial board to two GPIO pins on your DE0-nano, and connect a ground pin between the two boards (so that they both agree on voltages).

    2. Create an FPGA system containing a NIOS II processor, a UART, and your custom logic and connect that UART to the GPIO pins.

    3. Write NIOS II software to receive data over the serial port, and write the coefficients into your custom logic.

    4. Write the host software to send data to the NIOS II.

    While all this is pretty straightforward, since you are new to this, it might take you a while to get to grips with all the details.

    An alternative implementation is to implement the communications using the USB-Blaster connection that already exists between your board and your PC. Read through this tutorial

    http://www.alterawiki.com/wiki/using_the_usb-blaster_as_an_sopc/qsys_avalon-mm_master_tutorial

    The tutorial contains all the code you need for communications with a Qsys or SOPC System.

    Continue to ask questions and the readers of this forum will provide feedback.

    Cheers,

    Dave

    --- Quote End ---

    Hi Dave,

    Could you please provide me links for Step 3 and 4 that you mentioned? really appreciate

    2. Create an FPGA system containing a NIOS II processor, a UART, and your custom logic and connect that UART to the GPIO pins.

    3. Write NIOS II software to receive data over the serial port, and write the coefficients into your custom logic.

    4. Write the host software to send data to the NIOS II.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Ok, so I'm starting to get a bit crazy:D Atm, I just want to send a 8 bit vector from my computer, "not" it, and send it back.

    So I started with creating a SOPC

    http://www.alteraforum.com/forum/attachment.php?attachmentid=6556&stc=1

    And now I have no idea, do I use the new component option inside the SOPC(with the "not" logic, I attached the file but it's really simple) or outside the SOPC. I currently have something like this

    http://www.alteraforum.com/forum/attachment.php?attachmentid=6557&stc=1

    Which shows me that I can connect the UART to the GPIO pins, but how do I then send the received data(from the uart) to my logic block? Reading the manual that came with the de-0 nano didn't really help as they just used the sopc to run simple C program on the de-0 nano while using the Jtag UART. So my main problem would be how can I access the converted UART data? Peering into the vhdl file generated by the SOPC builder there is about a million signals and my guess would be that one of them would be used as the converted data from the UART?

    Well, since it's the more complicated idea maybe I can learn more from it:)

    Thanks for all the newbie info,

    Fred

    --- Quote End ---

    Hi Fred,

    Could you please tell me how did you access the converted UART data finally? Thank you
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The easiest way was to get the ALTERA university program (UP) IP cores. I added a RS232 UART component (from the UP) to a Qsys system and then used the HAL drivers (#include <altera_up_avalon_rs232.h>) supplied with the UP to receive and send data with a simple nios ii program.

    Open up the uart device:

    alt_up_rs232_dev *rs232_0_dev;

    rs232_0_dev=alt_up_rs232_open_dev("/dev/rs232_0");

    I then wait for data from the UART:

    while((alt_up_rs232_get_used_space_in_read_FIFO(rs232_0_dev))==0)

    {

    //wait for a character from the UART

    }

    Once a byte of data is ready i read it:

    alt_up_rs232_read_data(rs232_0_dev, &in_buffer[index1], &parity_read1)

    Writing data is similar, wait for free space in the UART outgoing buffer and send data:

    while(alt_up_rs232_get_available_space_in_write_FIFO(rs232_0_dev)==0)

    {

    //printf("waiting for space in out fifo\n");

    }

    //printf("after waiting for space in out fifo\n");

    if(alt_up_rs232_write_data(rs232_0_dev,temp1[index2])==0)

    {

    }

    A MUCH more elegant solution would be using nios ii interrupts, this simple example "blocks" the program until a specific amount of data is read (you have to wait for data before the program can do other things). In the university program folder you can find more examples using the UART core.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    The easiest way was to get the ALTERA university program (UP) IP cores. I added a RS232 UART component (from the UP) to a Qsys system and then used the HAL drivers (#include <altera_up_avalon_rs232.h>) supplied with the UP to receive and send data with a simple nios ii program.

    Open up the uart device:

    alt_up_rs232_dev *rs232_0_dev;

    rs232_0_dev=alt_up_rs232_open_dev("/dev/rs232_0");

    I then wait for data from the UART:

    while((alt_up_rs232_get_used_space_in_read_FIFO(rs232_0_dev))==0)

    {

    //wait for a character from the UART

    }

    Once a byte of data is ready i read it:

    alt_up_rs232_read_data(rs232_0_dev, &in_buffer[index1], &parity_read1)

    Writing data is similar, wait for free space in the UART outgoing buffer and send data:

    while(alt_up_rs232_get_available_space_in_write_FIFO(rs232_0_dev)==0)

    {

    //printf("waiting for space in out fifo\n");

    }

    //printf("after waiting for space in out fifo\n");

    if(alt_up_rs232_write_data(rs232_0_dev,temp1[index2])==0)

    {

    }

    A MUCH more elegant solution would be using nios ii interrupts, this simple example "blocks" the program until a specific amount of data is read (you have to wait for data before the program can do other things). In the university program folder you can find more examples using the UART core.

    --- Quote End ---

    Hi Fred,

    Thanks for your reply. What I want to do is Nios processor reads data from FPGA, Nios transmits the data to serial port and plot graph real time using Maltab,using de0 nano. I do not need to read data from serial port.

    1. I used the following code to access the UART component I created in Qsys, I connected the txdata pin to the oscilloscope and it shows nothing, i am wondering why couldn't I use IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE, txdata); to transmit data to UART?

    2. Quate "Writing data is similar, wait for free space in the UART outgoing buffer and send data:" When you said, send data, do you mean IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE, txdata)?

    I really hope to get some hints from you, been struggling for a while, thanks for your kind help.

    # include "altera_avalon_uart_regs.h"

    # define UART_BASE 0x00002000

    int main (void)

    {alt_u16 status, rxdata=0,aa=0, txdata=0;

    while (! (status & 0x0040)) // Wait for transmission completion

    status = IORD_ALTERA_AVALON_UART_STATUS (UART_BASE);

    printf("status= %.2f V \r\n", (float) status);

    rxdata = 5; // assuming I get this data by accessing sdram in Nios

    txdata = rxdata;

    IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE, txdata);

    printf("txdata= %.2f V \r\n", (float) txdata);

    return 0;}