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

s120 with TWI

I'm trying to use the TWI master example with the S120 soft device. It looks like there is a known problem trying to get the S110 working with the hardware TWI. It seems the TWI doesn't play well with the S120 either. I found this thread to get it working with the S110:

devzone.nordicsemi.com/.../

I tried the fix, but it doesn't seem to work with the S120. The TWI initializes now, but when I try to perform a read, it's causing a hard fault.

Does anyone know how to get the TWI master example working with the S120?

  • The TWI master example is set up to access the PPI registers directly without checking if the SoftDevice is enabled. When the softdevice is enabled, the sd_ppi_x functions must be used, as accessing the registers directly causes a HardFault.

    The attached hal_twi library will check to see if the SoftDevice is enabled and access the registers or SoftDevice API accordingly. I've also attached a driver file that utilizes the hal_twi library to access a IMU sensor as an example of use.

    Audun

  • That doesn't seem to work. My SDA line keeps getting stuck low for some reason, which doesn't happen with the twi_master code. Here is the init code:

    hal_twi_init_t twi_params;

    // 2-Wire initialization twi_params.scl_pin = TWI_CLK_PIN; twi_params.sda_pin = TWI_SDA_PIN; twi_params.frequency = hal_twi_freq_100khz; twi_params.ppi_chn = 3;

    hal_twi_init(&twi_params);

    After this I would think that SDA would be high, but it isn't. If I carry on with my code, sometimes it goes high, and tries to read data, but after transferring one byte (the device address), SDA sticks low again. If I erase the chip, and program my old code again, it works fine, so I don't think it's the device I am trying to talk to. I also checked to make sure that I'm using the same pins, and I am.

    Can you offer any other suggestions?

  • Oh, one difference between the two I forgot to mention is that the hal_twi code doesn't configure any pull-ups on the TWI pins. The design it's originally used in has 4.7 kOhm external pull resistors on the SDA and SCL lines. Does your design have any external pull resistors? If not, try configuring the pins with GPIO_PIN_CNF_PULL_Pullup instead of GPIO_PIN_CNF_PULL_Disabled.

  • We are using pull-ups, so that isn't the issue. After some close examination of the data on a scope, it looks like the S120 API isn't sending the register address correctly. The device address goes fine, but there is one less clock pulse than there should be. The last pulse is for the peripheral to ACK that it has received the last byte (the register address). It looks like the peripheral is waiting forever for the last clock pulse, which never shows up. I believe the S120, or something else Nordic related, has control of the clock at this point. I think that ACK bit is part of the I2C standard, so I wouldn't guess this is a configuration issue.

    Is the S120 SWI interface broken?

Related