Microchip-MPLAB-Harmony / core

Harmony 3 Core
https://onlinedocs.microchip.com/v2/keyword-lookup?keyword=MH3_core&redirect=true
Other
16 stars 12 forks source link

DRV_I2C_WriteReadTransferAdd returns invalid handle after a few seconds #2

Closed LuisCRSousa closed 4 years ago

LuisCRSousa commented 5 years ago

I'm controlling a touch panel with i2C. It works but after a few seconds, DRV_I2C_WriteReadTransferAdd returns me an invalid DRV_I2C_TRANSFER_HANDLE.

I've done everything to workaround it by reseting the I2C driver, read the errata and implemented the 3 solutions for some problem that may occur and till now I'm stuck.

I've debugging the application and found that the problem may reside in the following function at drv_i2c.c static DRV_I2C_TRANSFER_OBJ _DRV_I2C_FreeTransferObjGet(DRV_I2C_CLIENT_OBJ clientObj).

This function returns NULL when the bug occurs.

When the function returns null, SDA pulls down forever. If I reset ON flag at I2C3CON the SDA retuirns high, but after setting this flag again, DRV_I2C_WriteReadTransferAdd returns invalid handle again.

arpananand1 commented 5 years ago

what is your I2C driver queue size? try increasing that in MHC, regenerate code and see if things improve.

LuisCRSousa commented 5 years ago

Already tried it. Default was 2, increased to 10. Same thing

LuisCRSousa commented 5 years ago

Made it work with the blocking functions unfortunatly. But..

Had to use the blocking functions on a while loop till they returned true because if I called a DRV_I2C_WriteTransfer after a DRV_I2C_WriteReadTransfer, the former would return false at first call.. Is this normal?

while (DRV_I2C_WriteReadTransfer(goodix911Data.drvI2CHandle, GOODIX911_SLAVE_ADDR, (void) &goodix911Data.registerAddr, 2, (void) &goodix911Data.rxBuffer, 1) == false){}

//process data

while (DRV_I2C_WriteTransfer(goodix911Data.drvI2CHandle, GOODIX911_SLAVE_ADDR, (void*) &goodix911Data.txBuffer, 3) == false){} goodix911Data.state = GOODIX911_STATE_IDLE;

LuisCRSousa commented 5 years ago

I experienced some problems with the example above still...

I'm working with pic32mz2048dab288 and I2C3. I heard these chips had problems on this i2c interface before. Is this port still problematic?

LuisCRSousa commented 5 years ago

Made the same examples with I2C4, same problems.

The only way that I made it work properly was to call just once per cycle the blocking function DRV_I2C_WriteReadTransfer, reading all consecutives registers.

Still wanted to know why can't make it work with the async functions and why _DRV_I2C_FreeTransferObjGet returns false..

vishalgandhi commented 5 years ago

@LuisCRSousa , can you please share your I2C based projects that uses the Asynchronous and Synchronous I2C driver? For the Synchronous driver, did you enable RTOS? Synchronous drivers currently only work in RTOS environment.

LuisCRSousa commented 5 years ago

I didn't enabled RTOS, but it worked..

Please give me a contact to share it with you,

I created a project from scratch, and now it worked with async methods.. I'm trying to compare harmony generated files trying to find any differences.

LuisCRSousa commented 5 years ago

Found the issue after diffmerge every file :)

Using gcc otimization 0 crashes the I2C port async methods after a few seconds (10-20). It works using otimization 1.

Any explanation for this?

aethaniel commented 4 years ago

@LuisCRSousa, @vishalgandhi, I don't see more follow up on this issue here. Can I close it?