esp-open-rtos/examples/pcf8591/main.c

43 lines
906 B
C
Raw Normal View History

2017-04-23 08:35:23 +00:00
#include <stdio.h>
2017-04-25 16:57:40 +00:00
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "i2c/i2c.h"
#include "pcf8591/pcf8591.h"
2017-04-23 08:35:23 +00:00
2017-09-01 09:29:32 +00:00
#define ADDR PCF8591_DEFAULT_ADDRESS
#define I2C_BUS 0
2017-04-23 08:35:23 +00:00
#define SCL_PIN 5
#define SDA_PIN 4
2017-04-25 16:57:40 +00:00
static void measure(void *pvParameters)
{
2017-09-01 09:29:32 +00:00
i2c_dev_t dev = {
.addr = ADDR,
.bus = I2C_BUS,
};
2017-04-25 16:57:40 +00:00
while (1)
{
vTaskDelay(1000 / portTICK_PERIOD_MS);
2017-10-12 19:49:15 +00:00
printf("Value: %d\n", pcf8591_read(&dev, PCF8591_IC_4_SINGLES, 3));
2017-04-25 16:57:40 +00:00
}
}
2017-04-23 08:35:23 +00:00
void user_init(void)
{
uart_set_baud(0, 115200);
2017-04-25 16:57:40 +00:00
// Just some information
printf("\n");
printf("SDK version : %s\n", sdk_system_get_sdk_version());
printf("GIT version : %s\n", GITSHORTREV);
2017-04-23 08:35:23 +00:00
2017-09-01 09:29:32 +00:00
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
2017-04-23 08:35:23 +00:00
2017-04-25 16:57:40 +00:00
xTaskCreate(measure, "measure_task", 256, NULL, 2, NULL);
2017-04-23 08:35:23 +00:00
}