Hello, I am working on a project where I have 2 nRF52832 boards with the PCA10040. I have the example developer code examples. I am using the central and peripheral code examples to talk from one UART to another on Tera Term. Although, I noticed that this code is structured so that data is piled in an array and only sent to the other UART when I press "enter" or if it reaches a maximum size (which is very large). I am only using Tera Term to test my boards and not as part of the project. I have an external source of data that works properly on its own and am trying to use these UARTs to establish wireless communication. I have cut the solder bridges SB 22-25 to isolate PO.05 - PO.08 from nRF52832 to the Interface MCU. In pins 6 and 8 on both boards, I put TXD and RXD. Essentially what I am trying to do is have data go though the TXD & RXD wires to one UART, then wirelessly transfer data to the other UART, and have TXD & RXD wires come back. This processes will not work unless the code is structured so that data can be processed (sent & received) continuously. Or at least have it to where whatever is stacked up in the buffer is sent out every interval. I have attached the part of the code for both Central and Peripheral examples that specifically deal with data in UART. I have also put a diagram of sorts to help visualize. Any help would be great. Thanks.
You can remove the if statement if you want to transmit smaller packets:
if ((data_array[index - 1] == '\n') || (data_array[index - 1] == '\r') || (index >= m_ble_nus_max_data_len))
Hi, thanks for responding. I have tried that. And it seems to work on Tera Term. As I type characters, it sends it instantly. But it seems that when I try using it with the configuration as shown above, the link connects but the packets are not recognized. I am thinking this may be because it is sending a small bit of data every time. Is there any way to structure the code so that I can have data sent in intervals of like 500 microseconds. So whatever data accumulates in the buffer is pushed out at every interval?
So i have been working on this and before I posted this, I had tried removing the if ((data_array...etc on both codes and it works on a terminal program. I have narrowed down what it is I am looking to do. I am receiving data that is around 30-50 bits, but with this code alteration that Vidar Berg suggested, I am only able to pass around 8 bits through the bluetooth link. The rest of the data gets lost. Is there a way to alter the code so that I can put all of the data through the bluetooth link.
if anyone is trying to see the whole code it can be found in the nordic nRF52 SDK download here--> nRF52 SDK. In the folder, it is in nRF5SDK\nRF5SDK153059ac345\nRF5_SDK_15.3.0_59ac345\examples\ble_central\ble_app_uart_c\pca10040\s132\arm5_no_packs and nRF5SDK\nRF5SDK153059ac345\nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\ble_app_uart\pca10040\s132\arm5_no_packs
Hi, you will get higher bandwidth when you split the data into larger chunks as opposed to sending a few bytes at a time (Note: the max data size is defined by m_nus_max_data_len), so it's probably a good idea to accumulate data at a fixed interval before transmitting as you suggested. I would probably have used a longer timer interval though. The lowest connection interval allowed by BT spec. is 7.5 ms anyway.
Aashay said:The rest of the data gets lost
It's not lost by the Softdevice. Data passed to ble_nus_data_send() will be transmitted if the function returns NRF_SUCCESS (i.e., the link will be terminated if a packet is not received within the supervision timeout ). I think it's likely returning NRF_ERROR_RESOURCES as it's easier to fill the Softdevice's TX buffer when you send many small notifications rather than few large notifications. The message for handle value notification illustrates this: https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v6.1.1/group___b_l_e___g_a_t_t_s___h_v_n___m_s_c.html?cp=3_4_1_1_2_4_3_5
I'd recommend using an app timer instance to control the data transfer. You can use the ble_app_hrs example to see how timers are initialized.