This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Equation result is not as expected

Hello,

there is an equation in the code where I see that variable: deviceid is: 229 and var_temp is also: 229.

But the debugging shows that the Mikrocontroller is going into this if-case. I cant understand why. Both variables are uint8_t and have the same value.

  • I am using Segger-Embedded-Studio V3.30.
  • I am using SEGGER EDU
  • I am using NRF52832

I have downloaded the code into Mikrocontroller several times. So I am shure that the code in the mikrocontroller is the same code as I see in the Embedded-Studio IDE.

if (deviceid != var_temp)
{
  ret_eok |= ERROR_BIT_0;
}

Do you have any ideas what is going wrong?

  • And the equation also works If I add a whait time of 5ms before the if case code segment. At the moment I dont understand why I have to do this.

  • fairly obvious guess is that you've enabled the TWIM in non-blocking mode giving it a callback however you're using it as if it were in blocking mode in that code expecting the data to be available as soon as the twim rx call completes.

    That also explains why the debugger shows the values equal because, by the time you get to look at them in the debugger, the data has been transferred.

    If you want blocking mode then use that, if you want callback mode, put your code in the callback.

  • Yes that seems to be the explanation why the data is not available.

    But how can I know when the data is available? How can I use this feature what you call "the blocking mode" ?

  • please go and read the documentation on the twi handler you're using, it's very comprehensive and will tell you all about how to initialize the driver in blocking as opposed to non-blocking mode.

  • Thank you for your answer. Ok, of course I am going to read more about twi handler. But I am using TWIM0 (Twi Master) at the moment. And in this chapter of NRF52832 says nothing about Blocking Mode or something.

Related