Dear devzone community,
I am currently in the process of migrating my MBED code to NRF5 SDK. My MBED code is functional and it works fine, you can find the code below:
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "mbed.h"
I2C i2c(p2, p3); // sda, scl
RawSerial pc(p6, p5); // tx, rx
uint8_t addr = 0x19; // define the correct I2C Address
uint8_t acc_addr;
uint8_t acc_id;
uint8_t acc_ready;
uint8_t fs_factor;
char dt[2];
#define LIS3DH_CTRL_REG1 0x20
#define data_rate 1
#define LIS3DH_CTRL_REG4 0x23
#define fullscale 2
#define LIS3DH_SENSITIVITY_8G 4
#define LIS3DH_WHO_AM_I 0x0f
#define I_AM_LIS3DH 0x33
#define LIS3DH_OUT_X_L 0x28
#define GRAVITY (9.80665F / 1000)
#define LIS3DH_V_CHIP_ADDR (0x19 << 1)
However I am having problems making the code work in NRF5 SDK. This is what I have so far:
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Copyright (c) 2015 - 2019, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
Can anybody point out what I am doing wrong here, functionally I want the code to function like in MBED, but I'm not sure about the I2C communication part in NRF5 SDK. It would be super helpful if anybody can give an example in what order I should send and listen to the I2C bus.
kind regards,