demo-stm32f303-receiver/Core/Src/radio_demo.c
// Function to transmit data packet
// input:
//   pBuf - pointer to the buffer with data to transmit
//   length - length of the data buffer in bytes
// return: one of nRF24_TX_xx values
Function to transmit data packet
input:
pBuf - pointer to the buffer with data to transmit
length - length of the data buffer in bytes
return: one of nRF24_TX_xx values
Function to transmit data packet input : pBuf - pointer to the buffer with data to transmit length - length of the data buffer in bytes return : one of nRF24_TX_xx values
nRF24_TXResult nRF24_TransmitPacket(uint8_t *pBuf, uint8_t length) {
    volatile uint32_t wait = nRF24_WAIT_TIMEOUT;
    uint8_t status;
    nRF24_CE_L();
    nRF24_WritePayload(pBuf, length);
    nRF24_CE_H();
    do {
        status = nRF24_GetStatus();
        if (status & (nRF24_FLAG_TX_DS | nRF24_FLAG_MAX_RT)) {
            break;
        }
    } while (wait--);
    nRF24_CE_L();
    if (!wait) {
        return nRF24_TX_TIMEOUT;
    }
    UART_SendStr("[");
    UART_SendHex8(status);
    UART_SendStr("] ");
    nRF24_ClearIRQFlags();
    if (status & nRF24_FLAG_MAX_RT) {
        return nRF24_TX_MAXRT;
    }
    if (status & nRF24_FLAG_TX_DS) {
        return nRF24_TX_SUCCESS;
    }
    nRF24_FlushTX();
    return nRF24_TX_ERROR;
}
nRF24_TXResult nRF24_TransmitPacket ( uint8_t * pBuf , uint8_t length ) { volatile uint32_t wait = nRF24_WAIT_TIMEOUT ; uint8_t status ; nRF24_CE_L ( ) ; nRF24_WritePayload ( pBuf , length ) ; nRF24_CE_H ( ) ; do { status = nRF24_GetStatus ( ) ; if ( status & ( nRF24_FLAG_TX_DS | nRF24_FLAG_MAX_RT ) ) { break ; } } while ( wait -- ) ; nRF24_CE_L ( ) ; if ( ! wait ) { return nRF24_TX_TIMEOUT ; } UART_SendStr ( " " ) ; UART_SendHex8 ( status ) ; UART_SendStr ( " " ) ; nRF24_ClearIRQFlags ( ) ; if ( status & nRF24_FLAG_MAX_RT ) { return nRF24_TX_MAXRT ; } if ( status & nRF24_FLAG_TX_DS ) { return nRF24_TX_SUCCESS ; } nRF24_FlushTX ( ) ; return nRF24_TX_ERROR ; }
Function to transmit data packet
input:
pBuf - pointer to the buffer with data to transmit
length - length of the data buffer in bytes
return: one of nRF24_TX_xx values
Function to transmit data packet input : pBuf - pointer to the buffer with data to transmit length - length of the data buffer in bytes return : one of nRF24_TX_xx values
// Deassert the CE pin (in case if it still high) // Transfer a data from the specified buffer to the TX FIFO // Start a transmission by asserting CE pin (must be held at least 10us) // Poll the transceiver status register until one of the following flags will be set: //   TX_DS  - means the packet has been transmitted //   MAX_RT - means the maximum number of TX retransmits happened // note: this solution is far from perfect, better to use IRQ instead of polling the status // Deassert the CE pin (Standby-II --> Standby-I) // Timeout // Check the flags in STATUS register // Clear pending IRQ flags // Auto retransmit counter exceeds the programmed maximum limit (FIFO is not removed) // Successful transmission // Some banana happens, a payload remains in the TX FIFO, flush it