I test data transmission through NUS service as follows.
void data_tx_test(void)
{
char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
sprintf(ble_tx_buffer, "1. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
data_tx_handler(ble_tx_buffer);
sprintf(ble_tx_buffer, "2. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
data_tx_handler(ble_tx_buffer);
sprintf(ble_tx_buffer, "3. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
data_tx_handler(ble_tx_buffer);
sprintf(ble_tx_buffer, "4. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
data_tx_handler(ble_tx_buffer);
sprintf(ble_tx_buffer, "5. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
data_tx_handler(ble_tx_buffer);
sprintf(ble_tx_buffer, "6. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
data_tx_handler(ble_tx_buffer);
}
void data_tx_handler(char const *ble_tx_buff)
{
uint8_t tx_buffer[BLE_NUS_MAX_DATA_LEN] = {0,};
static uint8_t index = 0;
uint32_t err_code;
memcpy(tx_buffer, ble_tx_buff, BLE_NUS_MAX_DATA_LEN);
for(uint8_t i = 0; i < BLE_NUS_MAX_DATA_LEN; i++){
if(tx_buffer[i] == '\r'){
index = i;
break;
}
}
index++;
NRF_LOG_INFO("index = %d\r\n", index);
do
{
uint16_t length = (uint16_t)index;
err_code = ble_nus_data_send(&m_nus, tx_buffer, &length, m_conn_handle);
if ((err_code != NRF_ERROR_INVALID_STATE) &&
(err_code != NRF_ERROR_RESOURCES) &&
(err_code != NRF_ERROR_NOT_FOUND))
{
APP_ERROR_CHECK(err_code);
printf("OK!!! [%x]\r\n", err_code);
} else {
printf("ERR!!! [%x]\r\n", err_code);
}
} while (err_code == NRF_ERROR_RESOURCES);
index = 0;
}
If data is transmitted 6 times in succession, the system crashes. No logs appear.
However, the system does not die and operates normally when data is transmitted three times in a row.
void data_tx_test(void)
{
char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
sprintf(ble_tx_buffer, "1. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
data_tx_handler(ble_tx_buffer);
sprintf(ble_tx_buffer, "2. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
data_tx_handler(ble_tx_buffer);
sprintf(ble_tx_buffer, "3. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
data_tx_handler(ble_tx_buffer);
// sprintf(ble_tx_buffer, "4. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
// data_tx_handler(ble_tx_buffer);
//
// sprintf(ble_tx_buffer, "5. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
// data_tx_handler(ble_tx_buffer);
//
// sprintf(ble_tx_buffer, "6. The TCA8418 is a keypad scan device with integrated ESD protection. It can operate from 1.65 V to 3.6 V and has 18 general purpose inputs/outputs (GPIO) that can be used to support up to 80 keys via the I2C interface.\r\n");
// data_tx_handler(ble_tx_buffer);
}
I need to implement a function that sends data 6 times in succession. Please tell me how to solve this problem.
Best Regards,
SunBae Yim.