how to configure and work with nrf21540 with a pcb

Hello Nordic

I am working with nrf52840 and nrf52832 on pcbs, i want to use the nrf21540 with my pcbs to extend the strength of transmission.

I have read this data sheet : https://infocenter.nordicsemi.com/pdf/nRF21540_PS_v1.0.pdf

And saw the webinar on this page: https://www.nordicsemi.com/Products/Development-hardware/nRF21540-DB

I work with ncs1.9.2

I have some questions:

  1. Is there an example using the nrf21 on some other board that I can look into ? 
  2. Can I program and work with the nrf21540 only with GPIOs ? If so, how can I configure tx power to different values ? 
  3. When wanting to transmit, or receive, can’t we go from PD->TRX, do we have to PD->PG->TRX (that takes up to 28 microsec if i am correct ) ?
  4. If we need to switch from TX to RX do we need to switch TRX(TX)->PG->TRX(RX) and vice versa ? because this means transiting between receiving and transmitting taks up to 13.5 microsec, am I correct ? 

I refer to this table:

  1. If I want the nrf21540 to receive and transceive as the nrf52840 works, do I need to keep programming it or can it be configured somehow by UICR to certain TX power and it knows alone to pass between receiving and transmitting ?
  2. There are ANT1 and ANT2, why are there 2? Why can’t the be configured to work together (according to this table they can not, if i get it right) 

3. What changes do I need to put in my code and where to enable the control of the nrf21 ? if i am right transmitting and receiving happens somewhere in the low level of the app in the ncs, so it seems strange to me if i need to change something there

hope to read from you soon

best regards

