USART can't receive anything

DummyForALife
Posts: 2
Joined: Tue Oct 29, 2019 9:50 pm

USART can't receive anything

Postby DummyForALife » Wed Dec 04, 2019 12:25 pm

Hello guys,

I have this very specific problem with ESP. I have to simulate impulses with a different microcontroller, send it to my esp32 via UART(this is something I choose myself, but I'm flexible in terms of changing to SPI or I2C if it's necessary).
My problem is that I send out the data from the other microcontroler( checked via logic analizer), but my ISR never receive any interrupts on my ESP32.
Here is my intr_handle function

Code: Select all

static void IRAM_ATTR uart_intr_handle(void *arg)
{
  uint16_t rx_fifo_len, status;
  uint16_t i=0;
  
  status = UART0.int_st.val; // read UART interrupt Status
  rx_fifo_len = UART0.status.rxfifo_cnt; // read number of bytes in UART buffer
  
  while(rx_fifo_len)
  {
   rxbuf[i++] = UART0.fifo.rw_byte; // read all bytes
   rx_fifo_len--;
  }

 // after reading bytes from buffer clear UART interrupt status
 uart_clear_intr_status(EX_UART_NUM, UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR);

// a test code or debug code to indicate UART receives successfully,
// you can redirect received byte as echo also
 uart_write_bytes(EX_UART_NUM, (const char*) "RX Done", 7);
}
With this configuration:

Code: Select all

void app_main()
{
	wifi_init_sta();
	vTaskDelay(10000 / portTICK_RATE_MS);
    	esp_log_level_set(uart_tag, ESP_LOG_INFO);
	uart_config_t uart_config = {
		.baud_rate = 9600,
		.data_bits = UART_DATA_8_BITS,
		.parity = UART_PARITY_DISABLE,
		.stop_bits = UART_STOP_BITS_1,
		.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
	};

	ESP_ERROR_CHECK(uart_param_config(EX_UART_NUM, &uart_config));

	//Set UART log level
	esp_log_level_set(uart_tag, ESP_LOG_INFO);

	//Set UART pins (using UART0 default pins ie no changes.)
	ESP_ERROR_CHECK(uart_set_pin(EX_UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));

	//Install UART driver, and get the queue.
	ESP_ERROR_CHECK(uart_driver_install(EX_UART_NUM, BUF_SIZE * 2, 0, 0, NULL, 0));

	// release the pre registered UART handler/subroutine
	ESP_ERROR_CHECK(uart_isr_free(EX_UART_NUM));

	// register new UART subroutine
	ESP_ERROR_CHECK(uart_isr_register(EX_UART_NUM,uart_intr_handle, NULL, ESP_INTR_FLAG_IRAM, &handle_console));

	// enable RX interrupt
	ESP_ERROR_CHECK(uart_enable_rx_intr(EX_UART_NUM));
}
I want to use this code to send the data that my ESP32 receives through WiFi to an MQTT broker.

PS: I tried to print some strings out from my ISR and from anywhere else. It worked everywher, but from the ISR.

Thanks for your help!

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 130 guests