I have successfully implemented an interrupt-driven method to read data from the MPU6050 sensor on the NRF52840, and it functions as expected. However, I encounter an issue where I am unable to establish a Bluetooth connection while the interrupt-based reading is active. I am working with the nrf connect sdk v2.6.1
and have configured the peripheral_uart
example.
After I deleted that line, the Bluetooth connection became normal:
mpu_read_n_reg(info, ACCEL_XOUT_H, info->sensor_data.raw_data, 14);
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static void mpu6050_thread(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p2);
ARG_UNUSED(p3);
int ret = 0;
uint16_t tmp[7];
mpu6050_info_t *info = p1;
struct sensor_value val[7];
while (1) {
k_sem_take(&info->gpio_sem, K_FOREVER);
data_cnt++;
mpu_read_n_reg(info, ACCEL_XOUT_H, info->sensor_data.raw_data, 14);
gpio_pin_interrupt_configure_dt(info->int_gpio,
GPIO_INT_EDGE_TO_ACTIVE);
info->sensor_data.accel_x = sys_be16_to_cpu(info->sensor_data.raw_data[0]);
MPU6050 CONFIG:
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
static const uint8_t mpu6050_init_cmd[11][2] = {
{PWR_MGMT_1, 0x80}, // PWR_MGMT_1, DEVICE_RESET
// need wait
{PWR_MGMT_1, 0x00}, // cleat SLEEP
{GYRO_CONFIG, 0x18}, // Gyroscope Full Scale Range = ± 2000 °/s
{ACCEL_CONFIG, 0x00}, // Accelerometer Full Scale Range = ± 2g
{INT_ENABLE, 0x01}, // Interrupt Enable. DATA_RDY_EN
{USER_CTRL, 0x00}, // User Control.auxiliary I2C are logically driven by the primary I2C bus
{FIFO_EN, 0x00}, // FIFO Enable.disenable
{SMPLRT_DIV, 99}, // Sample Rate Divider.Sample Rate = 1KHz / (1 + 99)
{CONFIG, 0x23}, // EXT_SYNC_SET = GYRO_ZOUT_L[0]; Bandwidth = 3
{PWR_MGMT_1, 0x01}, // Power Management 1.PLL with X axis gyroscope reference
{PWR_MGMT_2, 0x00} // Power Management 2
};