There are two issues here:

  1. The warning: 'passing argument 2 of 'uart_read_bytes' makes pointer from integer without a cast'

This warning indicates that you are passing an integer value to a function that expects a pointer. In this case, you are passing the variable 'data' to 'uart_read_bytes()', but 'data' is an 'uint8_t' variable, which is an integer type, not a pointer. To fix this, you need to pass the address of 'data' instead of 'data' itself. You can do this by using the '&' operator:

rxBytes = uart_read_bytes(UART_NUM_0, &data, 1, 20 / portTICK_PERIOD_MS);
  1. The error: 'data' is used uninitialized'

This error indicates that you are using the variable 'data' before initializing it. In this case, you are trying to read one byte of data into 'data' using 'uart_read_bytes()', but 'data' has not been assigned a value yet. To fix this, you need to initialize 'data' before using it:

uint8_t data = 0;
rxBytes = uart_read_bytes(UART_NUM_0, &data, 1, 20 / portTICK_PERIOD_MS);
ESP32 UART 读取数据错误:指针转换和未初始化变量

原文地址: https://www.cveoy.top/t/topic/fZeG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录