One Wire Search ROM

spinnaker

Joined Oct 29, 2009
7,830
Looks like it might be an issue with your compiler. You are going to have to investigate on your own.

My guess it that your compiler does not allow you to pass by function.


You could try creating your own test program and see if it compiles.

Code:
struct test_struct
{
   int x;
   int y;   

};

void test(struct test_struct t)
{
   int x;
  int y;

  x = t.x;
  y = t.y;


}

void main()
{
  struct test_struct a;
   
  test(a);


}

I also realized that I used some variables that are declared on use. My compiler works fine with them but others might choke. I will get those updates changed soon but investigate your structure issue. If I have to I can pass by value. You might check that generic pointer thing. That is very strange and I have never seen that.

Are you certain you have the latest version of your compiler?
 

Thread Starter

sevenfold4

Joined Jan 12, 2015
80
Looks like it might be an issue with your compiler. You are going to have to investigate on your own.

My guess it that your compiler does not allow you to pass by function.


You could try creating your own test program and see if it compiles.

Code:
struct test_struct
{
   int x;
   int y;

};

void test(struct test_struct t)
{
   int x;
  int y;

  x = t.x;
  y = t.y;


}

void main()
{
  struct test_struct a;

  test(a);


}

I also realized that I used some variables that are declared on use. My compiler works fine with them but others might choke. I will get those updates changed soon but investigate your structure issue. If I have to I can pass by value. You might check that generic pointer thing. That is very strange and I have never seen that.

Are you certain you have the latest version of your compiler?
I have the latest release version of SDCC, i guess i could try snapshot.

When running the test code you gave me i got


Code:
C:\sdcc\code\final>sdcc test.c
test.c:9: error 97: SDCC cannot pass structure '_t' as function argument
test.c:9: error 97: SDCC cannot pass structure '_test_PARM_1' as function argument
I made it pass a pointer instead
Then i got this


Code:
C:\sdcc\code\final>sdcc test.c
test.c:13: error 25: Structure/Union expected left of '.->'
test.c:14: error 25: Structure/Union expected left of '.->'
i turned

x = t.x;
y = t.y;

into

x = t->x;
y = t->y;

and now i get
Code:
C:\sdcc\code\final>sdcc test.c
test.c:23: error 97: SDCC cannot pass structure '' as function argument
And i have not managed to understand that yet, since it just shows empty

Code:
struct test_struct
{
   int x;
   int y;

};

void test(struct test_struct *t)
{
   int x;
  int y;

  x = t->x;
  y = t->y;


}

void main()
{
  struct test_struct *a;

  test(*a);


}
This compiles

Code:
    struct test_struct
    {
       int x;
       int y;

    };
    typedef struct test_struct SC;
    void test(struct test_struct *t)
    {
       int x;
      int y;

      x = t->x;
      y = t->y;


    }

    void main()
    {
        SC mode;  
        test(&mode);
Another thing, that i am wondering about.
Code:
#define DSOWTherm_searchSensors(cb) OW_search(OW_SEARCHOWrom, cb)
How does it get the OW_search from that?
Sorry, there is a lot of new stuff you have given me and it is a lot to digest.
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
I will change to pass by pointer Probably never for small micros anyway. Might take me a day or so and I will upload the updates.

Read up on macro defines in C. Very useful.
 

Thread Starter

sevenfold4

Joined Jan 12, 2015
80
I will change to pass by pointer Probably never for small micros anyway. Might take me a day or so and I will upload the updates.

Read up on macro defines in C. Very useful.
But where does it get the search function, if it is not in your main nor any of your headers?
 

spinnaker

Joined Oct 29, 2009
7,830
But where does it get the search function, if it is not in your main nor any of your headers?

You provide it to the search function. Look at the help file for
DSOWTherm_searchSensors


There is a sample there of how to call the function.

Code:
void GetDevice(struct OW_ROM *OWrom, unsigned int count)
{
   memcpy((void*) &OW_deviceList[count - 1], (void*) OWrom, sizeof (struct OW_ROM));
}


void main()
{
      ............
     .............
      totalDevices = DSOWTherm_searchSensors(GetDevice);
      ........
      .......
}
You provide the GetDevice function. You can call it what ever you want and do with it what ever you want. As it finds each sensor your callback function is called. That is what a callback function does.


Here is the latest version. Everything is pass by pointer. I updated the sample to reflect the change.


On the last version I did a "replace all" for some things and screwed a couple things up. I was shocked it worked for me! :)
 

Attachments

Thread Starter

sevenfold4

Joined Jan 12, 2015
80
So after reading, and still not getting it to work, i decided to go back to good'ol OW_searchRom. I removed all those damn structures and pointers and got it to work.
I am simply using the same buffer what is inside of it to print out the values.

Thank you for all the time you have wasted on me. It sure was a crazy journey :)
I will investigate it further in the future, but not with SDCC.
 

spinnaker

Joined Oct 29, 2009
7,830
You have to be doing something wrong. Or it is just a minor issue. I find it hard to believe you compiler does not support pass structures by pointer.

Post your code and the error. I will try and download SDCC over the weekend to see if I see and issues.
 

Thread Starter

