ESP32S2 uart problem
Posted: 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:
app_main:
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 !!!
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);
}
}