Hi there,
Does the nRF Connect SDK support configuring the nRF21540 gain using SPI for values other than +10 and +20?
Looking at this previous Devzone question (SPI bus need to be dedicated to nRF21540?) it is mentioned that only GPIO-based gain setting is supported, which I believe restricts you to only +10 or +20. Although, this response was 1 year ago.
I am using the nRF21540-DK with the following KConfig options.
I am setting the Tx power (at the antenna) with the following piece of code on the Nordic DevZone. As you can see, this code also prints out what the FEM gain was set to after the Tx power has been set. Note: it seems a delay is required before querying the FEM gain or else the value will not be updated yet.
void set_tx_power(uint8_t handle_type, uint16_t handle, int8_t tx_pwr_lvl) { struct bt_hci_cp_vs_write_tx_power_level *cp; struct bt_hci_rp_vs_write_tx_power_level *rp; struct net_buf *buf, *rsp = NULL; int err; buf = bt_hci_cmd_create(BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL, sizeof(*cp)); if(!buf) { __ASSERT_NO_MSG(false); return; } cp = net_buf_add(buf, sizeof(*cp)); cp->handle = sys_cpu_to_le16(handle); cp->handle_type = handle_type; cp->tx_power_level = tx_pwr_lvl; err = bt_hci_cmd_send_sync(BT_HCI_OP_VS_WRITE_TX_POWER_LEVEL, buf, &rsp); if(err) { uint8_t reason = rsp ? ((struct bt_hci_rp_vs_write_tx_power_level *)rsp->data)->status : 0; __ASSERT(false, "Set Tx power err: %d reason 0x%02x\n", err, reason); return; } k_sleep(K_MSEC(100)); int8_t gain = 0; mpsl_fem_pa_is_configured(&gain); rp = (void *)rsp->data; LOG_INF("New Tx Power: %d (Gain: %d)", rp->selected_tx_power, gain); net_buf_unref(rsp); }
When I iterate through all of the potential Tx values from -20 to +20, the FEM Gain only ever changes between 10 and 20, it is not set to anything more granular. I believe when enabling configuration through SPI + using the Nordic power module, the FEM fain gain should be set to more granular values? This results in Tx power at the antenna that is off by 3dBm or more.
I can confirm that this file is being compiled, so it looks like it may be correctly using SPI:
nrf/subsys/mpsl/fem/nrf21540_gpio_spi/mpsl_fem_nrf21540_gpio_spi.c
My questions are:
- Should I expect to see FEM gain values other than +10 and +20?
- Is my method of setting the Tx power "at the antenna" correct?
- Is my method of querying the current gain of the FEM correct? It seems strange that it requires a delay beforehand. I followed this API down and it looks like it reads from a cached value in the stack rather than querying the FEM register directly, which doesn't fill me with as much confidence that it is accurate.
Thanks,
Sean