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

Changing the content of nRF ESB payload

Hello,

After decided and tried porting nrf_esb from the example code to my project, now I am stuck with changing the content of the payload.

I changed the payload using:

for (uint8_t i = 0; i < tx_payload.length; i++) {
			tx_payload.data[i] += 1;
//			printf("tx_payload.data[%d]: %x\r\n", i, tx_payload.data[i]);
		}

And here's my handler:

void nrf_esb_event_handler(nrf_esb_evt_t const * p_event) {
	nrf_gpio_pin_toggle(LED_2);
	printf("handler\r\n");
//	NRF_LOG_INFO("Inside handler!");
//	NRF_LOG_FLUSH();
	switch (p_event->evt_id) {
	case NRF_ESB_EVENT_TX_SUCCESS:
//		NRF_LOG_INFO("Packet sending succeeded!");
		printf("sent? PID: %x\r\n", tx_payload.pid);
		nrf_esb_pop_tx();
		break;
	case NRF_ESB_EVENT_TX_FAILED:
		(void) nrf_esb_flush_tx();
		(void) nrf_esb_start_tx();
		//NRF_LOG_INFO("Packet sending failed!");
		break;
	case NRF_ESB_EVENT_RX_RECEIVED:
		// Get the most recent element from the RX FIFO.
		while (nrf_esb_read_rx_payload(&rx_payload) == NRF_SUCCESS) {
			printf("Received a packet. ID: %x:\r\n", rx_payload.pid);
			for (uint8_t i = 0; i < rx_payload.length; i++) {
				printf("rx_payload.data[%d]: %x\r\n", i, rx_payload.data[i]);
			}
			// Set LEDs identical to the ones on the PTX.
//			NRF_LOG_INFO("Packet Received!");
		}
		//nrf_esb_flush_rx();
		break;

	}
//	NRF_LOG_INFO("Exit!");
//	NRF_LOG_FLUSH();
	//nrf_gpio_pin_toggle(LED_2);
}

Every time a "send packet command" is fired, it should increment the content inside tx_payload by 1 then send it.

Upon printing data, it always print the old data. Printing on the receiver will not happen if I did not fire sending on sender. The only way to print a new data is to reset it first.

Is this the correct way to use nrf_esb? or is it not?

Thank you,
Winz

Parents Reply Children
No Data
Related