This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C on NRF51822 Board w/ Zephyr

I've been stuck for days trying to get I2C working on a NRF51822 board by Holyiot. Through scanning, or using the sample project (samples/sensor/lps22hb) I am unable to detect the lps22hb sensor via I2C. I've added all details below, help would be very much appreciated.. I feel like I've tried everything.

board .dts

/dts-v1/;
#include <nordic/nrf51822_qfaa.dtsi>

/ {
	model = "DIGIBOARD";
	chosen {
		zephyr,sram = &sram0;
		zephyr,flash = &flash0;
	};
  };

&adc {
	status = "okay";
};

&gpiote {
	status = "okay";
};

&gpio0 {
	status = "okay";
};

&i2c0{
  status = "okay";
    compatible = "nordic,nrf-twi";
  	status = "okay";
  	sda-pin = < 30 >;
  	scl-pin = < 0 >;

    lps22hb-press@5d {
     compatible = "st,lps22hb-press";
     reg = <0x5d>;
     label = "LPS22HB";
   };
};


project .conf
#i2c
CONFIG_I2C=y
CONFIG_I2C_NRFX=y
CONFIG_NRFX_TWI=y
CONFIG_NRFX_TWI0=y
CONFIG_NRFX_TWI1=y
#   CONFIG_NFCT_PINS_AS_GPIOS=y

#lps22hb
CONFIG_SENSOR=y
CONFIG_LPS22HB=y

#logging
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_LOG_PRINTK=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_UART_CONSOLE=n
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_UART=n
CONFIG_ASSERT=y
CONFIG_STACK_SENTINEL=y
CONFIG_LOG_PROCESS_THREAD=y

#other
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_GPIO=y


main.c
#include <zephyr.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/gpio.h>
#include <logging/log_ctrl.h>
#include <drivers/i2c.h>
#include <stdio.h>
#include <sys/util.h>


#define I2C_DEV "I2C_0"


void main(void)
{
	log_init();
	struct device *i2c_dev;
	SEGGER_RTT_WriteString(0, "Starting i2c scanner...\n");

	i2c_dev = device_get_binding(I2C_DEV);
	if (!i2c_dev) {
		SEGGER_RTT_WriteString(0, "I2C: Device driver not found.\n");
		return;
	}
	int amtFound = 0;
	for (uint8_t i = 4; i <= 0x77; i++) {
		struct i2c_msg msgs[1];
		uint8_t dst;

		/* Send the address to read from */
		msgs[0].buf = &dst;
		msgs[0].len = 0U;
		msgs[0].flags = I2C_MSG_WRITE | I2C_MSG_STOP;

		if (i2c_transfer(i2c_dev, &msgs[0], 1, i) == 0) {
			SEGGER_RTT_WriteString(0, "0x%2x FOUND\n", i);
			amtFound = amtFound + 1;
		}
	}
	printk("found: %i\n", amtFound);
}

Schematic (Holyiot YJ-16060):

Related