I2C on nRF5340 Issues #i2c #driver #nrf5340


Marciano
 

I am attempting to write a basic I2C program using Zephyr, but I am currently unable to sent a single byte over I2C. The program hangs after the first clock falling & rising edge.

I'm using external 1K pullups, and have a BME680 device on the other end. I observe the same behavior on the bus with or without the BME680 device.

Am I doing something wrong?

 


prj.conf

CONFIG_NEWLIB_LIBC=y

CONFIG_PRINTK=y

CONFIG_HAS_SEGGER_RTT=y

CONFIG_USE_SEGGER_RTT=y

CONFIG_RTT_CONSOLE=y

CONFIG_UART_CONSOLE=n



# nRF5340 board config

CONFIG_TRUSTED_EXECUTION_SECURE=y



CONFIG_BT=n

CONFIG_TIMESLICING=n

CONFIG_DEVICE_POWER_MANAGEMENT=y

CONFIG_SYS_POWER_MANAGEMENT=y

CONFIG_SYS_POWER_DEEP_SLEEP_STATES=y

CONFIG_DEVICE_POWER_MANAGEMENT=y



CONFIG_I2C=y

CONFIG_I2C_1=y

main.c

#include 
#include 
#include <sys/printk.h>
#include <drivers/i2c.h>

/* Application main Thread */
int main(void)
{
  struct device *p_i2c = device_get_binding("I2C_1");
  u32_t dev_config = I2C_SPEED_SET(I2C_SPEED_STANDARD) | I2C_MODE_MASTER;
  int res = i2c_configure(p_i2c, dev_config);
  if (res)
  {
    return res;
  }
  struct i2c_msg msgs[2];
  u8_t data[2][2];
  data[0][0] = 0x01; // register address
  data[0][1] = 0x00;
  msgs[0].buf = data[0];
  msgs[0].len = 2U;
  msgs[0].flags = I2C_MSG_WRITE | I2C_MSG_STOP;

  data[1][0] = 0x4;
  data[1][1] = 0xff;
  msgs[1].buf = data[1];
  msgs[1].len = 2U;
  msgs[1].flags = I2C_MSG_WRITE | I2C_MSG_STOP;

  int i = i2c_transfer(p_i2c, &msgs[0], 2, 0x77);
  if  (i)
    printk("transfer failed");
  return 0;
}

Join users@lists.zephyrproject.org to automatically receive all group messages.