This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Definition of "Done" event for nrfx twim driver

I'm using the nrfx twim driver along with Zephyr.    I'm using the NRFX_TWIM_EVT_DONE to initiate a subsequent TWIM command and finding that the second command fails due to the TWIM still being busy.

I'm using version 1.5.0 of nRF Connect and nrfx v2.4.0

More detail:

I want to share a TWIM between multiple threads, each of which has its own I2C peripheral(s), but all using the same TWIM bus.

I created a Zephyr task that handles the operation of the TWIM.   It receives "jobs" via a Zephyr FIFO, from the threads that want to communicate with the I2C peripherals.   Since some peripheral operations can take significant time, this frees the CPU to do other things while the TWIM hardware clocks in/out the data.

When a "job" appears at the read end of the FIFO, the TWIM task starts the appropriate twim operation using the xfr_desc information passed in via the FIFO.    The TWIM task "stalls" using a k_poll() until the twim operation has completed.   When the completion event is received via the twim handler, it informs the requesting thread via a k_poll_signal_raise() and also sends a k_poll_signal_raise() to the TWIM task, which then loops back to check the FIFO for another "job".

I'm seeing that the signal indicating that the twim has completed is delivered to the TWIM task, allowing it to get another job from the FIFO.   But when it attempts to start the job, an error from the twim driver indicates that the twim is still busy.     Putting a loop:   while(nrfx_twim_is_busy(&twimInstance) == true);     fixes this (as a workaround), but in part defeats the purpose of my whole approach (as CPU cycles are used polling the twim).

Is there another event from the twim driver that indicates done-done (meaning really done, and the twim is free to start again)?

Thanks!

Parents Reply Children
Related