Colision between freemodbus in slave mode and Wi-Fi started with direct c function calls

havra553
Posts: 1
Joined: Tue Apr 25, 2023 4:48 pm

Colision between freemodbus in slave mode and Wi-Fi started with direct c function calls

Postby havra553 » Wed Apr 26, 2023 9:15 am

I have a project that utilizes both Espressif's freemodbus implementation (via RS232 to RS485 convertor connected to pins 16, 17 and control pin to 18) and uses Wi-Fi in promiscuous mode. When Wi-Fi is used as AP/connected to and AP Modbus works correctly (can normally communicate, signal on RTS pin is present.) That being said after starting Wi-Fi in promiscuous mode used to capture Wi-Fi probe requests with:

Code: Select all

	tcpip_adapter_init();
	wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
	ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
	ESP_ERROR_CHECK( esp_wifi_set_country(&wifi_country) );
	ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
	ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_NULL) );
	ESP_ERROR_CHECK( esp_wifi_start() );

	const wifi_promiscuous_filter_t filt = {
		.filter_mask = WIFI_EVENT_MASK_AP_PROBEREQRECVED
	};
	ESP_ERROR_CHECK(esp_wifi_set_channel(WIFI_CHANNEL, WIFI_SECOND_CHAN_NONE));
	ESP_ERROR_CHECK(esp_wifi_set_promiscuous_filter(&filt));
	ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&WiFiSniffer::wifiSnifferPacketHandler));
	ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true));
Modbus RTS signal stops either immediately stops or stops after few second. Same goes for TX signal. Just to be clear when device starts right away with Wi-Fi in promiscuous mode active, instead of acting as AP, problem still persists. When filtering uout what function call leads to this behavior esp_wifi_set_promiscuous_rx_cb was found to be responsible.

ESP_alisitsyn
Posts: 203
Joined: Fri Feb 01, 2019 4:02 pm
Contact:

Re: Colision between freemodbus in slave mode and Wi-Fi started with direct c function calls

Postby ESP_alisitsyn » Tue Jun 06, 2023 7:54 am

Hi @havra553 ,

I can recommend you to change the affinity option for Modbus task to run in on CPU1. This can be done through `idf.py menuconfig` the option is CONFIG_FMB_PORT_TASK_AFFINITY_CPU1. Also, you need to place the UART interrupt handler into IRAM (the option: CONFIG_UART_ISR_IN_IRAM).

Who is online

Users browsing this forum: No registered users and 96 guests