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;
}


Marciano
 

After further testing, I found that if I step through each instruction with the debugger the individual messages send correctly, but not if I let the program run regularly. In neither case does the i2c_transfer(…) function return. What might cause the differences in behavior between slow stepping and running the program?


PassiveLogic, Inc.
Main 801-394-3344
Mobile 801-800-1184
marciano@...

This e-mail and any files transmitted with it may contain confidential or legally privileged information of PassiveLogic and/or its affiliates, and are intended solely for the use of the individual or entity to which they are addressed. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited. If you have received this e-mail in error, please notify the sender immediately and delete the e-mail in its entirety from your system.



On Jan 7, 2020, at 3:07 PM, marciano@... wrote:

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;
}
<Screen Shot 2020-01-06 at 2.53.05 PM.png>