cancel
Showing results for 
Search instead for 
Did you mean: 

HAL I2C library returning HAL_ERROR even though communications are succesfull

RBack.1
Senior

I am using the STM32F746VET6 with a project generated using MX v6.5.0.

I am using interfacing to several I2C chips in my project and they are operation correctly. When I started checking the return values from the HAL_I2C_Master_Receive() function, however, many of them are returning HAL_ERROR. Debugging the HAL_I2C_Master_Receive() is rather complicated, however.

Should I just go back to ignoring these return values? I don't like to do that sort of thing but there doesn't seem to be much opportunity to call these HAL functions differently and the chips are operating correctly.

3 REPLIES 3
KnarfB
Principal III

HAL_I2C_Master_Receive should not fail. You may have a patrly filled buffer on return, or you might even have the old data in the buffer in case of error. For any serious project, you should find (debug?) the root cause. You might want to set breakpoints at places where the error code is set/returned to speed up that process. Having a scope/LA handy is also a good idea. I2C timing (raise/fall times) might also cause errors.

hth

KnarfB

Thanks for your reply. I guess I'll check it out with a scope. I do have a huge ribbon cable on those lines so possibly the capacitance is too large for the size pull ups I'm using.

I started to debug this today and started checking the hi2c_bridge->ErrorCode value upon receiving HAL_ERROR as the return value for the function calls. Shouldn't hi2c_bridge->ErrorCode contain more info as to what caused the error? In each case it contains HAL_I2C_ERROR_NONE?