Ziv

  • Hi Ziv,

    Is there an example using the nrf21 on some other board that I can look into ? 

    We currently have the design files for 3 boards using the nRF21540 available, the nRF21540DK and EK and the Thingy:53.

    Can I program and work with the nrf21540 only with GPIOs ? If so, how can I configure tx power to different values ? 

    Yes, using only GPIO is possible, but only 2 TX gain settings can be used. By default the MODE pin is used to switch between 10 and  20 dB gain, these values can be changed by writing to the POUTA_UICR and POUTB_UICR registers. The UICR is one time programmable, meaning  they can be programmed ones in production though the SPI interface.  In NCS v2.0.0 TX power split was added which splits the control of the output power between the nRF52/nRF53 and the nRF21450 to simplify setting the desired output power.

    • When wanting to transmit, or receive, can’t we go from PD->TRX, do we have to PD->PG->TRX (that takes up to 28 microsec if i am correct ) ?
    • If we need to switch from TX to RX do we need to switch TRX(TX)->PG->TRX(RX) and vice versa ? because this means transiting between receiving and transmitting taks up to 13.5 microsec, am I correct ? 

    The state diagram show the possible state transitions. To enter TRX from PD, PD->PG->TRX must be used. From RX to TX/TX to RX, the PG state must be used as a intermediate step.

    If I want the nrf21540 to receive and transceive as the nrf52840 works, do I need to keep programming it or can it be configured somehow by UICR to certain TX power and it knows alone to pass between receiving and transmitting ?

    The nRF21540 can not automatically switch between receive and transmit, it must be controlled by the main MCU. The UICR is only used for configuring the TX gain settings for the MODE pin.

    There are ANT1 and ANT2, why are there 2? Why can’t the be configured to work together (according to this table they can not, if i get it right) 

    The two antenna pins can be used for antenna diversity, where the two antennas are placed in different orientations/positions in the device, the antenna with the best RSSI can then be used to at any point giving better received signal strength.

    The two antenna pins can not be used together because a internal RF switch connects/disconnects the pins from the rest of the RF path.

    3. What changes do I need to put in my code and where to enable the control of the nrf21 ? if i am right transmitting and receiving happens somewhere in the low level of the app in the ncs, so it seems strange to me if i need to change something there

    You can use the MPSL FEM library, it includes support for GPIO only and GPIO+SPI control of the nRF21540. All you need for adding the nRF21540 to you project is shown here:
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/ug_radio_fem.html#

     

    Best regards,

    Bendik

  • hi Bendik

    You can use the MPSL FEM library, it includes support for GPIO only and GPIO+SPI control of the nRF21540. All you need for adding the nRF21540 to you project is shown here:
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/ug_radio_fem.html#

    i want to poc with an EK of nrf21540, the docs write about pin PDN to control the device via GPIO only

    but there is no PDN header pin on the EK ??? if i understand it right then on the EK its the pin under the 'SS' but i am not sure, and in any case. i connected tx, rx, pdn, one vdd line (1.8v) and GND and my program stops running when it gets to the Bluetooth setup - what am i missing ??? 

    my dts looks like that:

        nrf_radio_fem: nrf21_ek {
            compatible = "nordic,nrf21540-fem";
            tx-en-gpios = <&gpio0 25 GPIO_ACTIVE_HIGH>;
            rx-en-gpios = <&gpio0 11 GPIO_ACTIVE_HIGH>;
            pdn-gpios = <&gpio1 9 GPIO_ACTIVE_HIGH>;
        };

    this are the added configs to my .conf file 

    # nrf21540 
    CONFIG_MPSL=y
    CONFIG_MPSL_FEM=y
    CONFIG_MPSL_FEM_NRF21540_GPIO=y

    those are the only changes in the code so far, as i understand that should be enough ?? 

    and it seems to me the crash happens after this function call:

    void bt_conn_cb_register(struct bt_conn_cb *cb)
    {
    	cb->_next = callback_list;
    	callback_list = cb;
    }
     

    this is the log (i adder wr prints in the ncs for debug)

    [00000000] <wrn> bt_hci_core: hci core send sync
    [00000000] <wrn> bt_hci_core: take sem sync count 0
    [00000000] <wrn> bt_hci_core: Unable to store name
    [00000000] <wrn> bt_hci_core: hci core send sync
    [00000000] <wrn> bt_hci_core: take sem sync count 0
    ASSERTION FAIL [err == 0] @ WEST_TOPDIR/zephyr/subsys/bluetooth/host/hci_core.c:306
    
      k_sem_take failed with err -11
    
    [00000010] <err> os: r0/a1:  0x00000003  r1/a2:  0x00000002  r2/a3:  0x00000001
    [00000010] <err> os: r3/a4:  0x20003fd8 r12/ip:  0xfa000000 r14/lr:  0x00022ba5
    [00000010] <err> os:  xpsr:  0x41000000
    [00000010] <err> os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000
    [00000010] <err> os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000
    [00000010] <err> os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000
    [00000010] [1;31m<err> os: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x00000000
    [00000010] <err> os: fpscr:  0x00000000
    [00000010] <err> os: Faulting instruction address (r15/pc): 0x00022bb0
    [00000010] <err> os: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
    [00000010] <err> os: Current thread: 0x20005db0 (unknown)
    [00000010] <err> fatal_error: Resetting system
    *** Booting Zephyr OS build v2.7.99-ncs1-1  ***

    also i checked the gpios with a picoscope and saw no change, i don't know if it is related to the problem or just another outcome of the problem

    can i control the EK only with gpios, if so, what gpios am i missing ?

    another question, from the link you sent it seems i only need to add configs to the .conf file and add the node to the dts. is that realy all i need for the nrf21540 to act as a tx booster on my pcb (nrf52840 based) ?

    hope to read from you soon

    best regards

    Ziv

  • Hi Ziv,

    Sorry for not getting back to you sooner.

    If you are using the nRF21540EK then its as simple as including the shield overlay files already included in the SDK. To do this you just have to add the cmake argument -DSHIELD=nrf21540_ek to the build command. If you are using the VScode extension you can add this argument using the "Extra CMake arguments field":

    This includes the overlay file with the correct devicetree configuration for the EK and enables the MPSL FEM library.

     

    If you want to use the shield overlay files as reference for including it manualy you can find the files in:

    nrf/boards/shields/nrf21540_ek

    ziv123 said:
    but there is no PDN header pin on the EK ??? if i understand it right then on the EK its the pin under the 'SS' but i am not sure, and in any case.

    Yes the unlabeled pin next to the SS pin on the EK is the PDN.  I don't know why it isn't labeled on the PCB, but it is shown in the nRF21540-EK documentation:

    https://infocenter.nordicsemi.com/topic/ug_nrf21540_ek/UG/nrf21540_DK/connector_if.html?cp=7_0_4_2_4

    ziv123 said:
    can i control the EK only with gpios, if so, what gpios am i missing ?

    The minimal number of GPIOs needed to control the nRF21540-EK is: PDN, TX_EN, RX_EN, MODE and ANT_SEL.

    When adding the FEM to a custom board the MODE and ANT_SEL  pins can be tied directly to VDD/GND if only one of the default TX gain settings, and one antenna is used.

    ziv123 said:
    another question, from the link you sent it seems i only need to add configs to the .conf file and add the node to the dts. is that realy all i need for the nrf21540 to act as a tx booster on my pcb (nrf52840 based) ?

    The MPSL FEM library handles the control of the GPIO pins for every radio event, so enabling it should be enough.

     

    Best regards,

    Bendik

  • hi Bendik

    If you are using the nRF21540EK then its as simple as including the shield overlay files already included in the SDK

    i am working with nrf connect SDK (NCS) and not SDK.

    VScode extension you can add this argument using the "Extra CMake arguments field":

    This includes the overlay file with the correct devicetree configuration for the EK and enables the MPSL FEM library.

    if i add "set(SHEILD nrf21540_ek)" to my CMakeLists.txt file then i get compilation error cause my build configuration including my PCB does not know what is "arduino_header" cause i am not mounting the EK on a dev kit or on Arduino but trying to connect only by 3 GPIOS (plus VDD ad GND) to my PCB. there is some software issue here i think

    If you want to use the shield overlay files as reference for including it manualy you can find the files in:

    nrf/boards/shields/nrf21540_ek

    this dose not help, as you can see in my post that you replied to, i added a code of the device tree addition relevant to my PCB GPIOS.

    this is the log (i adder wr prints in the ncs for debug)

    can you tell why this happens, why there is not sem_give in the hci_core.c ?

    hope to read from you soon (we want to start the testing in Sunday so i hope we can find some solution till then)

    best regards

    Ziv

  • Hi again Ziv,

    ziv123 said:
    can you tell why this happens, why there is not sem_give in the hci_core.c ?

    I meant to write the nRF connect SDK, sorry about that.

    ziv123 said:
    can you tell why this happens, why there is not sem_give in the hci_core.c ?

    OK, then you can't use the shield overlay. Since you are only connecting 3 GPIOs you must tie the MODE and ANT_SEL to either VDD or GND depending on what configuration of TX gain and antenna output you are using.

     

    I see now that you are using the Zephyr Bluetooth LE controller, the MPSL library supports only the SoftDevice Controller. I am not sure if there is any support for front end modules in the zephyr controller, I recommend that you post in the Zephyr Discord for support with the Zephyr BLE controller.

Related