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.

  • 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.

Reply Children
No Data
Related