Hello everyone,
I am using 2 nRF52840 of nRF9160 DK to send large bulks of data (like 2MB) . My problem is that this communication have to be necesseraly delayed or it can't be completed, because at some point the TX board cannot receive the ACK from RX board and cannot complete the transmission of information. If i remove the 6ms delay after esb_write_payload the TX cannot even send the 2nd message. Could you help me ? I want to remove this delay as much as i can
I am using Enhanced Shockburst to send and receive, sending 252 bytes per package. Configured ESB to send Fixed payload length. Great part of the code came from the ESB PTX example code.
Here is the code:
typedef struct {
uint32_t contador;
uint8_t dados[248];
}DadosTeste;
void event_handler(struct esb_evt const *event)
{
switch (event->evt_id) {
case ESB_EVENT_TX_SUCCESS:
LOG_DBG("TX SUCCESS EVENT");
break;
case ESB_EVENT_TX_FAILED:
LOG_DBG("TX FAILED EVENT");
break;
case ESB_EVENT_RX_RECEIVED:
if (esb_read_rx_payload(&rx_payload) == 0) {
memcpy(&rx_Contador, rx_payload.data, 4);
LOG_DBG("%d : %d", rx_payload.length, rx_Contador);
/*
LOG_DBG("Packet received, len %d : "
"0x%02x, 0x%02x, 0x%02x, 0x%02x, "
"0x%02x, 0x%02x, 0x%02x, 0x%02x",
rx_payload.length, rx_payload.data[0],
rx_payload.data[1], rx_payload.data[2],
rx_payload.data[3], rx_payload.data[4],
rx_payload.data[5], rx_payload.data[6],
rx_payload.data[7]);
*/
leds_update(rx_payload.data[1]);
} else {
LOG_ERR("Error while reading rx packet");
}
break;
}
}
uint16_t qtdPacotesRecebidos = 0;
DadosTeste variavel;
int esb_initialize(void)
{
int err;
/* These are arbitrary default addresses. In end user products
* different addresses should be used for each set of devices.
*/
uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8};
struct esb_config config = ESB_DEFAULT_CONFIG;
config.protocol = ESB_PROTOCOL_ESB;
config.payload_length = 252;
config.bitrate = ESB_BITRATE_2MBPS;
config.event_handler = event_handler;
config.mode = ESB_MODE_PTX;
config.selective_auto_ack = false;
err = esb_init(&config);
if (err) {
return err;
}
err = esb_set_base_address_0(base_addr_0);
if (err) {
return err;
}
err = esb_set_base_address_1(base_addr_1);
if (err) {
return err;
}
err = esb_set_prefixes(addr_prefix, ARRAY_SIZE(addr_prefix));
if (err) {
return err;
}
return 0;
}
int main(void)
{
int err;
memset(&variavel, 0x0, sizeof(DadosTeste) );
tx_payload.pipe = 0;
tx_payload.length = sizeof(variavel) ;
tx_payload.noack = true;
LOG_INF("Enhanced ShockBurst ptx sample");
err = clocks_start();
if (err) {
return 0;
}
err = esb_initialize();
if (err) {
LOG_ERR("ESB initialization failed, err %d", err);
return 0;
}
LOG_INF("Initialization complete");
LOG_INF("Sending test packet");
memset(variavel.dados, 0x31, sizeof(variavel.dados));
while (variavel.contador < 1000) {
if (ready) {
printf("envia\n");
ready = false;
esb_flush_tx();
variavel.contador++;
memcpy(tx_payload.data, &variavel, tx_payload.length);
err = esb_write_payload(&tx_payload);
if (err) {
LOG_ERR("Payload write failed, err %d", err);
}
k_sleep(K_MSEC(6));
}
}