0
\$\begingroup\$

I am interfacing HDC1000 with STM32F303VC. My I2C code works in Debugging mode only. Other Blinky and UART code works properly. Write works perfectly but, Read function code stuck here:

while(I2C_GetFlagStatus(HDC_I2C, I2C_ISR_RXNE) != SET)
{
    if((HDC_Timeout--) == 0) 
        continue; 
    return HDC_TIMEOUT_UserCallback();
}

I have selected correct CPU. I am using Coocox IDE. Please find my code and appreciate help. 10Kohms pull ups connected on both SDA and SCL lines.

\$\endgroup\$

closed as unclear what you're asking by Scott Seidman, Daniel Grillo, Transistor, uint128_t, Tom Carpenter Mar 11 '16 at 4:26

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ "Please find my code". Any idea where you last had it? That is usually the best place to look for it. Alas I'm not sure where it could be. \$\endgroup\$ – Tom Carpenter Mar 11 '16 at 4:25
2
\$\begingroup\$

That loop will simply not work. The HDC_TIMEOUT_UserCallback() gets called on the first itertion if HDC_Timeout is non-zero, and on the second one if it is zero. Whoever created this one never tried it on real hardware.

It may work in single-step debugging because the I2C_ISR_RXNE flag will be set before this code is executed, and the while() condition is already false.

Note that there is not only the condition inverted in the if () but also no significant delay between loop cycles.

\$\endgroup\$
  • \$\begingroup\$ Yes it is not working on hardware. Only works in Single step debug mode. I used the example or Demo code. Same conditions works well with LSM303DLHC Accelerometer.There is no Continue in the code. /* Wait until RXNE flag is set */ HDC_Timeout = HDC_LONG_TIMEOUT; while(I2C_GetFlagStatus(HDC_I2C, I2C_ISR_RXNE) == RESET) { if((HDC_Timeout--) == 0) return HDC_TIMEOUT_UserCallback(); } \$\endgroup\$ – Kumar Naveen Mar 10 '16 at 11:42
  • \$\begingroup\$ You do realisze that the if condition is inversed without the continue? You do realize that HDC_Timeout counts roughly as fast as Sysclock/10? \$\endgroup\$ – Turbo J Mar 10 '16 at 13:32
  • \$\begingroup\$ Ok. If I removed if condition and HDC_Timeout Counts, It will wait infinitely till the RXNE = SET. It doesn't matter of Timeout Sysclock/10 or quick. My code hangs at this point I2C_GetFlagStatus(HDC_I2C, I2C_ISR_RXNE) == RESET \$\endgroup\$ – Kumar Naveen Mar 11 '16 at 4:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.