NRF5340 TWIM example code to communicate with nPM1300

Hello,

we want to control the nPM1300 from an NRF5340 without using Zephyr. Is there example code on

how to configure/control the TWIM driver for this? The NPMX archive seems to contain higher layers

of the stack, but I'm looking for the twim code, especially the transfer.

do you use TXRX/TXTX or just TX and RX TWIM types in the transfer?

Parents
  • We do not support FreeRTOS on nRF53 officially and I did not had time to experiment with it as we went all in with Zephyr RTOS. 

    But your question does not seem to be very specifically tied to the FreeRTOS.

    To perform a read operation as described in the nPM specification, you would need to set up a TXRX transfer. This involves a write operation (to send the 7-bit device address and 16-bit register address) followed by a read operation (to read 8 bits).Maybe you should do something like this, haven't tested this myself so use for template only.

    nrfx_twim_xfer_desc_t xfer_desc;
    xfer_desc.type = NRFX_TWIM_XFER_TXRX;
    xfer_desc.address = device_address;
    xfer_desc.primary_length = 3; // 7-bit device address + 16-bit register address
    xfer_desc.secondary_length = 1; // 8 bits to read
    xfer_desc.p_primary_buf = &write_buffer; // Buffer containing device and register addresses
    xfer_desc.p_secondary_buf = &read_buffer; // Buffer to store read data
    
    nrfx_err_t err_code = nrfx_twim_xfer(&twim_instance, &xfer_desc, flags);

  • I assume the nPM1300 works fine under Zephyr. Inside the Zephyr codebase the code seems spread out over an nPM1300 driver and an i2c driver. What I could find is that Zephyr didn't seem to use TXRX..

    Also I think the primary length should be 2 bytes, since the address is passed separately right?

  • Bas van den Berg said:
    What I could find is that Zephyr didn't seem to use TXRX..

    Yes, That seems true. Need to understand the code architecture to see how this is working in Zephyr.

    Bas van den Berg said:
    Also I think the primary length should be 2 bytes, since the address is passed separately right?

    Yup, you are right, my bad. 

Reply Children
No Data
Related