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

Modbus RTU protocol over "BLE UART"

I used the Nordic EVAL model nRF52-DK which uses the "nRF52832" chip.
The EVAL has been programmed as "Pheripheral" with the application "BLE over UART" made available by Nordic itself.
The "BLE over UART" profile contains the SoftDevice inside: "s132_nrf52_6.1.0_softdevice.hex".
The RX / TX signals of the UART have been connected to the serial port of an external device.
The BLE client is a PC application interfaced with the VCP of the "nRF51-Dongle" dongle.
The data frames to be exchanged have a maximum size of 512 bytes (stardard modbus RTU). The ATT_MTU = 20.
What is the reliability of BLE communication in the case of buffer fragmentation in packets of 20 bytes each ?
Is there a guarantee that the packets are always sent sequentially without the loss of packets ?
Which recommended solution to use for data exchange with such large buffers with modbus RTU ?

Best regards.
Thank you.

Demetrio Magrin

Parents
  • Hi,

    The link layer of BLE will ensure all packets are successfully received by peer and in the correct order. It's only a link loss that may interfere with this.

    To transmit large buffers it may be a good idea to use data length extension (include gatt_init in your project to handle this), this allow the two peers to exchange the maximum data packet size on-air, which overall will increase throughput and reduce latency.

    You can in the application have a large UART buffer, e.g. 1kByte, and in addition use hardware flow control on UART. This should ensure that the application can buffer the next packet while the current is transmitted. Enabling flow control will ensure that the peer don't overrun the buffer.

    Best regards,
    Kenneth

  • Hello Mr. Kenneth,

    With the examples provided by Nordic as UART over BLE (pheriferal and client) the transmission of a buffer of 300 bytes (for example), is received in 15 packets of 20 bytes with a pause between a packet and the next.
    If I send, through the UART, these 15 packets to my external control I would have the intervention of the end-of-frame modbus RTU interrupt at the end of each pack of 20 bytes.
    To solve this problem it is necessary to receive all the data in 20 bytes packets and then transmit all the received buffer to my control. Similar to Bluetooth BR/EDR.
    Note: for iOS systems it is advisable to use an ATT_MTU of 20 bytes.
    For this reason we have chosen to use ATT_MTU = 20 (default).
    We ignored the possibility of using an ATT_MTU> 20 bytes.
    I await a kind reply.

    Best regards,

    Demetrio Magrin

  • The UART service may be by default be setup for 20bytes, but longer is possible by modify the software. I could not find any specific requirement in iOS that prevent longer packet, they seem to support up to 251 bytes (ch. 11.11 and 11.7):

    https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf 

    In terms of software deliveries I guess you can find what we have to offer in the SDK documentation, maybe this link is a good starting point:

    https://www.nordicsemi.com/DocLib/Content/SDK_Doc/nRF5_SDK/v15-2-0/transport_libraries 

Reply Children
  • Hello Mr. Kenneth,

    It confirms that to transmit BLE packages of size greater than 20 bytes I have to modify the row
    #define BLE_GATT_ATT_MTU_DEFAULT 23 and then recompile my application and the related softdevice ?
    This must be done for both BLE (pheripheral and client).

    Is this the only way to use for MODBUS RTU over BLE communication or are there other possibilities?

    Thank you for your availability.
    BR
    Demetrio Magrin
  • Hi,

    There is really no short answer to your question other than to say it is fully configurable. The example will as you indicate use the NRF_SDH_BLE_GATT_MAX_MTU_SIZE you set for both UART and BLE packets, but this is just the way is setup. You are free to modify the project and use any combination of size, on any layer of the protocol, you may even split and reassemble packets in the application if you like.

    Best regards,
    Kenneth

  • Hello Mr. Kenneth,

    I ask her for advice on the following.

    The HW at my disposal to do the BLE tests is as follows:
    - EVAL NRF52-DK as "BLE pheripheral" with "ble_app_uart"
       (file ble_app_uart_pca10040_s132.hex).
       The VCP made available is accessible from my external DockLight tool.
    - Dongle "nRF51 dongle" as "BLE central" with "ble_app_uart_c"
       (file ble_app_uart_pca10031_s130.hex).
       The VCP made available is accessible from my external DockLight tool.


    1st Test: a buffer of 200 bytes is sent from the VCP "BLE Pheripheral" (for example).
             The "BLE central" VCP displays 10 frames of 20 bytes each.
            The time elapsed between a frame received of 20 bytes and the next one is 75 ms.
             Why is this time of 75 ms? How can you reduce?
             On the code I saw that there are the following two definitions:
             #define MIN_CONNECTION_INTERVAL MSEC_TO_UNITS (20, UNIT_1_25_MS)
             #define MAX_CONNECTION_INTERVAL MSEC_TO_UNITS (75, UNIT_1_25_MS)
             It seems to me that the pause time between the plots is linked to the definition
             "MAX_CONNECTION_INTERVAL".
             I tried to decrease this number to 30 ms on "BLE pheripheral and central" but nothing works.
             If I change this number from 75 to 200 I see that the time between the frames is 200 ms.

    2nd Test: The "nRF51 dongle" dongle is associated with the Nordic "nRF Connect v.2.6.1" TOOL PC
                  In this case the Nordic TOOL PC programs the "nRF51 dongle" dongle in the mode
                  "Ble_connectivity".
                  A buffer of 200 bytes is sent from the "BLE Pheripheral" VCP.
                  The Nordic "nRF Connect v.2.6.1" TOOL PC displays 10 frames of 20 bytes each.
                  The times elapsed between the received frames of 20 bytes have a minimum value of 0 ms
                  and a maximum value of 13 ms.
                  How come there are times so different from the previous test ?

    In my final use the dongle "nRF51 dongle" as "BLE central" will be replaced by an APP. on android or iOS where the buffer size will be greater than 20 bytes.
    For now I wanted to simulate a MODBUS communication using the HW described above
    (EVAL NRF52-DK as "BLE pheripheral" and dongle "nRF51 dongle" as "BLE central").
    How can I minimize the time of 75 ms by modifying the source code ?
    Is it possible that this time is deterministic ?


    I await a kind reply.
    BR

    Demetrio Magrin

  • It is as you already indicate depending on the connection parameters, and in specific the connection interval. It may be a better idea to use the central peer example in the SDK: \nRF5_SDK_15.2.0_9412b96\examples\ble_central\ble_app_uart_c in this case.

    And set the min and max interval to for instance 20ms, then I would expect them to negotiate to use 20ms.

    Best regards,
    Kenneth

  • Hello Mr. Kenneth,

    I have modified the define as follows(Pheripheral and Central):

    #define MIN_CONNECTION_INTERVAL MSEC_TO_UNITS (20, UNIT_1_25_MS)
    #define MAX_CONNECTION_INTERVAL MSEC_TO_UNITS (20, UNIT_1_25_MS)

    Perfect. Now the buffers are received without pauses.
    I have seen that if I decrease the time from 20 ms to 10 ms nothing works.
    Thank you very much for your availability.

    BR

    Demetrio Magrin

Related