Forum Discussion

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

RS232 interface, DE2-70 board

Can someone please help me? I have two weeks left in my senior design project and have to interface a Doran 2200 Scale to an Altera DE2-70 board using RS232. I have the configuration set-up on the board and have the scale transmitting data to the board (I know this based off the blinking LED that is telling me data is being received). I am using C code to run on a softcore processor that I have put in the FPGA and need to read data from the RS232 port. I have this code written so far;

Insert

Code:

void get_weight_from_uart(char * weight){ FILE* fp; char in_char = 0; int pointer = 0; fp = fopen ("/dev/RS232", "r+"); //Open file for reading and writing if (fp ==0) { printf("error"); } if (fp) { while (1) { in_char = fgetc(fp); // Get a character from the UART. // if ((in_char == '\n') | (in_char == '\r') | (in_char == 0)) // { // fclose (fp); // return; // } // else // { weight[pointer++] = in_char; printf("0%0x\n",weight); delay(1000); // } } fclose (fp); } // return 0;}

However when I read the data from those ports, I get the same thing printing over and over again which is;

05ffffa8

I am not sure whether or not I have the correct code written or why I am getting the same thing. Please advise.

Thanks.

Duffbuster

7 Replies

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

    Sorry code got screwed up here it is ;

    void get_weight_from_uart(char * weight)

    {

    FILE* fp;

    char in_char = 0;

    int pointer = 0;

    fp = fopen ("/dev/RS232", "r+"); //Open file for reading and writing

    if (fp ==0)

    {

    printf("error");

    }

    if (fp)

    {

    while (1)

    {

    in_char = fgetc(fp); // Get a character from the UART.

    // if ((in_char == '\n') | (in_char == '\r') | (in_char == 0))

    // {

    // fclose (fp);

    // return;

    // }

    // else

    // {

    weight[pointer++] = in_char;

    printf("0%0x\n",weight);

    delay(1000);

    // }

    }

    fclose (fp);

    }

    // return 0;

    }

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

    Your printf code

    > printf( "0%0x\n",weight);

    prints “weight” which is the address of a char array. It should be always the same value.

    If you want to print the received characters, try to replace the printf with

    printf( "0%0x\n",in_char); or printf( "0%0x\n",weight[pointer-1]);
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for the help I had a friend look at it as well and we came up with a working code for those that would need help from these posts, the code came out as below which is a function that I called in my main program to give back the weight;

    void

    get_weight_from_uart(char * weight)

    {

    FILE* fp;

    char in_char = 0;

    int pointer = 0;

    fp = fopen ("/dev/RS232", "r+"); //Open file for reading and writing

    if (fp ==0)

    {

    printf("error");

    }

    if (fp)

    {

    while (1)

    {

    in_char = fgetc(fp); // Get a character from the UART.

    if ((in_char == '\n') | (in_char == '^') | (in_char == 0))

    {

    weight[pointer] = 0;

    fclose (fp);

    return;

    }

    else

    {

    weight[pointer++] = in_char;

    // weight[pointer] = 0;

    // printf(weight);

    // delay(1000);

    }

    }

    fclose (fp);

    }

    // return 0;

    }

    Thanks for the help.

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

    hello

    i am new at all of this,am also using a de2-70 board for my senior project. i want to use rs232 as input to the board and i have no idea how to do that !!!

    could u pliz tell me how did u do the configuration set-up on the board and the scale transmitting data to the board .

    also how u did u do the interface between RS232 and the Doran 2200 Scale??

    i hope u did well in your project .....
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Unfortunately I cannot explain all of what I did here. It took a lot of time but I can tell you some things that should help. First I would suggest truly reading the entire manual for the DE2-70 board. That helped me an extreme amount. Second if you are trying to interface with a Doran scale I would suggest reading that entire manual as well (that one is a long one). This again is very time consuming and you will have to probably read them over again but it helps a great deal.

    For setting up the RS-232 port I used the SOPC builder and generated a soft core processor in which I added the RS232 input. There are some demos on the altera site that helped as well but you will have to dig for them they don't just pop out.

    Once you learn all those things from the manuals and demos you will have to make sure that you read the section for the data transmitting in the Doran scale carefully and ensure you are using the correct outputs (I had to switch mine because the manual is not very clear and I think it might be wrong can't remember though). So call Doran if you have issues and they should be able to help.

    Hope this helps and sorry but it's something that is just going to take some research and time unless I was right there next to you.

    Good Luck! If you have any more questions later that I could help with, let me know and I will try.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    thank you for your replay

    i want to ask about SOPC , what software do i need to use ???do i need to install altera moniter program and is there any other program that i can work with ??

    and how i will integrate the SOPC builder to my project ??

    and i use this program it gave me this error Using cable "USB-Blaster [USB-0]", device 1, instance 0x00

    Resetting and pausing target processor: FAILED

    Leaving target processor paused...

    thnx for help.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I used the Quartus II software which has SOPC builder in it. However, I am not sure what changes they have made to the software since then so not sure what options are available. If you go here:

    http://www.altera.com/products/software/sfw-index.jsp

    you can download the software off the Altera site. Although again I am not sure if the free web edition will give you access to the SOPC builder. The link below this has a lot of information on SOPC builder

    http://www.altera.com/support/software/system/sopc/sof-sopc_builder.html

    The error seems like you don't have the correct type of cable configured in your software (my inital guess without looking at it). There are multiple types of cables to use for the jtag including RS232 and USB. Some troubleshooting techniques:

    1. Check cable connection is correct on both ends and you don't have them flipped or inverted.

    2. Check to make sure your PC is recognizing the cable

    3. Make sure your software is communicating with your cable.

    4. Ensure your software is configured correctly.

    Hope this helps you. I would suggest getting familiar with the Altera support section. They do a pretty good job of explaining a lot of their products and how to configure things.