Data corrupted when passed to callback function!

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
The ongoing saga on my callback function issues. Thanks to John in this thread, I was able to get my code to compile but I am still having issues.


OW_search2 calls my callback function. But the data passed in the structure gets corrupted after it gets passed to the callback function cb.


And get this, if I don't define all of those other variables in OW_search2 the data gets passed correctly.

I am using the XC8 compiler V1.21.

Stack problems maybe?



Rich (BB code):
typedef  void *(OW_update_cb)( struct OW_info info, unsigned int count);

int OW_search2(unsigned char searchType, OW_update_cb update_cb)
{
    struct OW_info info;
    unsigned int count = 0;
 
    unsigned char* buffer = (unsigned char*)&info;

    int id_bit_number;
    int last_zero, rom_byte_number, search_result;
    int id_bit, cmp_id_bit;
    unsigned char rom_byte_mask, search_direction;
    // initialize for search


    OW_lastDiscrepancy = 0;
    OW_lastDeviceFlag = FALSE;
    OW_lastFamilyDiscrepancy = 0;
   


            count++;
            info.family = 16;

            for (int i=0; i<=5; i++)
                info.serialNum = i;

            info.crc = 20;

            update_cb(info, count);
            return 0;
}



void cb(struct OW_info info, unsigned int count)
{
    volatile int x = count;


}


 int count = OW_search2(OW_SEARCHROM,cb);
 
Top