GPIO Control of the nRF21540 FEM

I have a custom board with a nRF52840 and a nRF21540.  To control my FEM (nRF21540) I have added the following to my code to my nRF52840_nRF52840.dts file:

/ {
    nrf_radio_fem: name_of_fem_node {
       compatible  = "nordic,nrf21540-fem";
       tx-en-gpios = <&gpio0 22 GPIO_ACTIVE_HIGH>;
       rx-en-gpios = <&gpio0 24 GPIO_ACTIVE_HIGH>;
       pdn-gpios   = <&gpio0 31 GPIO_ACTIVE_HIGH>;
       ant-sel-gpios = <&gpio0 20 GPIO_ACTIVE_HIGH>;
       mode-gpios = <&gpio0 17 GPIO_ACTIVE_HIGH>;
 };
};
Now, in the 'main.c' file, I want to add the code to control these pins/signals.  I'm sorry this is probably so simple, but I am new to this type of configuration, and I don't what I should do next.  I don't know what to do to control the various FEM lines within the 'main.c' program.  Any help would greatly be appreciated.
Thanks,
Sheldon
Parents
  • Hi Sheldon,

    You only need to specify the FEM in the device tree (as I see you are doing) and enable MPSL FEM support in your project configuration. Then the MPSL will automatically control the FEM. You can read more about this under Working with RF front-end modules.

    Einar

  • I tried to enable it in the pro.config: 

    CONFIG_MPSL_FEM =y
    The problem is I get an error:
    c:/ncs/bt-fund-main/lesson4/blefund_less4_exer3_solution/prj.conf:24: warning: attempt to assign the value 'y' to the undefined symbol MPSL_FEM

    error: Aborting due to Kconfig warnings
    The auto complete suggested use of the CONFIG_MPSL_FEM so I thought for sure it would work.  I'm not sure why it thinks it is undefined.
  • Hi,

    You will get this error as you have a whitespace before the equal sign. It should be like this: "CONFIG_MPSL_FEM=y".

    Regarding manual control that is also possible, but it makes sense to let the MPSL control the FEM. You do not have full control of when the radio is used from the application, as it is the stack that keeps track of packet transmission times, retransmissions etc.

  • I must be doing something wrong because it still doesn't work.  I do see several concerning things in my code: When I mouse over to of the FEM lines in the 'pro.config' file I get the following comments (which makes me think some things are not present that need to be).  I don't quite know what to do:

    Below is the code:

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    # Enable the UART driver
    CONFIG_UART_ASYNC_API=y
    CONFIG_NRFX_UARTE0=y
    CONFIG_SERIAL=y
    
    CONFIG_GPIO=y
    
    # Make sure printk is printing to the UART console
    CONFIG_CONSOLE=y
    CONFIG_UART_CONSOLE=y
    
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    CONFIG_MAIN_STACK_SIZE=4096
    
    CONFIG_BT_SCAN_UUID_CNT=1
    
    
    # Enable FEM and MPSL
    CONFIG_MPSL=y
    CONFIG_MPSL_FEM=y
    
    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="Nordic_UART_Service"
    CONFIG_BT_DEVICE_APPEARANCE=833
    CONFIG_BT_MAX_CONN=1
    CONFIG_BT_MAX_PAIRED=1
    
    CONFIG_BT_CENTRAL=y
    CONFIG_BT_SMP=y
    CONFIG_BT_GATT_CLIENT=y
    
    CONFIG_BT_NUS_CLIENT=y
    
    CONFIG_BT_RX_STACK_SIZE=2048
    
    CONFIG_MPSL_FEM_NRF21540_GPIO=y
    
    
    # Enable the NUS service
    # STEP 1 - Enable the Kconfig symbol of the NUS service
    CONFIG_BT_NUS=y
    CONFIG_BT_NUS_AUTHEN=n
    CONFIG_BT_NUS_SECURITY_ENABLED=n
    CONFIG_BT_SCAN=y
    CONFIG_BT_SCAN_FILTER_ENABLE=y
    CONFIG_BT_SCAN_UUID_CNT=1
    CONFIG_BT_SCAN_NAME_CNT=1
    CONFIG_BT_GATT_DM=y
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    # Enable bonding
    CONFIG_BT_SETTINGS=n
    CONFIG_FLASH=n
    CONFIG_FLASH_PAGE_LAYOUT=n
    CONFIG_FLASH_MAP=n
    CONFIG_NVS=n
    CONFIG_SETTINGS=n
    
    # Added as suggested by technical support
    # CONFIG_BT_PERIPHERAL_PREF_MIN_INT=12
    # CONFIG_BT_PERIPHERAL_PREF_MAX_INT=132
    # CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=400
    
    # Enable DK LED and Buttons library
    CONFIG_DK_LIBRARY=y
    
    # This example requires more workqueue stack
    CONFIG_MAIN_STACK_SIZE=1152
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    # Config logger
    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=n
    CONFIG_LOG_PRINTK=n
    
    CONFIG_ASSERT=y
    

  • Hi,

    The error about missing MPSL_FEM_CHOICE is because you need to set one of the three of

    • CONFIG_MPSL_FEM_NRF21540_GPIO
    • CONFIG_MPSL_FEM_NRF21540_GPIO_SPI
    • CONFIG_MPSL_FEM_SIMPLE_GPIO

    You have selected MPSL_FEM_NRF21540_GPIO but do not have MPSL_FEM_NRF21540_GPIO_SUPPORT, which I expect i s because it is not configured properly in your device tree. Have you added the FEM suppor to the device tree (either in your board fiel or in an overlay file)?

  • I don't understand.  As I showed, I did make the choice of 'CONFIG_MPSL_FEM_NRF21540_GPIO = y' and it doesn't like that (see the second thing I posted).  It told me that had dependencies and I don't know what to do about them.  Are they something I also must see with a '= y'?

    Anyway, I have looked on my oscilloscope (see the attached plot) and it does look like the RX_EN and TX_EN lines going to the nRF21540 are switching (as I set it up in my device tree overlay file).  Yet, the RF signal strength received by my nRF52840 is measured as very weak.  I don't know what I could be doing wrong on my board.

