bouffalolab / bl_iot_sdk

BL602/BL702 SDK. Any technical topic, please access the following link.
http://bbs.bouffalolab.com
Apache License 2.0
267 stars 172 forks source link

I2C is not waiting to END when NACK happens #21

Open gamelaster opened 3 years ago

gamelaster commented 3 years ago

Related to this post on BBS, I found the reason why this happens. Here when NACK happens, it calls i2c_callback which disables all interrupts and generally the I2C. Anyway, at that time, the I2C BUSY flag is still true, and there is not possible to immediately make another I2C transmission.

When we don't disable I2C on NACK, the flow is following: I2C_TXF_INT > I2C_NAK_INT > I2C_NAK_INT > I2C_END_INT (and now is BUSY flag false). So my solution is after NACK happen, don't disable interrupts or I2C, just set status and wait for END interrupt. Then everything works like charm.

YafeiJin commented 3 years ago

@gamelaster Thanks, we will fix this issue soon

gamelaster commented 3 years ago

Thank you 😊 Also, don't use i2c_set_freq function, use I2C_ClockSet instead, since i2c_set_freq don't set all clocks.

YafeiJin commented 3 years ago

@gamelaster Please provide your sample code to reproduce this issue. Cause there are different levels of API in SDK. Thanks

gamelaster commented 3 years ago

@YafeiJin the i2c_set_freq API doesn't work wrongly, it correctly sets the registers, but not all of them (and also, it doesn't check for current hclk freq). It doesn't use GLB_Set_I2C_CLK, so it's not possible to get higher I2C frequencies. Example: i2c_set_freq(0, 100); // 100 KHz image (As you can see, the clock frequency is barely 1000 Hz) But when using I2C_ClockSet: I2C_ClockSet(0, 100000) image (Now, there is everything OK)

YafeiJin commented 3 years ago

image Please try again by switching params

gamelaster commented 3 years ago

@YafeiJin Ah yes, I'm blind 😁 thank you

robertlipe commented 1 year ago

Should this be closed? Should this be documented (or enforced) to take a better argument than "int" ?