Page 1 of 1

How to use external FEM with ESP32

Posted: Thu Oct 24, 2019 5:22 am
by szwitlink
Hi everyone,
We are considering use ESP32 in long range Wifi application. We need to connect ESP32 with an external FEM (including PA/LNA/RF-switch).

To control the PA and RF-switch, we need to connect some GPIOs of ESP32 with FEM, it is easy. But the software must enable/disable PA before/after transmission. But I cannot find the RF source code in esp-idf. The RF piece is in the form of binary lib.

Is there any solution?

Thanks!

Re: How to use external FEM with ESP32

Posted: Thu Oct 24, 2019 11:33 am
by WiFive

Re: How to use external FEM with ESP32

Posted: Thu Oct 24, 2019 1:57 pm
by szwitlink
Thanks a lot! But it seems this article explains how to use multiple antennas for diversity. But for external FEM, we need some way to enable/disable PA in Tx/Rx state. We also need some way to bypass LNA when the received signal is too strong.

Re: How to use external FEM with ESP32

Posted: Mon Dec 02, 2019 3:03 am
by szwitlink
Hi,
We try to use esp_wifi_set_ant_gpio and esp_wifi_set_ant to control FEM. It seems ESP32 always uses ANT0. It means it does not activate ANT1 even under Tx mode.

Is there any example on multiple antennas? Would you help review the code below?

void app_setup_gpio(void)
{
gpio_config_t io_conf;

//disable interrupt
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);

gpio_set_level(GPIO_RF_LNAEN, 0);
gpio_set_level(GPIO_RF_TXEN, 0);
gpio_set_level(GPIO_RF_RXEN, 0);
gpio_set_level(GPIO_PHY_RSTn, 0);
}

void wifi_init_sta()
{
wifi_ant_gpio_config_t ant_gpio_config;
wifi_ant_config_t ant_config = {
.rx_ant_mode = WIFI_ANT_ANT0,
.rx_ant_default = WIFI_ANT_ANT0,
.tx_ant_mode = WIFI_ANT_MODE_ANT1,
.enabled_ant0 = 3,
.enabled_ant1 = 4
};

app_setup_gpio();

ant_gpio_config.gpio_cfg[0].gpio_select = 1;
ant_gpio_config.gpio_cfg[0].gpio_num = GPIO_RF_LNAEN;
ant_gpio_config.gpio_cfg[1].gpio_select = 1;
ant_gpio_config.gpio_cfg[1].gpio_num = GPIO_RF_RXEN;
ant_gpio_config.gpio_cfg[2].gpio_select = 1;
ant_gpio_config.gpio_cfg[2].gpio_num = GPIO_RF_TXEN;
ant_gpio_config.gpio_cfg[2].gpio_select = 0;
ant_gpio_config.gpio_cfg[2].gpio_num = 0;

s_wifi_event_group = xEventGroupCreate();

tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL) );

wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
wifi_config_t wifi_config = {
.sta = {
.ssid = EXAMPLE_ESP_WIFI_SSID,
.password = EXAMPLE_ESP_WIFI_PASS
},
};

if (ESP_OK != esp_wifi_set_ant_gpio(&ant_gpio_config))
{
ESP_LOGI(TAG, "fail to set ant gpio.");
while (1);
}
if (ESP_OK != esp_wifi_set_ant(&ant_config))
{
ESP_LOGI(TAG, "fail to set ant config.");
while (1);
}

ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
ESP_ERROR_CHECK(esp_wifi_start() );
......