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

"Hello World" data transfer over 802.15.4

Hi!

I'd like to get a minimal "Hello World" example working for data transfer over 802.15.4

I have two of Makerdiary nRF52840 MDK USB Dongle, one as sender and one as receiver.

I started from examples/802_15_4/wireless_uart/ from the nRF5 SDK 16.0.0. When sending data with tx_options.ack = false, at least my callback gets called that was passed to mcps_data_req(). When sending with tx_options.ack = true, the callback is not called, I guess because no ACK is received.

On the other side, I don't receive anything. I configured PHY and MAC and then set MAC_RX_ON_WHEN_IDLE. Then I expect that mcps_data_ind() gets called. Is this right? (Interestingly there is no linker error if I don't implement mcps_data_ind()).

Did I forget something?

This is my code, for sender and receiver CONFIG_SHORT_ADDRESS and CONFIG_DESTINATION_SHORT_ADDRESS are exchanged

#include "config.h"
#include "ral_irq_handlers.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

#include "nrf_drv_clock.h"

#include "mac_mcps_data.h"
#include "sys_init.h"
#include "sys_task_scheduler.h"
#include "boards.h"

#include "mac_mlme_pib.h"
#include "sys_memory_manager.h"


#define CONFIG_SHORT_ADDRESS 11
#define CONFIG_DESTINATION_SHORT_ADDRESS 10

static uint8_t phyChannel = 15;
static uint16_t macPanId = CONFIG_PAN_ID;
static uint16_t macShortAddress = CONFIG_SHORT_ADDRESS;
static uint64_t macExtendedAddress = CONFIG_IEEE_ADDRESS + CONFIG_SHORT_ADDRESS;
static uint8_t on = 1;


static uint8_t __ALIGN(ALIGN_VALUE) m_heap[CONFIG_POOL_SIZE];
static const size_t m_heap_size = CONFIG_POOL_SIZE;

static void out_of_memory_callback(const void * data);
static void memory_freed_callback(const void * data);

static sys_event_desc_t m_out_of_memory_desc =
{
.event_id = SYS_EVENT_OUT_OF_MEMORY,
.callback = out_of_memory_callback,
};

static sys_event_desc_t m_memory_freed_desc =
{
.event_id = SYS_EVENT_MEMORY_FREED,
.callback = memory_freed_callback,
};

static void out_of_memory_callback(const void * data)
{
//LEDS_ON(BIT(CONFIG_ERROR_PIN));
}

static void memory_freed_callback(const void * data)
{
//LEDS_OFF(BIT(CONFIG_ERROR_PIN));
}


// init clock
// infocenter.nordicsemi.com/index.jsp
// infocenter.nordicsemi.com/index.jsp
static void clockCallback(nrfx_clock_evt_type_t event) {}
static void clock_init(void)
{
nrfx_err_t err_code = nrfx_clock_init(clockCallback);
ASSERT(err_code == NRFX_SUCCESS);
nrfx_clock_enable();

nrfx_clock_hfclk_start();
while (!nrfx_clock_hfclk_is_running()) {
// spin lock
}

nrfx_clock_lfclk_start();
while (!nrfx_clock_lfclk_is_running()) {
// spin lock
}
}

// called when data was sent
void sentCallback(mcps_data_conf_t *result) {
bsp_board_led_invert(0);
}

// called when data was received
void mcps_data_ind(mcps_data_ind_t *p_ind)
{
bsp_board_led_invert(1);
}

// configure phy and mac
void initMac()
{
const pib_id_t phyChannelPibId = {.plme_id = PHY_CURRENT_CHANNEL_ID};
const pib_id_t macPanIdPibId = {.mlme_id = MAC_PAN_ID};
const pib_id_t macShordAddressPibId = {.mlme_id = MAC_SHORT_ADDRESS};
const pib_id_t macExtendedAddressPibId = {.mlme_id = MAC_EXTENDED_ADDRESS};
const pib_id_t macRxOnWhenIdlePibId = {.mlme_id = MAC_RX_ON_WHEN_IDLE};
mlme_set(phyChannelPibId, 0, &phyChannel);
mlme_set(macPanIdPibId, 0, &macPanId);
mlme_set(macShordAddressPibId, 0, &macShortAddress);
mlme_set(macExtendedAddressPibId, 0, &macExtendedAddress);
mlme_set(macRxOnWhenIdlePibId, 0, &on);
}

// timer for sending data in regular interval
sys_timer_t timer;
static mcps_data_req_t m_data_req;
void timerCallback(void *data)
{
// send data
m_data_req.dst_addr_mode = MAC_ADDR_SHORT;
m_data_req.dst_addr.short_address = CONFIG_DESTINATION_SHORT_ADDRESS;
m_data_req.dst_pan_id = CONFIG_PAN_ID;
m_data_req.src_addr_mode = MAC_ADDR_SHORT;
m_data_req.msdu = (uint8_t*)"foo";
m_data_req.msdu_length = 3;
m_data_req.msdu_handle++;
m_data_req.tx_options.ack = true;//false
m_data_req.tx_options.gts = false;
m_data_req.tx_options.indirect = false;
mcps_data_req(&m_data_req, sentCallback);
}

int main(void)
{
ral_irq_handler_import();

// init board
bsp_board_init(BSP_INIT_LEDS);

// init log
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("Wireless UART example started.");

// init clock
clock_init();

// init system
// infocenter.nordicsemi.com/index.jsp
sys_init(m_heap, m_heap_size);
sys_event_subscribe(&m_out_of_memory_desc);
sys_event_subscribe(&m_memory_freed_desc);

// configure ieee 802.15.4 mac
initMac();

// start a timer to send data in regular interval
timer.interval = 1000000;
timer.type = SYS_TIMER_PERIODIC;
timer.callback = timerCallback;
timer.p_data = NULL;
sys_timer_start(&timer);

while (true) {
sys_task_run();
}
}
Parents Reply Children
Related