Reply
  • I don't understand.  As I showed, I did make the choice of 'CONFIG_MPSL_FEM_NRF21540_GPIO = y' and it doesn't like that (see the second thing I posted).  It told me that had dependencies and I don't know what to do about them.  Are they something I also must see with a '= y'?

    Anyway, I have looked on my oscilloscope (see the attached plot) and it does look like the RX_EN and TX_EN lines going to the nRF21540 are switching (as I set it up in my device tree overlay file).  Yet, the RF signal strength received by my nRF52840 is measured as very weak.  I don't know what I could be doing wrong on my board.

Children
  • As an aside question: Is it possible to have the receiver spend more time with RX_EN on more?  It is always off for a short period of time quite frequently and I would like it on almost all of the time.  I miss some of the signals I want to detect and I bet it is during the 'RX_EN' low periods when they are missed.

  • Hi,

    Sheldon01 said:
    As I showed, I did make the choice of 'CONFIG_MPSL_FEM_NRF21540_GPIO = y' and it doesn't like that (see the second thing I posted)

    Here you have white space again, and that will not work. This must be wihtout white spaces.

    Sheldon01 said:
    Are they something I also must see with a '= y'?

    You need to enable it in the device tree file. You can se a reference of this for instance in the nRF52540 DK board files (search for "nrf21540" in zephyr/boards/arm/nrf21540dk_nrf52840/nrf21540dk_nrf52840.dts). I see it seems like you have done that now as you got the pins toggling.

    Sheldon01 said:
     Yet, the RF signal strength received by my nRF52840 is measured as very weak.  I don't know what I could be doing wrong on my board.

    Have you had your hardware reviewed by Nordic? If not, it makes sense to make a support case and attach your shcematics and layout fiels (as gerber). We can also do tuning of your HW. If not, it could be an hardware issue, perhaps as simple as bad antenna tuning.

    Sheldon01 said:
    As an aside question: Is it possible to have the receiver spend more time with RX_EN on more?  It is always off for a short period of time quite frequently and I would like it on almost all of the time.

    You could control it manually instead of MPSL if you want it on all the time (refer to the docuemtation I linked to in my first post). But that would incerase the current consumption, and the MPSL knows when the radio is in use, so the most efficient is to leave controlling the FEM up to MPSL.

  • I have just done the most telling experiment yet:

    I removed the nRF21540 IC from my board and simply added a thin wire to link the antenna to the TRX pin.  When I feed in a -20dBm signal to my system (that now goes directly to the nRF52840) I get close to an RSSI value of -20dBm.  When I have the nRF21540 IC in place, I read a RSSI of -50dBm (or worse).  It gets weaker with the FEM circuit in place when it should be much stronger!.  I think that there must be something wrong with the control signals I am sending to my nRF21540.

    I may send in my schematic and board layout but I am quite sure that they are not the problem.  I still believe that I must be sending the FEM incorrect control signals.  It's like nRFnRF52840 gets nothing from the FEM but only a weak signal leaks in to it (which it still is able to detect/decode).

    Note that I care nothing about power consumption.  I want to detect/decode all of the advertisement packets of my reference transmitter.  I don't care if it uses more power.  I don't want to miss a single transmission.

  • Hi,

    As you see the control poins toggling on the scope the control mechanism seems to be good, and so I would be very interested in looking at the HW as the next step.

    Sheldon01 said:
    Note that I care nothing about power consumption.  I want to detect/decode all of the advertisement packets of my reference transmitter.  I don't care if it uses more power.  I don't want to miss a single transmission.

    I see. In that case you can try to set for instance the TN_EN externally and see if that makes a difference on the Tx power. Note that you will not loose any transmissions by letting the MPSL control this. By controlling the FEM, it will enable the PA and LNA as needed, and there should not be any down sides with this approach.

  • As an experiment, I redefined the location of the '&nRF_radio_fem rx-en' pin to an unused location.  The RSSI that I then measured was much much weaker.  Thus, I think the signals are probably being switched ok but there is a hardware problem.  Is there a way that I can confidentially have someone at Nordic look at my design (not letting it be shown to the public where our competition could see it)?

Related