Hi, I'm getting an error saying that "ble_link_ctx_manager.h: No such file or directory issue"
This is the main.c file:
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "nrf.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "app_timer.h" // required for timer function
#include "bsp_btn_ble.h" //required for LED
#include "nrf_pwr_mgmt.h" //Required for power management. this will allow the system to sleep when it's not being used.
#include "nrf_sdh.h"
#include "nrf_sdh_ble.h"
#include "nrf_sdh_soc.h"
#include "ble_nus.h"
#include "nrf_ble_qwr.h"
#include "nrf_ble_gatt.h"//header file for gatt function.
#define MPU6050_ADDRESS 0x68
#define TWI_INSTANCE_ID 0
//Two required header files for advertisement.
#include "ble_advdata.h"
#include "ble_advertising.h"
#include "ble_conn_params.h"
#define APP_BLE_CONN_CFG_TAG 1
#define APP_BLE_OBSERVER_PRIO 3
//This would be my name for the bluetooth connection.
#define DEVICE_NAME "SW-BT"
//This will help me to set minimum connection interval as 100ms from using RTC 1.25ms.
#define MIN_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS)
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(200, UNIT_1_25_MS)
#define SLAVE_LATENCY 0
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(2000, UNIT_10_MS) //in 2 seconds if the device is not responding, then the connection is terminated.
#define FIRST_CONN_PARMS_UPDATE_DELAY APP_TIMER_TICKS(5000)
#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(30000)
#define MAX_CONN_PARAMS_UPDATE_COUNT 3
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);
BLE_NUS_DEF(m_nus); // BLE NUS service instance
NRF_BLE_QWR_DEF(m_qwr); // Need to change this to NRF_BLE_QWRS_DEF(m_qwr) if I'm connecting more than one device.
NRF_BLE_GATT_DEF(m_gatt); //This is the instance for the gatt.
BLE_ADVERTISING_DEF(m_advertising); //This is the instance for advertisement.
static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID;
//Constants for advertisement
#define APP_ADV_INTERVAL 300
#define APP_ADV_DURATION 0
void twi_init(void) {
ret_code_t err_code;
const nrf_drv_twi_config_t twi_config = {
.scl = 25, // Pin number for SCL
.sda = 24, // Pin number for SDA
.frequency = NRF_TWI_FREQ_400K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = false
};
err_code = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&m_twi);
}
void mpu6050_init(void) {
uint8_t data[2];
data[0] = 0x6B; // PWR_MGMT_1 register
data[1] = 0x00; // Set to 0 to wake up the MPU6050
ret_code_t err_code = nrf_drv_twi_tx(&m_twi, MPU6050_ADDRESS, data, 2, false);
APP_ERROR_CHECK(err_code);
}
void read_mpu6050_data(int16_t* accel_data, int16_t* gyro_data) {
uint8_t reg = 0x3B; // Starting register to read from (ACCEL_XOUT_H)
uint8_t data[14];
ret_code_t err_code = nrf_drv_twi_tx(&m_twi, MPU6050_ADDRESS, ®, 1, true);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_twi_rx(&m_twi, MPU6050_ADDRESS, data, 14);
APP_ERROR_CHECK(err_code);
accel_data[0] = (data[0] << 8) | data[1]; // ACCEL_XOUT_H, ACCEL_XOUT_L
accel_data[1] = (data[2] << 8) | data[3]; // ACCEL_YOUT_H, ACCEL_YOUT_L
accel_data[2] = (data[4] << 8) | data[5]; // ACCEL_ZOUT_H, ACCEL_ZOUT_L
gyro_data[0] = (data[8] << 8) | data[9]; // GYRO_XOUT_H, GYRO_XOUT_L
gyro_data[1] = (data[10] << 8) | data[11]; // GYRO_YOUT_H, GYRO_YOUT_L
gyro_data[2] = (data[12] << 8) | data[13]; // GYRO_ZOUT_H, GYRO_ZOUT_L
}
/* Step 6: gap initialization */
static void gap_params_init(void)
{
ret_code_t err_code;
ble_gap_conn_params_t gap_conn_params; //This variable holds all the GAP connection parameters.
ble_gap_conn_sec_mode_t sec_mode; //This variable holds the security mode.
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); //Security is opened.
//Set device name
err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)DEVICE_NAME, strlen(DEVICE_NAME));// (const uint8_t *) is pointer. strlen is string length.
APP_ERROR_CHECK(err_code);
//initialize connection parameters. But before that, we have to clear the memory.
memset(&gap_conn_params, 0, sizeof(gap_conn_params)); //clearing the memory.
//Now setting the values.
gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
gap_conn_params.slave_latency = SLAVE_LATENCY;
gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT;
//Now we will pass these values to PPCP set function.
err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
APP_ERROR_CHECK(err_code);
}
/* Step 7: gatt initialization */
static void gatt_init(void)
{
ret_code_t err_code = nrf_ble_gatt_init(&m_gatt, NULL); // NULL is the event hander.
APP_ERROR_CHECK(err_code);
}
/*Step 9.1: error handler for queue writer */
static void nrf_qwr_error_handler(uint32_t nrf_error)
{
APP_ERROR_HANDLER(nrf_error);
}
/*Step 9:Initialize the services */
static void services_init(void)
{
ret_code_t err_code;
nrf_ble_qwr_init_t qwr_init = {0};
qwr_init.error_handler = nrf_qwr_error_handler;
err_code = nrf_ble_qwr_init(&m_qwr, &qwr_init);
APP_ERROR_CHECK(err_code);
}
/*Step 10.1: create an event handler for connection parameters update*/
static void on_conn_params_evt(ble_conn_params_evt_t * p_evt)
{
ret_code_t err_code;
if(p_evt-> evt_type == BLE_CONN_PARAMS_EVT_FAILED)//if the connection parameter's update request fails.
{
err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); // this will disconnect.
APP_ERROR_CHECK(err_code);
}
if(p_evt-> evt_type == BLE_CONN_PARAMS_EVT_SUCCEEDED)
{
}
}
/*Step 10.2: creat an error handler for conn params update */
static void conn_params_error_handler(uint32_t nrf_error)
{
APP_ERROR_HANDLER(nrf_error);
}
/*Step 10:Create a function for setting up the connection parameters */
static void conn_params_init(void)
{
ret_code_t err_code;
ble_conn_params_init_t cp_init; //connection parameter.
memset(&cp_init, 0, sizeof(cp_init)); //Clearing the memory
cp_init.p_conn_params = NULL; //pointer
cp_init.first_conn_params_update_delay = FIRST_CONN_PARMS_UPDATE_DELAY;
cp_init.next_conn_params_update_delay = NEXT_CONN_PARAMS_UPDATE_DELAY;
cp_init.max_conn_params_update_count = MAX_CONN_PARAMS_UPDATE_COUNT;//after reaching this max amount of number of parameter not able to update by the master, it will generate error.
cp_init.start_on_notify_cccd_handle = BLE_GATT_HANDLE_INVALID;
cp_init.disconnect_on_fail = false; //If the connection param is not still updated,it will still not be disconnected by the master due to setting it to false.
cp_init.error_handler = conn_params_error_handler;
cp_init.evt_handler = on_conn_params_evt;
err_code = ble_conn_params_init(&cp_init); //initializing the cp_init to the ble_conn_params_init function.
APP_ERROR_CHECK(err_code);
}
/* Step 8.1: Creating advertisement event handler */
static void on_adv_evt (ble_adv_evt_t ble_adv_evt_)
{
ret_code_t err_code;
switch (ble_adv_evt_)
{
case BLE_ADV_EVT_FAST: //When the device is advertising
NRF_LOG_INFO("Fast advertising...");
err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING); //When the device goes into the fast advertising state, it will blink LED.
APP_ERROR_CHECK(err_code);
break;
case BLE_ADV_EVT_IDLE://device is not advertising anymore. no LED are turned on.
err_code = bsp_indication_set(BSP_INDICATE_IDLE);
APP_ERROR_CHECK(err_code);
break;
default:
break;
}
}
/* Step 8: advertising initialization */
static void advertising_init(void)
{
ret_code_t err_code;
ble_advertising_init_t init; //This will hold advertising values.
memset(&init, 0, sizeof(init)); //Clearing the memory of the init.
init.advdata.name_type = BLE_ADVDATA_FULL_NAME; //setting the name of the BLE to the init.
init.advdata.include_appearance = true; //setting the appearance of the BLE to the init.
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; //Setting the flag
init.config.ble_adv_fast_enabled = true; //Setting the advertisement as fast mode.
init.config.ble_adv_fast_interval = APP_ADV_INTERVAL; //Setting the interval for the advertisement.
init.config.ble_adv_fast_timeout = APP_ADV_DURATION;
init.evt_handler = on_adv_evt; //Event handler will receive event from the advertisement.
err_code = ble_advertising_init(&m_advertising, &init);
APP_ERROR_CHECK(err_code);
ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG); //Passing the tag to the advertisement.
}
/* Step 5.1: BLE Event handler*/
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void *p_context) // this will allow us to know if our system is connected or not.
{
ret_code_t err_code = NRF_SUCCESS;
switch(p_ble_evt -> header.evt_id)
{
case BLE_GAP_EVT_DISCONNECTED:
NRF_LOG_INFO("Device is disconnected!!");
break;
case BLE_GAP_EVT_CONNECTED:
NRF_LOG_INFO("Device is connected!!");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED); // the LED will turn on if our device is connected.
APP_ERROR_CHECK(err_code);
m_conn_handle = p_ble_evt -> evt.gap_evt.conn_handle;
err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
APP_ERROR_CHECK(err_code);
break;
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
NRF_LOG_DEBUG("PHY Update Request.");
ble_gap_phys_t const phys =
{
.rx_phys = BLE_GAP_PHY_AUTO,
.tx_phys = BLE_GAP_PHY_AUTO,
};
err_code = sd_ble_gap_phy_update(p_ble_evt -> evt.gap_evt.conn_handle, &phys);
APP_ERROR_CHECK(err_code);
break;
}
}
/*Step 5: BLE Stack Initialization */
//initializing the softdevice.
static void ble_stack_init()
{
ret_code_t err_code;
err_code = nrf_sdh_enable_request(); //sending request to enable soft device.
APP_ERROR_CHECK(err_code);
uint32_t ram_start = 0;
err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
APP_ERROR_CHECK(err_code);
err_code = nrf_sdh_ble_enable(&ram_start); //If everything goes well, it will be enabled.
APP_ERROR_CHECK(err_code);
NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}
/* Step 4: Init Power Management */
static void power_management_init(void)
{
ret_code_t err_code = nrf_pwr_mgmt_init();
APP_ERROR_CHECK(err_code);
}
//Before sleeping, it will transmit logger data.
/* Step 4.1: idle state handle */
static void idle_state_handle(void)
{
if(NRF_LOG_PROCESS() == false) //This is checking if all the logger is processed. See if it sent all the data.
{
nrf_pwr_mgmt_run(); //Once it finished transmitting all the data, it will be false state and the power goes to sleep.
}
}
void nus_init(void) {
ret_code_t err_code;
ble_nus_init_t nus_init;
memset(&nus_init, 0, sizeof(nus_init));
nus_init.data_handler = NULL;
err_code = ble_nus_init(&m_nus, &nus_init);
APP_ERROR_CHECK(err_code);
}
/* Step 3: Init BSP(LEDS) */
static void leds_init(void)
{
ret_code_t err_code = bsp_init(BSP_INIT_LEDS, NULL);
APP_ERROR_CHECK(err_code);
}
/* Step 2: Init APP timer */
static void timers_init(void)
{
ret_code_t err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
}
/* 1st step: Initialize the logger */
static void log_init()
{
ret_code_t err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);
NRF_LOG_DEFAULT_BACKENDS_INIT();
}
/*Step 11:create a function which will start the advertisement*/
static void advertising_start(void)
{
ret_code_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);
}
/**@brief Function for application main entry.
*/
int main(void)
{
log_init();
// Initialize
twi_init();
mpu6050_init();
timers_init();
leds_init();
power_management_init();
ble_stack_init();
gap_params_init();
nus_init();
gatt_init();
advertising_init();
services_init();
conn_params_init();
NRF_LOG_INFO("BLE Base application started...");
advertising_start(); //starts the advertising.
int16_t accel_data[3], gyro_data[3];
char data_buffer[64];
uint16_t length;
while (true) {
read_mpu6050_data(accel_data, gyro_data);
snprintf(data_buffer, sizeof(data_buffer), "ACC: X=%d, Y=%d, Z=%d; GYRO: X=%d, Y=%d, Z=%d",
accel_data[0], accel_data[1], accel_data[2], gyro_data[0], gyro_data[1], gyro_data[2]);
length = strlen(data_buffer);
err_code = ble_nus_data_send(&m_nus, (uint8_t*)data_buffer, &length, m_conn_handle);
if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_RESOURCES) && (err_code != NRF_ERROR_NOT_FOUND)) {
APP_ERROR_CHECK(err_code);
}
nrf_delay_ms(1000);
}
// Enter main loop.
for (;;)
{
idle_state_handle();//the system is keep on watching if the device is free. If it's free, it will go to sleep.
}
}
/**
* @}
*/
Also, I have attached the snapshot of my project explorer:


Please help:(
Thank you!
