Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For what you say I can only think of 3 possibilities: 1) your assumption that the function is being called on every I2C communication is incorrect, 2) your program has a bug (maybe a memory leak) in some unrelated function which causes the variable <strong>calls</strong> to become corrupted. or 3) two or more threads are calling your function simultaneously and <strong>calls</strong> is being incremented in a different way than you expect, use <strong>></strong> instead of <strong>==</strong>, if this solves the problem, then you are running in a milti-threaded environment and you didn't konw.</p> <p>You need an accurate method to know the exact value of <strong>calls</strong>, if you don't have a debugger and don't have the means to output text either, the only thing you have left to play is time. I don't know you compiler, but I am sure it contains some useful timing functions, so what I would do would be to loop before increment for 10+calls seconds, and after increment again 10+calls seconds, for example:</p> <pre><code>sleep(1000*(10+calls)); ++calls; sleep(1000*(10+calls)); if(calls&gt;8){ // your actual code } </code></pre> <p>I would (chronometer in hand) expect a delay of (10+0 plus 10+1) = 21 seconds on the first call, 23 seconds on the second call, 25 in the third and so on. That way I could be sure the value of <strong>calls</strong> started with 0 and then it was progressively increased until 9.</p> <p>Also, you must test for what you expect not for what you don't expect, so instead of doing this:</p> <pre><code>++calls; if (calls==0) while (1); </code></pre> <p>do this:</p> <pre><code>++calls; if (calls==1) while (1); </code></pre> <p>that way if your program hangs you can be sure the value of <strong>calls</strong> is exactly 1, and not whatever different from zero. If you count one valid I2C communication and your program hangs then the transition from 0 to 1 was done correctly, so change the hang statement accordingly:</p> <pre><code>++calls; if (calls==2) while (1); </code></pre> <p>Again, if you count 2 valid I2C communications before your program hangs that means that the transition from 1 to 2 was correct, and so on.</p> <p>Another suggestion, try this:</p> <pre><code>uint8_t Times(void){ static uint8_t calls = 0; return ++calls; } void callback(void){ if (Times()&gt;8) { // Your actual code } } </code></pre> <p>And this:</p> <pre><code>void callback(void){ static uint8_t calls = 0; if (calls++&gt;7) { // some code. } } </code></pre> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload