wip, doesnt work

modbus
Ondřej Hruška 3 years ago
parent 83d62c0ef7
commit 7c1c0203c0
  1. 2
      main/app_main.c
  2. 13
      main/co2_sensor.c
  3. 43
      main/periph_init.c

@ -59,7 +59,7 @@ void app_main(void) {
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
xTaskCreatePinnedToCore(voc_read_task, "VOC", 4096, NULL, PRIO_NORMAL, NULL, 1); //xTaskCreatePinnedToCore(voc_read_task, "VOC", 4096, NULL, PRIO_NORMAL, NULL, 1);
xTaskCreatePinnedToCore(co2_read_task, "CO2", 4096, NULL, PRIO_NORMAL, NULL, 1); xTaskCreatePinnedToCore(co2_read_task, "CO2", 4096, NULL, PRIO_NORMAL, NULL, 1);
// xTaskCreate(co2_read_task, "CO2", 4096, NULL, PRIO_NORMAL, NULL); // xTaskCreate(co2_read_task, "CO2", 4096, NULL, PRIO_NORMAL, NULL);

@ -31,10 +31,8 @@ void co2_read_task(void *param) {
uint8_t buffer[128]; uint8_t buffer[128];
while (1) { while (1) {
vTaskDelay(pdMS_TO_TICKS(2000)); vTaskDelay(pdMS_TO_TICKS(2000));
uint16_t ppm = 0; uint16_t ppm = 0;
int i = 0; int i = 0;
@ -42,20 +40,23 @@ void co2_read_task(void *param) {
buffer[i++] = 0x04; buffer[i++] = 0x04;
buffer[i++] = 0x00; buffer[i++] = 0x00;
buffer[i++] = 0x00; buffer[i++] = 0x00;
buffer[i++] = 0x00; buffer[i++] = 0x00;
buffer[i++] = 0x04; buffer[i++] = 0x04;
buffer[i++] = 0xf8; buffer[i++] = 0xf8;
buffer[i++] = 0xf0; buffer[i++] = 0xf0;
ESP_LOGI(TAG, "send %d bytes", i);
uart_write_bytes(CO2_UART_NUM, buffer, i); uart_write_bytes(CO2_UART_NUM, buffer, i);
i = uart_read_bytes(CO2_UART_NUM, buffer, 13, pdMS_TO_TICKS(1000)); i = uart_read_bytes(CO2_UART_NUM, buffer, 13, pdMS_TO_TICKS(1000));
ESP_LOGI(TAG, "received %d bytes", i);
ESP_LOG_BUFFER_HEXDUMP(TAG, buffer, i, ESP_LOG_DEBUG);
if (i != 13) { if (i != 13) {
ESP_LOGE(TAG, "Rx failed"); ESP_LOGE(TAG, "Rx failed");
continue; continue;
} }
ESP_LOG_BUFFER_HEXDUMP(TAG, buffer, i, ESP_LOG_DEBUG);
continue; continue;

@ -61,24 +61,29 @@ esp_err_t periph_init() {
return rv; return rv;
} }
#else #else
const uart_config_t uart_config = { int i2c_co2_port = I2C_NUM_1;
.baud_rate = 9600,
.data_bits = UART_DATA_8_BITS, const uart_config_t uart_config = {
.parity = UART_PARITY_DISABLE, .baud_rate = 9600,
.stop_bits = UART_STOP_BITS_1, .data_bits = UART_DATA_8_BITS,
.use_ref_tick = true .parity = UART_PARITY_DISABLE,
}; .stop_bits = UART_STOP_BITS_1,
ESP_ERROR_CHECK( uart_param_config(UART_NUM_1, &uart_config) ); .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_APB,
// Set UART pins(TX: IO17 (UART2 default), RX: IO16 (UART2 default), RTS: IO18, CTS: IO19) //.use_ref_tick = true
ESP_ERROR_CHECK(uart_set_pin(UART_NUM_2, };
CONFIG_PIN_I2C_SCL1,
CONFIG_PIN_I2C_SDA1, ESP_ERROR_CHECK(uart_driver_install(i2c_co2_port,
UART_PIN_NO_CHANGE, /* rxbuf */ 256, /* txbuf */ 256, /* que */ 0, /* uart que */ NULL, /* alloc flags */ 0));
UART_PIN_NO_CHANGE));
ESP_ERROR_CHECK( uart_param_config(i2c_co2_port, &uart_config) );
ESP_ERROR_CHECK(uart_driver_install(UART_NUM_1,
/* rxbuf */ 256, /* txbuf */ 0, /* que */ 0, /* uart que */ NULL, /* alloc flags */ 0)); // Set UART pins(TX, RX, RTS, CTS)
ESP_ERROR_CHECK(uart_set_pin(i2c_co2_port,
CONFIG_PIN_I2C_SCL1,
CONFIG_PIN_I2C_SDA1,
UART_PIN_NO_CHANGE,
UART_PIN_NO_CHANGE));
#endif #endif
} }
@ -95,7 +100,7 @@ esp_err_t periph_init() {
return rv; return rv;
} }
gpio_set_level(CONFIG_PIN_CO2_COMSEL, 0); // low=I2C gpio_set_level(CONFIG_PIN_CO2_COMSEL, 1); // low=I2C
gpio_set_level(CONFIG_PIN_CO2_EN, 1); // active high gpio_set_level(CONFIG_PIN_CO2_EN, 1); // active high
} }

Loading…
Cancel
Save