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

nrf9160 i2c bit-bang driver gives no output

Hello,

I want to implement an SMbus read block function. As this function seems to be not supported by hardware I want to try by modifying the i2c bit bang driver.

Unfortunately the stock bitbang driver seems to be unable to output any waveform. The code execution reaches i2c_gpio_set_scl and i2c_gpio_set_sda function from i2c_gpio.c

Is this driver supported by nrf9160? Did I miss any config option?

prj.conf:

CONFIG_STDOUT_CONSOLE=y
CONFIG_PRINTK=y

CONFIG_GPIO=y
CONFIG_I2C=y
CONFIG_I2C_GPIO=y
CONFIG_I2C_GPIO_2=y
CONFIG_I2C_GPIO_2_SCL_PIN=31
CONFIG_I2C_GPIO_2_SDA_PIN=30
CONFIG_I2C_GPIO_2_NAME="I2C_2"
CONFIG_I2C_GPIO_2_GPIO="GPIO_0"

The project is based on i2c_fujitsu_fram sample from zephyr repo. My goal is to get a WR+ACK using the bitbang driver.

Best regards,

Vlad

Parents Reply Children
  • You said that your code failed at i2c_gpio_set_sda() and  i2c_gpio_set_scl(), what do you mean by that? That the code stops the execution there or that the value written is not output on the SDA and SCL pins? Have you checked with a logic analyzer to confirm this?

    Best regards,

    Simon

  • You said that your code failed at i2c_gpio_set_sda() and  i2c_gpio_set_scl(), what do you mean by that? That the code stops the execution there or that the value written is not output on the SDA and SCL pins? 

    The code seems to run just fine. Those functions do not block/stop or crash.

    Have you checked with a logic analyzer to confirm this?

    Yes. There is literary no voltage level change on the pins.

    ___

    After some trials I found out that if those pins are configured as OUTPUT, I do get a waveform but it fails to read the ACK. It could be a GPIO config problem.

  • I tested the sample and I saw the same behavior as you. I connected a BME280 to the SCL and SDA pins and I could not see any activity (If I disconnected the BME280 I saw activity on the pins), but configuring them as output through gpio_pin_configure() in main.c solved the issue. 

    Then I tried to modify this I2C_scanner example to use bit-banging instead. When looking at the results on the logic analyzer, it seemed to work fine. The BME280 sensor sent an ACK on address 0x76. However, the nR9160 could not read the signal and the code failed, which I believe is because the SDA pin is configured as an output

    Take a look at this thread, which shows how to enable the input buffer of a GPIO even if it's configured to be output. This was for nRF52832, but I assume it will work with the nRF9160 as well. If you have problems implementing this, or it didn't work, please ask, and I will look into it.

    Best regards,

    Simon

  • I am impressed this problem has not been solved yet. I am working with nRF9160-DK and NCS 2.2.0 and have exactly the same problem. There is no output on the I2C pins P0.30 (SCL) and P0.29 (SDA).

  • Hi 

    This is not a driver that is tested to work with Nordic devices, and since most people use the I2C hardware driver providing a working bit banged driver hasn't really been a priority. 

    I would suggest following Simon's workaround. If that doesn't work for some reason please open a new ticket and we can have a look at it. 

    Best regards
    Torbjørn

Related