|
在使用ESB 2.4G 接收端上一直毫無進展
但是在使用官方範例 examples\peripheral\radio\receiver
確實是可以進行2.4G通訊 以下分別為 ESB 及 2.4G radio 代碼
payload length 皆為 20 使用pipe0
void radio_configure()
{
// Radio config
NRF_RADIO->TXPOWER = (RADIO_TXPOWER_TXPOWER_0dBm << RADIO_TXPOWER_TXPOWER_Pos);
NRF_RADIO->FREQUENCY = 7UL; // Frequency bin 7, 2407MHz
NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos);
// Radio address config
NRF_RADIO->PREFIX0 =
((uint32_t)swap_bits(0x05) << 24) // Prefix byte of address 3 converted to nRF24L series format
| ((uint32_t)swap_bits(0x05) << 16) // Prefix byte of address 2 converted to nRF24L series format
| ((uint32_t)swap_bits(0x05) << 8) // Prefix byte of address 1 converted to nRF24L series format
| ((uint32_t)swap_bits(0x05) << 0); // Prefix byte of address 0 converted to nRF24L series format
NRF_RADIO->PREFIX1 =
((uint32_t)swap_bits(0x05) << 24) // Prefix byte of address 7 converted to nRF24L series format
| ((uint32_t)swap_bits(0x05) << 16) // Prefix byte of address 6 converted to nRF24L series format
| ((uint32_t)swap_bits(0x05) << 0); // Prefix byte of address 4 converted to nRF24L series format
NRF_RADIO->BASE0 = bytewise_bitswap(0x04030201UL); // Base address for prefix 0 converted to nRF24L series format
NRF_RADIO->BASE1 = bytewise_bitswap(0x04030201UL); // Base address for prefix 1-7 converted to nRF24L series format
NRF_RADIO->TXADDRESS = 0x00UL; // Set device address 0 to use when transmitting
NRF_RADIO->RXADDRESSES = 0x01UL; // Enable device address 0 to use to select which addresses to receive
// Packet configuration
NRF_RADIO->PCNF0 = (PACKET_S1_FIELD_SIZE << RADIO_PCNF0_S1LEN_Pos) |
(PACKET_S0_FIELD_SIZE << RADIO_PCNF0_S0LEN_Pos) |
(PACKET_LENGTH_FIELD_SIZE << RADIO_PCNF0_LFLEN_Pos); //lint !e845 "The right argument to operator '|' is certain to be 0"
// Packet configuration
NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) |
(RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) |
(PACKET_BASE_ADDRESS_LENGTH << RADIO_PCNF1_BALEN_Pos) |
(PACKET_STATIC_LENGTH << RADIO_PCNF1_STATLEN_Pos) |
(PACKET_PAYLOAD_MAXSIZE << RADIO_PCNF1_MAXLEN_Pos); //lint !e845 "The right argument to operator '|' is certain to be 0"
// CRC Config
NRF_RADIO->CRCCNF = (RADIO_CRCCNF_LEN_Two << RADIO_CRCCNF_LEN_Pos); // Number of checksum bits
if ((NRF_RADIO->CRCCNF & RADIO_CRCCNF_LEN_Msk) == (RADIO_CRCCNF_LEN_Two << RADIO_CRCCNF_LEN_Pos))
{
NRF_RADIO->CRCINIT = 0xFFFFUL; // Initial value
NRF_RADIO->CRCPOLY = 0x11021UL; // CRC poly: x^16 + x^12^x^5 + 1
}
else if ((NRF_RADIO->CRCCNF & RADIO_CRCCNF_LEN_Msk) == (RADIO_CRCCNF_LEN_One << RADIO_CRCCNF_LEN_Pos))
{
NRF_RADIO->CRCINIT = 0xFFUL; // Initial value
NRF_RADIO->CRCPOLY = 0x107UL; // CRC poly: x^8 + x^2^x^1 + 1
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define NRF_ESB_ADDR_DEFAULT
{
.base_addr_p0 = {0x04, 0x03, 0x02, 0x01},
.base_addr_p1 = {0x04, 0x03, 0x02, 0x01},
.pipe_prefixes = { 0x05, 0x05, 0x05, 0x05,0x05,0x05, 0x05, 0x05},
.addr_length = 5,
.num_pipes = 8,
.rf_channel = 7,
.rx_pipes_enabled = 0x01
}
#define NRF_ESB_DEFAULT_CONFIG {.protocol = NRF_ESB_PROTOCOL_ESB_DPL,
.mode = NRF_ESB_MODE_PTX,
.event_handler = 0,
.bitrate = NRF_ESB_BITRATE_2MBPS,
.crc = NRF_ESB_CRC_16BIT,
.tx_output_power = NRF_ESB_TX_POWER_0DBM,
.retransmit_delay = 250,
.retransmit_count = 1,
.tx_mode = NRF_ESB_TXMODE_AUTO,
.radio_irq_priority = 1,
.event_irq_priority = 2,
.payload_length = 20,
.selective_auto_ack = false
}
uint32_t esb_init( void )
{
uint32_t err_code;
uint8_t base_addr_0[4] = {0x04, 0x03, 0x02, 0x01};
uint8_t base_addr_1[4] = {0x04, 0x03, 0x02, 0x01};
uint8_t addr_prefix[8] = {0x05, 0x05, 0x05, 0x05,0x05,0x05, 0x05, 0x05};
nrf_esb_config_t nrf_esb_config = NRF_ESB_DEFAULT_CONFIG;
nrf_esb_config.payload_length = 20;
nrf_esb_config.protocol = NRF_ESB_PROTOCOL_ESB_DPL;
nrf_esb_config.bitrate = NRF_ESB_BITRATE_2MBPS;
nrf_esb_config.mode = NRF_ESB_MODE_PRX;
nrf_esb_config.event_handler = nrf_esb_event_handler;
nrf_esb_config.selective_auto_ack = false;
err_code = nrf_esb_init(&nrf_esb_config);
VERIFY_SUCCESS(err_code);
err_code = nrf_esb_set_base_address_0(base_addr_0);
VERIFY_SUCCESS(err_code);
err_code = nrf_esb_set_base_address_1(base_addr_1);
VERIFY_SUCCESS(err_code);
err_code = nrf_esb_set_prefixes(addr_prefix, 8);
VERIFY_SUCCESS(err_code);
return err_code;
}
還請各位大大幫忙看一下ESB是哪裡出問題
|
|