Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
920 B
30
Indexable
Never
void IRAM_ATTR przerwanie_uart(void *arg)
{
	uint8_t *data = (uint8_t *) malloc(1024);
    uint32_t len = uart_read_bytes(UART_NUM_0, data, 1024, 20/portTICK_RATE_MS);
	data[len] = 0;
    //char data[] = "hello";
    uart_write_bytes(UART_NUM_0, (const char *)data, 6);
    uart_flush(UART_NUM_0);
    uart_clear_intr_status(UART_NUM_0, UART_INTR_MASK);
	free(dataa);
}


void app_main(void)
{
    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
    };
    
    uart_driver_install(UART_NUM_0, 1024 * 2, 0, 0, NULL, 0);
    uart_param_config(UART_NUM_0, &uart_config);
    
    uart_isr_register(UART_NUM_0, przerwanie_uart, NULL);
    uart_enable_rx_intr(UART_NUM_0);


    while(1)
    {
        vTaskDelay(10000 / portTICK_PERIOD_MS);
    }
}