sevenfold4

Joined Jan 12, 2015
80
You have to be doing something wrong. Or it is just a minor issue. I find it hard to believe you compiler does not support pass structures by pointer.



Post your code and the error. I will try and download SDCC over the weekend to see if I see and issues.

http://comments.gmane.org/gmane.comp.compilers.sdcc.user/2495

Of course it is me, i have no previous experience with using struct and pointers for funtions (only for LCD)
I removed everything else, and only using the OW_search to get the number of devices and ROM codes.
After i have gotten more familiar with structs and pointers i will try again with them.

I did run into a very, very funny problem tho. After 32 degrees, it jumps down to 16.


Code:
d=        -(((~values[1]<<7)+~values[0])); //original value
            //d=-((values[6])<<0);
            sign= sign & 0x8000; //get sign value
            d=d*0.0625; //12 bit precision

If i have a simple MSB + LSB i get a wrong answer, however, if i use the test value (+85) it is right, but with the calculation i show you, it is wrong...(I believe /12 because default mode is 12 bits)

I did testing with different bits and stuff, but i just can not figure it out.

The read buffer function to get values

Code:
int OW_readBuffer(unsigned char *buffer, long count)
{
  
    int i;
    for(i=0; i<count; i++)
        buffer[i] = ~OW_readByte();
  
    crc8 = 0;

    for(i=0; i<count-1; i++)
        docrc8(buffer[i]);

    buffcrc = buffer[count-1];
     
     if (buffcrc != crc8)
         return OW_CRCERROR;
     else
         return OW_SUCCESS;
}


The readByte gets inverted because of the hardware.

It is really weird, because from your code and from other people codes i see that i simply should just add them
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830

spinnaker

Joined Oct 29, 2009
7,830
Wow SDCC sure is picky. :)

Take a look at the enclosed file. It should work now. Cleaned up a lot of additional code. I had references to XC8 where I should not. New version should co,pile for you now. It did for me.


Here is a sample code for some of the calls:

Code:
struct OW_ROM OW_deviceList[10];
int totalDevices;


void GetDevice(struct OW_ROM *OWrom, unsigned int count)
{
  memcpy((void*) &OW_deviceList[count - 1], (void*) OWrom, sizeof (struct OW_ROM));
}

void main()
{
  struct OW_ROM *OWrom;

  totalDevices =  DSOWTherm_searchSensors(GetDevice);


  OWrom = &(OW_deviceList[0]);

   // You want a delay here.  See sample code.

  DSOWTherm_convertSpecific(OWrom);


}
 

Attachments

Thread Starter

sevenfold4

Joined Jan 12, 2015
80
Wow SDCC sure is picky. :)

Take a look at the enclosed file. It should work now. Cleaned up a lot of additional code. I had references to XC8 where I should not. New version should co,pile for you now. It did for me.


Here is a sample code for some of the calls:

Code:
struct OW_ROM OW_deviceList[10];
int totalDevices;


void GetDevice(struct OW_ROM *OWrom, unsigned int count)
{
  memcpy((void*) &OW_deviceList[count - 1], (void*) OWrom, sizeof (struct OW_ROM));
}

void main()
{
  struct OW_ROM *OWrom;

  totalDevices =  DSOWTherm_searchSensors(GetDevice);


  OWrom = &(OW_deviceList[0]);

   // You want a delay here.  See sample code.

  DSOWTherm_convertSpecific(OWrom);


}
I will try it as soon as i have a time window. Thanks.
Could you explain me something tho.
Since i did not get my own temperature calculation to work and i took yours
Code:
(unsigned)(values[1] << 8) | values[0];
Why does this work? I thought it's MSB+LSB /12(in this case)
and when i did it, it was kinda working, don't know if correctly(it seemed right) but after 32 it jumped to 24, which was because LSB overflowed or something and MSB went from 16 to 24.
 

spinnaker

Joined Oct 29, 2009
7,830
You need to look at your datasheet. Some sensors 7 bits for the whole number an 4 for the decimal. Others have 7 for the whole number and 1 bit for the decimal.

So for my particular sensor I shift 1 to the right.

unsigned integerPart = result.temperature >> 1;

to get the whole number part. I have not yet complete the sample code for negative value but basically test the negative bit and invert. I will come up with a sample later. Really not felling well right now.


Here is how to get the fraction or decimal part with one bit fraction.

unsigned fractPart = ((result.temperature & 0b00000001) * 5);
 

Thread Starter

sevenfold4

Joined Jan 12, 2015
80
You need to look at your datasheet. Some sensors 7 bits for the whole number an 4 for the decimal. Others have 7 for the whole number and 1 bit for the decimal.

So for my particular sensor I shift 1 to the right.

unsigned integerPart = result.temperature >> 1;

to get the whole number part. I have not yet complete the sample code for negative value but basically test the negative bit and invert. I will come up with a sample later. Really not felling well right now.


Here is how to get the fraction or decimal part with one bit fraction.

unsigned fractPart = ((result.temperature & 0b00000001) * 5);
I actually managed to get the float to work. SDCC is just made for small memories, but using --model-large i can access all the memory i need, which the kit i have has enough.
 
Top