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

SPI communication and BLE advertising data with nRF52 DK

Hi everyone!

I have already developed a couple projects in nRF52 DK and the result was quite messy. I want to make it right this time and that's why I am requesting your help.

I am using nRF52 DK and SDK 13.0.0. and Eclipse Mars 2 (C/C++) with the setup explained in this Devzone Tutorial.
My goal is to create a project starting from some examples, modifying and merging them. I intend to comunicate with a SPI peripheral and send the recieved data through BLE advertising mode (broadcast).

I have compiled and tested the SPI example and it works just fine. Now, I need to send that data over BLE advertising. The requirement is it to be sent at least 10 times every second.

I would be very grateful if you could guide me on this. Some pages that I should read, any example that broadcasts data over BLE, any question already answered on this topic (I have searched and I did not find that much), any help will be very welcome. I really want to learn how to use Nordic hardware but my previous experience has only been frustrating so far.

Thank you so much for your time!

AGB

  • Everytime that I create a new project i follow the steps of the Devzone Tutorial (Propierties > C/C++ General > Preprocessor Include paths, Macros, etc and change the CDT GCC Build Outparser and CDT GCC Built-in Compiler Settings Cross ARM). I am not an expert, so I may be wrong but I think that is for avoiding erros in includes, isn't it?

    And yes, I have added the spi's includes to the main.c file of the ble_app_beacon.

  • I got rid of the problem with "undefined reference to 'nrf_drv_spi_init' " and "undefined reference to 'nrf_drv_spi_transfer' ". Turns out that I hadn't added the lines:

    $(SDK_ROOT)/components/drivers_nrf/spi_master \

    $(SDK_ROOT)/components/drivers_nrf/spi_master/nrf_drv_spi.c \

    To the Makefile. Now it compiles perfectly, I just need to fill the advdata info with the readings from the spi and that should be it.

  • I am almost done. I fully integrated both projects together and now the readings are being send properly. I just have a few matters that I would like to solve:

    The LOG is printing an ERROR:FATAL somewhere in my code. After debugging I found out that it is this:

    err_code = sd_ble_gap_adv_start(&m_adv_params, BLE_CONN_CFG_TAG_DEFAULT);

    In the debug I got err_code = 7, which according to the documentation is NRF_ERROR_INVALID_PARAM. My m_adv_params are:

    m_adv_params.type        = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
    m_adv_params.p_peer_addr = NULL;
    m_adv_params.fp          = BLE_GAP_ADV_FP_ANY;
    m_adv_params.interval    = NON_CONNECTABLE_ADV_INTERVAL;
    m_adv_params.timeout     = APP_CFG_NON_CONN_ADV_TIMEOUT;

    They are the default ones of the ble_app_beacon example and they had no errors before.

    Any idea?

  • What do you mean by readings are send properly?? how you are sending your spi data??

    Are you advertising it into beacon?

  • I send the m_rx_buf (sensor data) like this:

    manuf_specific_data.data.p_data = (uint8_t *) m_rx_buf;

    Yes, I am advertising them as a beacon in the Manufacturer Specific Data field. I am using nRF connect to check the content of the advertising packet and it actually is the sensor data. Thats was I was talking about when I said that they are being sent properly.

    This is what I talked about. The LOG is registering som ERROR:FATAL issue.

    I noticed a weird thing:

    APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, NULL, 0, m_rx_buf, m_length));
    
    NRF_LOG_FLUSH();
    
    bsp_board_led_invert(BSP_BOARD_LED_0);
    
    nrf_delay_ms(10);
    
    advertising_init();
    advertising_start();

    When I change this delay to 5 instead of 10, I get this other "error":

    Do you want me to post the whole main.c file? You will probably detect the mistakes very easy.

Related