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

nrfx and twis samples

I wasn't able to find sample code showing how to use the nrfx sdk to perform TWI slave.

Can you point me to some examples ?

Parents Reply Children
  • Thanks, looking at both the SDK and the migration guide, I start to see how to use TWI slave, still one question remains, how can I emit a NACK, for example, in case of a write to a read-only i2c register, or requesting a register that doesn't exists

  • I can't find a clear procedure to do this in the driver or in the peripheral documentation. You will have to handle this in the application, but since the TWIS peripheral use EasyDMA to read/write directly from/to RAM, there is no way to intercept the transfer between the register-address being written and the ACK being generated. You can stop a read operation if the slave does not support the register-address after the address-write, by stopping the peripheral, using the following function:

    nrf_twis_task_trigger(m_twis.p_reg,NRF_TWIS_TASK_STOP);

    Note that this does not prevent the master from performing the read, the master will have to detect and react to the NACKs and stop the transfer itself. This is a capture I did with the TWIS example:

  • I still need some clarifications in nrfx usage for twis:

    * evt_write_req and evt_write_done seems to be per write request, is there a way to prepare multiple time the dma rx buffer inside the same write request ? (for example a 2 bytes buffer used for the i2c register, and next allocate the right amount of memory for the following write in the same request)

    * I would like to perform some cleanup when the i2c transaction is stopped, but I don't see an event for that in the nrfx_twis_evt_type_t , is there a way to do it.  (start write / data / start read / data / stop <wanted_callback_here>)

  • Stephane D'Alu said:
    is there a way to prepare multiple time the dma rx buffer inside the same write request

    No, the TWIS peripheral is designed to allow reading/writing without CPU intervention, in case the CPU is busy with handling timing-critical radio events. It will only allow you to prepare one TX and one RX buffer. Is the TWI master not able to do this in two separate requests?

    Stephane D'Alu said:
    I would like to perform some cleanup when the i2c transaction is stopped, but I don't see an event for that in the nrfx_twis_evt_type_t , is there a way to do it.

    If by stopped you mean after you trigger the STOP_TASK as discussed before? The driver does not provide any events for this, as it is not expected behavior in the driver. In fact, triggering the STOP_TASK while the driver is active may leave the driver state-machine in an unknown state. The driver only provides events for transfer done and detected errors. If you want an event in the driver for the STOPPED event, you need to catch this in the interrupt handler in the TWIS driver and pass a custom-defined event to the application.

  • I was looking for a callback for the i2c stop bit. as it doesn't seem possible to know which NRFX_TWIS_EVT_{READ,WRITE}_DONE is the last one in the i2c transaction (assuming repeated start).
    Perhaps what I'm looking matches the driver STOPPED event? So if I understand you, in this case I need to patch the nrfx_twis_state_machine ?

Related