Data corrupted when passed to callback function!

Discussion in 'Embedded Systems and Microcontrollers' started by spinnaker, Feb 27, 2014.

  1. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    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?



    Code ( (Unknown Language)):
    1.  
    2.  
    3. typedef  void *(OW_update_cb)( struct OW_info info, unsigned int count);
    4.  
    5. int OW_search2(unsigned char searchType, OW_update_cb update_cb)
    6. {
    7.     struct OW_info info;
    8.     unsigned int count = 0;
    9.  
    10.     unsigned char* buffer = (unsigned char*)&info;
    11.  
    12.     int id_bit_number;
    13.     int last_zero, rom_byte_number, search_result;
    14.     int id_bit, cmp_id_bit;
    15.     unsigned char rom_byte_mask, search_direction;
    16.     // initialize for search
    17.  
    18.  
    19.     OW_lastDiscrepancy = 0;
    20.     OW_lastDeviceFlag = FALSE;
    21.     OW_lastFamilyDiscrepancy = 0;
    22.    
    23.  
    24.  
    25.             count++;
    26.             info.family = 16;
    27.  
    28.             for (int i=0; i<=5; i++)
    29.                 info.serialNum[i] = i;
    30.  
    31.             info.crc = 20;
    32.  
    33.             update_cb(info, count);
    34.             return 0;
    35. }
    36.  
    37.  
    38.  
    39. void cb(struct OW_info info, unsigned int count)
    40. {
    41.     volatile int x = count;
    42.  
    43.  
    44. }
    45.  
    46.  
    47.  int count = OW_search2(OW_SEARCHROM,cb);
    48. [/i]
     
Loading...