#include #include "esp_err.h" #include "driver/gpio.h" #include "esp_spi_flash.h" #include "esp_types.h" #include "esp_err.h" #include "esp_log.h" #include "driver/uart.h" #include "driver/adc.h" #include "rtos_tasks.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/queue.h" #include "freertos/semphr.h" #include "freertos/ringbuf.h" #include "esp_attr.h" #include "esp8266/uart_struct.h" #include "esp8266/uart_register.h" #include "esp8266/pin_mux_register.h" #include "esp8266/eagle_soc.h" #include "esp8266/rom_functions.h" #include "rom/ets_sys.h" #include "driver/uart_select.h" uint8_t rxbuf[256]; uint16_t final_recvd_bytes = 0; void IRAM_ATTR uart_intr_handle(void *arg) { uint16_t rx_fifo_len, status; uint16_t i = 0; status = uart0.int_st.val; rx_fifo_len = uart0.status.rxfifo_cnt; while(rx_fifo_len){ rxbuf[i++] = uart0.fifo.rw_byte; rx_fifo_len--; } final_recvd_bytes = i; // after reading bytes from buffer clear UART interrupt status uart_clear_intr_status(UART_NUM_0, UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR); } void IR_RxTx_task() { printf("IR TASK STARTED\n"); char dataRecvdFromMobileApp[9] = {0x7E, 0xA0, 0x07, 0x03, 0x41, 0x93, 0x5A, 0x64, 0x7E}; //when these bytes are sent to the interfaced module, it send the response. while (1) { vTaskDelay(1000 / portTICK_PERIOD_MS); /*for(int i = 0; i < 9; i++) printf("Byte sent = 0x%X\n", dataRecvdFromMobileApp[i]);*/ uart_write_bytes(UART_NUM_0, (const char *) dataRecvdFromMobileApp, 9); if(final_recvd_bytes > 0) { printf("Total bytes recvd = %d\n", final_recvd_bytes); for(int i = 0; i < final_recvd_bytes; i++) printf("Byte received = 0x%X\n", rxbuf[i]); final_recvd_bytes = 0; } } } void app_main() { int ret; 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(UART_NUM_0, &uart_config)); ESP_ERROR_CHECK(uart_driver_install(UART_NUM_0, BUF_SIZE * 2, 0, 0, NULL, 0)); ESP_ERROR_CHECK(uart_isr_register(UART_NUM_0,uart_intr_handle, NULL); ESP_ERROR_CHECK(uart_enable_rx_intr(UART_NUM_0)); xTaskCreate(IR_RxTx_task,"IR_Task",8192,NULL, configMAX_PRIORITIES-1, &ir_task); }