I am using nRF52840 to interface my MPU6050 sensor via I2C , I build and flashed the program and there were no problem. But I can't see any clock signal on the default I2C Clock , even i checked all the GPIOs there was no clock at any pin
This is my main.c
/* * Copyright (c) 2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ #include <zephyr/kernel.h> #include <zephyr/device.h> #include <zephyr/devicetree.h> #include <zephyr/drivers/i2c.h> #include <zephyr/sys/printk.h> #define SLEEP_TIME_MS 1000 /* MPU6050 Register Addresses */ #define MPU6050_REG_PWR_MGMT_1 0x6B #define MPU6050_REG_ACCEL_XOUT_H 0x3B #define MPU6050_REG_ACCEL_XOUT_L 0x3C #define MPU6050_REG_ACCEL_YOUT_H 0x3D #define MPU6050_REG_ACCEL_YOUT_L 0x3E #define MPU6050_REG_ACCEL_ZOUT_H 0x3F #define MPU6050_REG_ACCEL_ZOUT_L 0x40 #define MPU6050_REG_TEMP_OUT_H 0x41 #define MPU6050_REG_TEMP_OUT_L 0x42 #define MPU6050_REG_GYRO_XOUT_H 0x43 #define MPU6050_REG_GYRO_XOUT_L 0x44 #define MPU6050_REG_GYRO_YOUT_H 0x45 #define MPU6050_REG_GYRO_YOUT_L 0x46 #define MPU6050_REG_GYRO_ZOUT_H 0x47 #define MPU6050_REG_GYRO_ZOUT_L 0x48 /* MPU6050 I2C Address */ #define MPU6050_I2C_ADDR 0x68 #define I2C_NODE DT_NODELABEL(mysensor) int main(void) { int ret; /* Retrieve the API-specific device structure and make sure that the device is ready to use */ static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C_NODE); if (!device_is_ready(dev_i2c.bus)) { printk("I2C bus %s is not ready!\n", dev_i2c.bus->name); return -1; } /* Wake up MPU6050 by writing 0x00 to the PWR_MGMT_1 register */ uint8_t pwr_mgmt[2] = {MPU6050_REG_PWR_MGMT_1, 0x00}; ret = i2c_write_dt(&dev_i2c, pwr_mgmt, sizeof(pwr_mgmt)); if (ret != 0) { printk("Failed to write to I2C device address %x at Reg. %x \n", dev_i2c.addr, pwr_mgmt[0]); return -1; } while (1) { uint8_t accel_x[2] = {0}, accel_y[2] = {0}, accel_z[2] = {0}; uint8_t temp[2] = {0}; /* Read accelerometer and temperature data from the MPU6050 */ ret = i2c_burst_read_dt(&dev_i2c, MPU6050_REG_ACCEL_XOUT_H, accel_x, sizeof(accel_x)); ret |= i2c_burst_read_dt(&dev_i2c, MPU6050_REG_ACCEL_YOUT_H, accel_y, sizeof(accel_y)); ret |= i2c_burst_read_dt(&dev_i2c, MPU6050_REG_ACCEL_ZOUT_H, accel_z, sizeof(accel_z)); ret |= i2c_burst_read_dt(&dev_i2c, MPU6050_REG_TEMP_OUT_H, temp, sizeof(temp)); if (ret != 0) { printk("Failed to read from I2C device address %x \n", dev_i2c.addr); return -1; } /* Convert the accelerometer and temperature data */ int16_t accel_x_val = (accel_x[0] << 8) | accel_x[1]; int16_t accel_y_val = (accel_y[0] << 8) | accel_y[1]; int16_t accel_z_val = (accel_z[0] << 8) | accel_z[1]; int16_t temp_val = (temp[0] << 8) | temp[1]; /* Convert temperature to Celsius */ double cTemp = (temp_val / 340.0) + 36.53; /* Print the accelerometer and temperature data */ printk("Accel X: %d, Accel Y: %d, Accel Z: %d\n", accel_x_val, accel_y_val, accel_z_val); printk("Temperature in Celsius: %.2f C\n", cTemp); k_msleep(SLEEP_TIME_MS); } }
this is my prj.config file
&i2c0{ mysensor:mysensor@68{ compatible = "i2c-device"; reg = < 0x68 >; label = "MYSENSOR"; }; };