uart_write_bytes doesn't print anything on minicom when esp_wifi_init is called.

nmtrivedi
Posts: 6
Joined: Wed Jan 04, 2017 2:10 pm

uart_write_bytes doesn't print anything on minicom when esp_wifi_init is called.

Postby nmtrivedi » Mon Jan 23, 2017 10:10 am

I am using ESP32_Core_board_v2. I am facing issue in uart_write_bytes API (using UART_NUM_0) that if I do esp_wifi_init before writing to UART, nothing is printed on the console. If I comment out esp_wifi_init then I can see uart prints. Below is the application I am using to test this. Please let me know if I am missing anything here.

Code: Select all

#include "esp_err.h"
#include "esp_log.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "freertos/event_groups.h"
#include "esp_event.h"
#include "esp_wps.h"
#include "esp_interface.h"
#include "esp_wifi_types.h"
#include "esp_wifi.h"
#include "nvs.h"
#include "driver/uart.h"


static esp_err_t _EventHandler(void *ctx, system_event_t *event)
{
	switch(event->event_id) {
	case SYSTEM_EVENT_STA_START:
		esp_wifi_connect();
		break;
	case SYSTEM_EVENT_STA_GOT_IP:
		printf("Got IP.....\n");
		break;
	case SYSTEM_EVENT_STA_DISCONNECTED:
		esp_wifi_connect();
		printf("WLAN Disconnected\n");
		break;
	case SYSTEM_EVENT_AP_START:
		break;
	case SYSTEM_EVENT_STA_WPS_ER_SUCCESS:
		break;
	case SYSTEM_EVENT_AP_STACONNECTED:
		break;
	default:
		break;
	}
	return ESP_OK;
}



void app_main() {

	if(ESP_OK != nvs_flash_init())
	{
		printf("Failed to initialize nvs\n");
	}
	uart_config_t uart_config = {
			.baud_rate = 115200,                    //baudrate
			.data_bits = UART_DATA_8_BITS,                       //data bit mode
			.parity = UART_PARITY_DISABLE,                       //parity mode
			.stop_bits = UART_STOP_BITS_1,                       //stop bit mode
			.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,               //hardware flow control(cts/rts)
			.rx_flow_ctrl_thresh = 120,                          //flow control threshold
	};
	// Configure UART Parameter
	if(ESP_OK != uart_param_config(UART_NUM_0, &uart_config))
	{
		printf("Failed to configure uart parameters\n");
	}
	if(ESP_OK != uart_driver_install(UART_NUM_0, 512, 512, 0, 0, 0))
	{
		printf("Failed to initialize driver\n");
	}

	esp_err_t ret;
	tcpip_adapter_init();

	ret = esp_event_loop_init(_EventHandler, NULL);
	if(ret != ESP_OK)
	{
		printf("Failed to initialize event loop : %d\n", ret);
	}
	wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
#if 1
	// Init Wi-Fi
	ret = esp_wifi_init(&cfg);
	if(ret != ESP_OK)
	{
		printf("Failed to initialize Wi-Fi : %d\n", ret);
	}
#endif
    int bytes = uart_write_bytes(UART_NUM_0, "Hello!\r\n", strlen("Hello!\r\n"));
	printf("Wrote: %d bytes\n", bytes);
}
    

daiwei
Posts: 1
Joined: Tue Jan 10, 2017 8:31 am

Re: uart_write_bytes doesn't print anything on minicom when esp_wifi_init is called.

Postby daiwei » Mon Feb 06, 2017 4:32 pm

Hi,
I have tested your code on my side. I can get output "Hello" no matter wifi init or not. Could you please try it again? Thanks a lot.

Who is online

Users browsing this forum: No registered users and 168 guests