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

ble_app_uart reconnection problem

Hi all,

I am using an nrf51422 DK as a peripheral, with s130 softdevice and sdk11 on Keil, and iPhone6, with iOS 9.3.1, runing nrf Toolbox UART app.

I am sending data packets from my computer serial port to the nrf51422 DK UART, and I want to forward the data over ble to my iPhone. The data I'm sending is checked with CRC, and loosing packets is also affordable in my situation. I need to send 65B every 200ms without flow control, and was able to do that by modifying the ble_app_uart example.

I am having a problem with connecting to the bluetooth with my smartphone. On the first try it connects normally, works fine, and stays connected for as long as I have tested (30 min). But after reconnecting the central disconnects immediately. It seems the board resets itself and then I can connect again as for the first time. I couldn't get to the source of the restart, but I figured that if I don't send UART data during connection, the board doesn't reset.

What I modified on ble_app_uart example:

When I started working on the example I lowered the baud rate, from 115200 to 57600, and that has helped a lot, since I was unable to maintain a connection - there was an error in the nrf Toolbox log: connection timed out unexpectedly. The UART was probably hijacking the CPU, so the ble couldn't communicate with the central. This same error is currently present on the second connect, so I lowered the baud rate to 9600, but that didn't help.

I also modified this part of code:

    case APP_UART_COMMUNICATION_ERROR:
        if (p_event->data.error_communication != 1) {				
			APP_ERROR_HANDLER(p_event->data.error_communication);
			break;
		}
	case APP_UART_DATA_READY:
		if (m_conn_handle != BLE_CONN_HANDLE_INVALID) {
			UNUSED_VARIABLE(app_uart_get(&data_array[index]));
			++index;
			if (index >= BLE_NUS_MAX_DATA_LEN) 
			{
				err_code = ble_nus_string_send(&m_nus, data_array, index);
				if (err_code != NRF_ERROR_INVALID_STATE) APP_ERROR_CHECK(err_code);
				index = 0;
			}
		} 
		else 
		{
			app_uart_flush();
			//UNUSED_VARIABLE(app_uart_get(&data_array[index]));
			index = 0;
		}
        break;

I was sometimes having an overflow (data.error_communication == 1) I couldn't recover from without resetting the board, so I ignored the error and skipped to APP_UART_DATA_READY. It help me get out of that error - the data.error_communication was no longer 1. I also flushed the fifo when the ble wasn't connected.

Could anyone please help on this matter?

EDIT: This is the rar of my project: ble_uart.rar

Parents Reply Children
No Data
Related