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

nRF24LE1 : Payload with ACK

Hello, I use two NRF24LE1 emission and reception when I use a simple ACK is good but with ACK payload, there is a problem, I do not really see where you can help me, Thank you in advance Sincerely, Cédric

My code:

RX:

hal_nrf_set_operation_mode(HAL_NRF_PRX);
hal_nrf_enable_dynamic_payload(true);
hal_nrf_enable_ack_payload(true);
hal_nrf_setup_dynamic_payload (0xFF);
hal_nrf_set_power_mode(HAL_NRF_PWR_UP);

CE_HIGH();

// Radio interrupt NRF_ISR() { uint8_t irq_flags;

// Read and clear IRQ flags from radio irq_flags = hal_nrf_get_clear_irq_flags();

// If data received if((irq_flags & (1<<(uint8_t)HAL_NRF_RX_DR)) > 0) { // Read payload while(!hal_nrf_rx_fifo_empty()) { hal_nrf_read_rx_payload(payload); } // transmit ACK Payload pipe 1 hal_nrf_flush_tx(); hal_nrf_write_ack_payload(1, ack_payload, 1);

// Write received payload[0] to port 0
P0 = payload[0];                    <- OK, it's good

} }


TX:

hal_nrf_enable_dynamic_payload(true);
hal_nrf_enable_ack_payload(true);
hal_nrf_setup_dynamic_payload (0xFF);
hal_nrf_set_power_mode(HAL_NRF_PWR_UP);

for( ; ; ) { // Put P0 contents in payload[0] payload[0] = ~P0;

// Write payload to radio TX FIFO
hal_nrf_write_tx_payload(payload, 3U);

// Toggle radio CE signal to start transmission
	P10 = 1;
CE_PULSE();
	P10 = 0;

radio_busy = true;
// Wait for radio operation to finish
while (radio_busy)
{
}

}

// Radio interrupt NRF_ISR() { uint8_t irq_flags;

// Read and clear IRQ flags from radio irq_flags = hal_nrf_get_clear_irq_flags();

switch(irq_flags) { // Transmission success case (1 << (uint8_t)HAL_NRF_TX_DS): P11 = !P11; <- OK, it's good radio_busy = false; // Data has been sent break; // Transmission failed (maximum re-transmits) case (1 << (uint8_t)HAL_NRF_MAX_RT): // When a MAX_RT interrupt occurs the TX payload will not be removed from the TX FIFO. // If the packet is to be discarded this must be done manually by flushing the TX FIFO. // Alternatively, CE_PULSE() can be called re-starting transmission of the payload. // (Will only be possible after the radio irq flags are cleared) hal_nrf_flush_tx(); radio_busy = false; P12 = !P12; <- OK, it's good break; default: break; }

 // If data received

if((irq_flags & (1<<(uint8_t)HAL_NRF_RX_DR)) > 0) { // Read payload while(!hal_nrf_rx_fifo_empty()) { hal_nrf_read_rx_payload(payload); }

P13 = !P13; <- Never 

}


Parents
  • Just to be clear, calling hal_nrf_write_ack_payload() preloads an ack packet that's then sent to the PTX when the PTX sends a packet to the PRX. if your code takes too long to assemble the ack payload, the PTX will timeout and assume that no ack was received. you can also have your PTX send two packets -- one with the real data, which once received, the PRX will assemble an ack packet. and then the PTX waits a little bit and then sends a second packet, the response to which is the actual ack packet.

Reply
  • Just to be clear, calling hal_nrf_write_ack_payload() preloads an ack packet that's then sent to the PTX when the PTX sends a packet to the PRX. if your code takes too long to assemble the ack payload, the PTX will timeout and assume that no ack was received. you can also have your PTX send two packets -- one with the real data, which once received, the PRX will assemble an ack packet. and then the PTX waits a little bit and then sends a second packet, the response to which is the actual ack packet.

Children
No Data
Related