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

Multiple TWI-instances SDK 11

Hi,

I'm currently running two separate TWI-instances on my nRF52 DK with SDK 11.

Each instance runs quite well with no issue, except for when instance 1 becomes active (it either reads or writes); the SDA-line on instance 0 becomes permanently low.

For clarity, I'm wondering why the SDA-line on TWI-instance 0 is going permanently low after the TWI-instance 1 has performed a read/write operation.

I have a Saleae 16 logic analyzer at hand, if needed, I can provide with some captures.

Here is my code for TWI-instance 0:

    static const nrf_drv_twi_t twi_motor = NRF_DRV_TWI_INSTANCE(0);
    const nrf_drv_twi_config_t twi_motor_config = {
      .scl                = SCL_MOTOR_PIN,                     // SCL_MOTOR_PIN = 27
      .sda                = SDA_MOTOR_PIN,                   // SDA_MOTOR_PIN = 26
      .frequency          = NRF_TWI_FREQ_100K,
      .interrupt_priority = TWI0_CONFIG_IRQ_PRIORITY
   };

   nrf_drv_twi_init(&twi_motor, &twi_motor_config, NULL, NULL);

   nrf_drv_twi_enable(&twi_motor);

Here is my code for TWI-instance 1:

static const nrf_drv_twi_t twi_rfid = NRF_DRV_TWI_INSTANCE(1);

 const nrf_drv_twi_config_t twi_rfid_config = {
      .scl                = SCL_RFID_PIN,                              //SCL_RFID_PIN = 25
      .sda                = SDA_RFID_PIN,                            //SDA_RFID_PIN = 24
      .frequency          = NRF_TWI_FREQ_100K,
      .interrupt_priority = TWI1_CONFIG_IRQ_PRIORITY
   };

   nrf_drv_twi_init(&twi_rfid, &twi_rfid_config, NULL, NULL);

   nrf_drv_twi_enable(&twi_rfid);

Here is my configuration in nrf_drv_config.h:

#define TWI0_ENABLED 1

#if (TWI0_ENABLED == 1)
#define TWI0_USE_EASY_DMA 0

#define TWI0_CONFIG_FREQUENCY     NRF_TWI_FREQ_100K
#define TWI0_CONFIG_SCL           0x1b
#define TWI0_CONFIG_SDA           0x1a
#define TWI0_CONFIG_IRQ_PRIORITY  1

#define TWI0_INSTANCE_INDEX      0
#endif

#define TWI1_ENABLED 1

#if (TWI1_ENABLED == 1)
#define TWI1_USE_EASY_DMA 0

#define TWI1_CONFIG_FREQUENCY    NRF_TWI_FREQ_100K
#define TWI1_CONFIG_SCL          0x19
#define TWI1_CONFIG_SDA          0x18
#define TWI1_CONFIG_IRQ_PRIORITY 3

#define TWI1_INSTANCE_INDEX      (TWI0_ENABLED)
#endif

#define TWI_COUNT                (TWI0_ENABLED + TWI1_ENABLED)
Parents
  • The issue has been resolved.

    If you have the same issue, make sure to assign enough bytes for reading the TWI-data. If you have any more questions about this issue, feel free to contact me.

  • As far as I know TWI0 does not have fixed SDA and SCL pins, I believe they can be freely defined. However, it's been a while since I worked with SDK 11.

    You can define SDA and SCL pins for a TWI-instance in two ways:

    1. Go to nrf_drv_config.h and change the defines (TWI1_CONFIG_SCL and TWI1_CONFIG_SDA) to whatever you like (either in hexadecimal (0x19) or decimal (25). It doesn't matter).

    2. Create a config, as you can see I did for my TWI instance 1. This will overwrite the values defined in nrf_drv_config.h as long as you apply the config to the nrf_drv_twi_init()-function.

Reply
  • As far as I know TWI0 does not have fixed SDA and SCL pins, I believe they can be freely defined. However, it's been a while since I worked with SDK 11.

    You can define SDA and SCL pins for a TWI-instance in two ways:

    1. Go to nrf_drv_config.h and change the defines (TWI1_CONFIG_SCL and TWI1_CONFIG_SDA) to whatever you like (either in hexadecimal (0x19) or decimal (25). It doesn't matter).

    2. Create a config, as you can see I did for my TWI instance 1. This will overwrite the values defined in nrf_drv_config.h as long as you apply the config to the nrf_drv_twi_init()-function.

Children
No Data
Related