This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

BLE accelerometer

Greetings,

I'm using nRF52 DK to transfer LIS3DH accelerometer data in Bluetooth. I successfully managed to establish an I2C connection with my sensor, I get my XYZ values. Now I want to send the data in Bluetooth, I'm a bit confused about what to do next. Is there any example program in SDK that will help me? or if you can suggest to me some tutorial that would be helpful too. I'm a beginner, so any advice or suggestions are welcome. Thank you.

Parents Reply Children
  • Thank you for the quick response. I will go through your materials.

  • Hi,

    I tried the BLE UART example to send my TWI sensor data. I'm having trouble with sdk_config. In my TWI program, im using the nrf_drv_twi legacy driver. I think it is creating some compatibility problems. So as per the article in devzone, I'm migrating from nrf_drv_twi to nrfx_twim driver. I have a doubt in it. What is this NRFX_TWIM_DESC_TX macro? I don't understand what is this descriptor means. I searched for other functions in nrfx_twim, but the functions are not advised to use. Please help me to understand this, I'm a t lost here. What are the functions or macros I need to migrate to this new nrfx_twim driver? For your information, I'm reading 3axis accelerometer LIS3DH using I2C communication. Please let me know my approach is correct.

  • I assume you mean NRFX_TWIM_XFER_DESC_TX? These are also present in the legacy driver: Advanced usage.

    There is not much advantage of migrating to the NRFX driver, most of it is just redefinitions of the old API, both APIs use the NRFX driver in the bottom layer anyway.

  • Thank you for your information. I fixed the driver issue. As per your advice, I'm trying to use app_ble_uart to send my TWI sensor data. Can I just use the NUS function to send the data or should I program the ble services and events to function properly? Because I called the function ble_nus_data_send into my sensor read and it didn't work.

    void twim_handler(nrfx_twim_evt_t const * p_event, void * p_context)
    {

    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t err_code;

    switch (p_event->type)
    {
    case NRFX_TWIM_EVT_DONE:
    UNUSED_VARIABLE(MPU6050_ReadAcc( &data_array[index]));
    index++;

    if ((data_array[index - 1] == '\n') ||
    (data_array[index - 1] == '\r') ||
    (index >= m_ble_nus_max_data_len))
    {
    if (index > 1)
    {
    NRF_LOG_DEBUG("Ready to send data over BLE NUS");
    NRF_LOG_HEXDUMP_DEBUG(data_array, index);

    do
    {
    uint16_t length = (uint16_t)index;
    err_code = ble_nus_data_send(&m_nus, data_array, &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);
    }
    } while (err_code == NRF_ERROR_RESOURCES);
    }

    index = 0;
    }
    break;

    m_xfer_done = true;
    break;
    default:
    break;
    }
    }

  • Do you get any error codes when calling ble_nus_data_send? Also, make sure that twim_handler does not run at a interrupt priority higher than 4, as this will prevent you from calling softdevice APIs.

Related