ESP32S2 uart problem

ankayca
Posts: 14
Joined: Wed Aug 26, 2020 4:58 pm

ESP32S2 uart problem

Postby ankayca » Wed Sep 02, 2020 3:30 pm

I want to receive data byte by byte
I can not find any example for uart interrupt of esp32s2
I step in isr function and receive data 's length but can not find where is data stored.

İsr function:

Code: Select all

static void IRAM_ATTR uart_intr_handle(void *arg)
{
uint16_t len,t=0;
len = UART1.status.rxfifo_cnt;
//printf("%d\r\n",len);
while(len){
	buff[t++]=UART1.ahb_fifo.rw_byte;


	len--;
}
ESP_EARLY_LOGI("hallo bro","this is is : %s",buff[t]);
//sprintf(buff,"this is it!%d",t);
//uart_write_bytes(EX_UART_NUM, (const char*) buff, 40);

 uart_flush(EX_UART_NUM);
 uart_clear_intr_status(EX_UART_NUM, UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR);
 flagdeneme=1;

}

app_main:

Code: Select all

void app_main()
{

	const uart_config_t uart_config = {
	.baud_rate = 115200,
	.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 pins (using UART0 default pins ie no changes.)
	ESP_ERROR_CHECK(uart_set_pin(EX_UART_NUM, GPIO_NUM_17, GPIO_NUM_16, 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));

	gpio_reset_pin(BLINK_GPIO);
	    /* Set the GPIO as a push/pull output */
	gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
	//Uart_Init2();
	while(1){
		printf("hello\n\r");
		 //uart_write_bytes(EX_UART_NUM, (const char*) "selamal1", 7);

		//uart_write_bytes(EX_UART_NUM, (const char*) "RX not Done", 11);
		 uart_write_bytes(EX_UART_NUM, (const char*) "selamal2\r\n", 9);
		 if(flagdeneme){
			 uart_write_bytes(EX_UART_NUM, (const char*) "kaan eve geldi!!!\r\n", sizeof("kaan eve geldi!!!\r\n"));
			 gpio_set_level(BLINK_GPIO, 1);
			 flagdeneme=0;
		 }
		 else{
			 gpio_set_level(BLINK_GPIO, 0);
		 }
		vTaskDelay(1000 / portTICK_PERIOD_MS);
	}



}
I stuck for 1 week. Thanks for any help . If you share with me basic uart interrupt(just receive a byte and transmit it) , I will be thankful !!!

ankayca
Posts: 14
Joined: Wed Aug 26, 2020 4:58 pm

Re: ESP32S2 uart problem

Postby ankayca » Sun Sep 06, 2020 12:42 pm

pump!!!!

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: ESP32S2 uart problem

Postby PeterR » Mon Sep 07, 2020 3:51 pm

Use the driver & request 1 byte with a timeout!
& I also believe that IDF CAN should be fixed.

ankayca
Posts: 14
Joined: Wed Aug 26, 2020 4:58 pm

Re: ESP32S2 uart problem

Postby ankayca » Mon Sep 07, 2020 8:15 pm

how to do that ? can you give an example ?

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Re: ESP32S2 uart problem

Postby PeterR » Tue Sep 08, 2020 11:56 am

https://docs.espressif.com/projects/esp ... /uart.html

Code: Select all

int uart_read_bytes(uart_port_t uart_num, void *buf, uint32_t length, TickType_t ticks_to_wait)
The IDF examples folder will show you more. You do not need to unregister the ISR, just start the standard library & then use above.
& I also believe that IDF CAN should be fixed.

Who is online

Users browsing this forum: Bing [Bot] and 117 guests