Onewire interface

Hello again!

I am planning to do a onewire interface for this connectme. I plan using uart (and DS2480B chip) because programming a reliable software communications (using GPIO) even at speeds of 9600bps seems to be very hard.

Has anyone done something similar? Any recommendations how to use the uart? Just using ansi c functions to read / write from serial port (very slow?) or use directly the Serial API.

Secondly, because I’m not very experienced programmer, is there some clean or “right” way to do interprocess communication in C? What I thought it would be best that the 1-wire application would be running as it’s own thread and other applications could call it somehow. Through sockets perhaps? Any suggestions or pointers are welcome :slight_smile:

Ok. I was going for termios, but…

I have generated a simple web page, so i could use it to output some data.

I’ve started to generate my own functions under index_v.c, and ran into strange problems.

First, i cannot open a com port straight at index_v.c. If i do a following piece of code:

int fd;
fd = open(“/com/0”, O_RDWR);

The compiler cries about:
/pbuilder/html/index_v.c -o objs/index_v.o
…/pbuilder/html/index_v.c:21: warning: type defaults to int' in declaration of fd’
…/pbuilder/html/index_v.c:21: warning: implicit declaration of function `open’
…/pbuilder/html/index_v.c:21: initializer element is not constant
…/pbuilder/html/index_v.c:21: warning: data definition has no type or storage c
lass

So is this just a totally wrong place to do this?

Second, i was going to use pointers, because if i declare my own funtion and call it, i can use the above code in the function… But.

As from my early lessons in c, i defined
int initializeserial(int *ptr1);

and the code:

int filepointer;
filepointer=(int
)calloc(1,sizeof(int));

int alusta = initializeserial(int *filepointer);

This isn’t good either, i get:

/pbuilder/html/index_v.c -o objs/index_v.o
…/pbuilder/html/index_v.c:35: warning: type defaults to int' in declaration of filepointer’
…/pbuilder/html/index_v.c:35: conflicting types for filepointer' ../pbuilder/html/index_v.c:34: previous declaration of filepointer’
…/pbuilder/html/index_v.c:35: warning: implicit declaration of function `calloc

…/pbuilder/html/index_v.c:35: warning: initialization makes integer from pointe
r without a cast
…/pbuilder/html/index_v.c:35: initializer element is not constant
…/pbuilder/html/index_v.c:35: warning: data definition has no type or storage c
lass

I also tried passing an empty pointer, with no luck (thought about using malloc or calloc in my own function).

I am using upgraded dev kit, with gcc 3.2. Could this be cause of the newer gcc? Or is it just me… I’m not much of a programmer, but in this I think I am using quite simple things that have always worked (at least placing a return value in variable…)

sijuma00,

Have you included the appropriate header files into your index_v.c file? Specifically, you will need termios.h, netosIo.h and serParam.h.

The key indicator that this is your problem is the message, “warning: implicit declaration of function `open’”, which is generally caused by attempting to make use of a function that has not been prototyped.

Good luck.

D

Thank you very much!

I was indeed missing a one header, SerParams.h. Now world seems a little brighter :wink:

But more about gcc being not compatible with me…

I now have following includes in index_v.c
#include
#include
#include
#include

and for the code:

int fd;
fd = open(“/com/0”, O_RDWR); // This is line 28

I get:

/pbuilder/html/index_v.c -o objs/index_v.o
…/pbuilder/html/index_v.c:28: warning: type defaults to int' in declaration of fd’
…/pbuilder/html/index_v.c:28: warning: implicit declaration of function `open’
…/pbuilder/html/index_v.c:28: initializer element is not constant
…/pbuilder/html/index_v.c:28: warning: data definition has no type or storage c
lass

So it still says about implicit declaration of open, still missing an include?. And what in earth is trying to say the line: Initializer element is not constant?

And second one, line 43:

alusta = initializeserial((int *) filepointer);

I get:

…/pbuilder/html/index_v.c:43: warning: type defaults to int' in declaration of alusta’
…/pbuilder/html/index_v.c:43: initializer element is not constant
…/pbuilder/html/index_v.c:43: warning: data definition has no type or storage c
lass
make: *** [objs/index_v.o] Error 1

So clearly I am now doing something in a way that gcc doesn’t like. Any ideas?

To the latter error, i tried to first initialize the “alusta” with int alusta=0; and after that used

alusta = functionfoo(*ptr);

and when using this method it says I’m redefining the alusta… Though it’s just a warning, but why? My c-lessons were worth nothing? :wink:

Yup, the missing include was fcntl.h, so now only problem is that “initializer element is not constant”.

I tried defining the serial device as
const char SERIALDEV[]=“/com/0”, but it doesn’t like this either.

The API reference says following, but what kind of a pointer should i give to it - I can’t figure that out?

int open(const char * filename, int mode, …);

I can’t give it a single pointer, because array contains more than one pointer… And the example found in the headers and API reference fd = open(“/com/0”, O_RDWR) doesn’t work, as it says the same :confused:

Ok, I got it !

I putted your two lines :
"
int fd;
fd = open(“/com/0”, O_RDWR);
"
in my basic web server with the right header files and it works just fine !

Then I tried to understand your error message, and now I understand your problem :
You tried to open the serial port com 0 outside of any function (then initializing a global var with a function), and this is strictly forbiden in C.

So you just need to put your “fd = open(”/com/0", O_RDWR);" line in a “init” function and it will work perfectly well :slight_smile:

Tell us !

Thanks again!

I didn’t yet have time to try this, but I believe you’re right. I was a little confused because i did something similar before with no problems, but now when i checked it, all my own code was inside a initformpage() function (my page contained forms) and in this onewirething it is outside any function, just as you said :slight_smile:

So we’ll see if I can make this working :slight_smile: