C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-02-2009, 12:11 PM   #1
Registered User
 
Join Date: May 2009
Posts: 2
Exclamation 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
duffbuster220 is offline   Reply With Quote
Old 05-02-2009, 12:46 PM   #2
Registered User
 
Join Date: Oct 2008
Location: TX
Posts: 1,262
The data read from the port maybe different each time but the code prints the location of weight over and over again, as in
Code:
printf("0%0x\n", weight);
itCbitC is offline   Reply With Quote
Old 05-02-2009, 01:03 PM   #3
Registered User
 
Join Date: May 2009
Posts: 2
Thanks for the quick response this is going to sound stupid because I am not very good with C but how do I print the values in weight?
duffbuster220 is offline   Reply With Quote
Old 05-02-2009, 01:22 PM   #4
Registered User
 
Join Date: Oct 2008
Location: TX
Posts: 1,262
Code:
printf("0%0x\n", weight[pointer-1]);

Last edited by itCbitC; 05-02-2009 at 01:24 PM.
itCbitC is offline   Reply With Quote
Reply

Tags
c code, embedded, rs232

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
function trouble rebel C++ Programming 4 12-21-2005 05:23 AM
Pick a number.... Salem A Brief History of Cprogramming.com 39 01-19-2003 07:27 AM
Isn't the C Board a cool name? DavidP A Brief History of Cprogramming.com 18 12-23-2002 01:09 PM
Considering shutting down the General Discussions board webmaster A Brief History of Cprogramming.com 59 09-26-2002 08:41 PM


All times are GMT -6. The time now is 07:43 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22