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

receive data from the peripheral

hello everybody!

i want to sample an analog signal with  the board and send the 0/1 data with ble to the receiver .

i created my on service with rx and tx like in ble uart example but i don't now how to read the data received from the board . how could i do??

thans a lot for your answer!

marikalp.

Parents Reply Children
  • i have a dongle too,..anyway isn't that one the problem. i didn't how to create the service to send data from the peripheral to the central ( pc). in my project i have to sample an anlog data and transfer it to pc with the ble.

    but thanks a lot for yor answer.

  • OK - I think I see what you want to do. Here is what I think you should try:

    SDK 15.2.0:
    File: nRF5_SDK_15.2.0_9412b96/examples/ble_peripheral/ble_app_uart/main.c
    functon: void uart_event_handle(app_uart_evt_t * p_event), line 521

    This is where normally Nordic is gettng 'data ready' from their UART device.
    You want to replace this with 'data ready' events from your ADC device.

    If you are using their SAADC, then those events will be EVENTS_END event. This signals that the SAADC has completed the conversion across all channels. In the SAADC device the converted data is held in the buffer NRF_SAADC_Type->RESULT_PTR.

    As a first start, the easiest way to get the ADC conversion across your BLE connection would be to directly call the function

    uint32_t error_code = ble_nus_data_send(&m_nus, your_data_pointer, your_data_length, m_conn_handle);
    Line 545 in that file.

    This should give you immediate results. These results will not be optimized for throughput. If you send your data too fast you will get the return code NRF_ERROR_RESOURCES from the call. At this point you will have to concern yourself with the connection interval and fitting your data chunks into the link layer payload or MTU size optimally. But this should get you started.

  • ok my your_data_pointer is for me the input pin 28, the sampling function i wrote was something like this:

     uint32_t  pin_value=nrf_gpio_pin_read(28);
         
          if (pin_value==0)
          {
          nrf_gpio_pin_clear(15);
          m_custom_value=0;
          ble_nus_data_send()
         
          }
          else  if (pin_value!=0)
          {
          nrf_gpio_pin_set(15);
          m_custom_value=1;
          ble_nus_data_send()

    BUT i don't how to face that with the uart and all the program

    thanks a lot really for your answer!!

    best regards.

  • Your call to ble_nus_data_send() should look something like this:

    uint16_t length = sizeof(m_custom_value);

    // or perhaps length merely = 1;

    uint32_t error_code = err_code = ble_nus_data_send(&m_nus, m_custom_value, &length, m_conn_handle);

    Are you able to build the program, load it onto the nrf52, and run it?

  • obviusly it was only to semplify ...anyway i tried that code without the ble and was ok...the problem is to undestand in which way put it with the uart and ble in order  to send this message to the receiver and put it to video...

Related