Hi, I need know how i do run the Interruption UART1 and 2
I did this and the uart1 working very good, my question is how i do for run the uart2
http://zerothelement21.blogspot.com/201 ... dling.html
static intr_handle_t handle_console; // UART0
static intr_handle_t UART1_NFC; // UART2
for uar0
// ********** Serial ISR0 used, Define UART interrupt subroutine to ackowledge interrupt
static void IRAM_ATTR uart_intr_handle(void *arg){
uint16_t rx_fifo_len;
//uint16_t 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){
bufferByte = UART0.fifo.rw_byte; //
switch(bufferByte){ //
case 'a': // start
start_nfc=1;
break; // Enter -> Habilita Flag para procesar Comando en Main
default:
if (start_nfc) {
if (bufferByte == 'b'){ // End
moduleResonseBuffer[moduleBufferIndex] = 0; // Add Null terminator
messageReady= 1; // Messeger ok
moduleBufferIndex = 0; // Prepare index for next message
start_nfc=0; // Prepare next message
}
else // Start
{
moduleResonseBuffer[moduleBufferIndex++] = bufferByte; // Add Byte to Buffer
}
}
break;
}
//rxbuf[i++] = UART0.fifo.rw_byte; // read all bytes
rx_fifo_len--;
}
uart_clear_intr_status(UART_NUM_0, UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR); // after reading bytes from buffer clear UART interrupt status
// uart_write_bytes(EX_UART_NUM, (const char*) "RX Done", 7); // a test code or debug code to indicate UART receives successfully, you can redirect received byte as echo also
}
for uart2
// ********** Serial ISR2 used, Define UART interrupt subroutine to ackowledge interrupt
static void IRAM_ATTR uart_intr_handle2(void *arg){
uint16_t rx_fifo_len;
//uint16_t status;
//uint16_t i=0;
//status = UART0.int_st.val; // read UART interrupt Status
rx_fifo_len = UART2.status.rxfifo_cnt; // read number of bytes in UART buffer
while(rx_fifo_len){
bufferByte = UART2.fifo.rw_byte; //
switch(bufferByte){ //
case 's': // 0x02 Start 0x02|...8/10/16ASCII...|0x03
start_nfc=1;
break; // Enter -> Habilita Flag para procesar Comando en Main
default:
if (start_nfc) {
if (bufferByte == 'p'){ // 0x03 End
moduleResonseBuffer[moduleBufferIndex] = 0; // Add Null terminator
messageReady= 1; // Messeger ok
moduleBufferIndex = 0; // Prepare index for next message
start_nfc=0; // Prepare next message
}
else // Start
{
moduleResonseBuffer[moduleBufferIndex++] = bufferByte; // Add Byte to Buffer
}
}
break;
}
//rxbuf[i++] = UART0.fifo.rw_byte; // read all bytes
rx_fifo_len--;
}
uart_clear_intr_status(UART_NUM_2, UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR); // after reading bytes from buffer clear UART interrupt status
}
in main
// ************************************************************* Config for UART2
//Install UART driver, and get the queue.
//esp_err_t ret = ESP_OK;
const 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_2, &uart_config));
//Set UART pins (using UART0 default pins ie no changes.)
ESP_ERROR_CHECK(uart_set_pin(UART_NUM_2, TXD2_PIN, RXD2_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
//Install UART driver, and get the queue.
ESP_ERROR_CHECK(uart_driver_install(UART_NUM_2, BUF_SIZE * 2, 0, 0, NULL, 0));
// release the pre registered UART handler/subroutine
ESP_ERROR_CHECK(uart_isr_free(UART_NUM_2));
// register new UART subroutine
ESP_ERROR_CHECK(uart_isr_register(UART_NUM_2,uart_intr_handle2, NULL, ESP_INTR_FLAG_IRAM, &UART1_NFC));
// enable RX interrupt
ESP_ERROR_CHECK(uart_enable_rx_intr(UART_NUM_2));
The uar0 working good, but not uart0, neve run the interrupt
uart 0 and 2 interrupts
Re: uart 0 and 2 interrupts
I think I know why you're having this issue,
UART 0 is the debugging uart by default so this could be why it's not working.
Try using UART 1 instead and that might fix your issue.
UART 0 is the debugging uart by default so this could be why it's not working.
Try using UART 1 instead and that might fix your issue.
Who is online
Users browsing this forum: No registered users and 422 guests