Replies: 1 comment
-
sorry for the long post, i appreciate any help. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi! I'm having problems initializing max17048. The problem is that as soon as i use "max1704x_quickstart(&dev)" the i2c driver fails to install and my esp32-c3 goes into a boot loop. If i don't use the "max1704x_quickstart(&dev)" the device doesn't initialise and nothing in my max.c file is logged, but the bme280 works as it should.
this is my max file.
`/*
*/
#include <driver/i2c.h>
#include <esp_err.h>
#include <hal/gpio_types.h>
#include <hal/i2c_types.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <freertos/event_groups.h>
#include <freertos/portmacro.h>
#include <freertos/projdefs.h>
#include <freertos/task.h>
#include "esp_log.h"
#include "esp_mac.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_http_client.h"
#include <max1704x.h>
#include "driver/i2c_master.h"
#include "freertos/FreeRTOS.h"
#include <sys/socket.h>
#include "esp_http_client.h"
#define SERVER_URL "http://10.245.30.119:3000/insert-data"
static const char *MAX17048_TAG = "MAX17048";
#define SDA_PIN GPIO_NUM_0
#define SCL_PIN GPIO_NUM_1
TaskHandle_t max_reader_task_handle = NULL;
void max_reader_task(void *device_name_ptr){
}
void max_main(void)
{
}
`
i then call the max_main function on my main file, where i also initialise i2c
`#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <freertos/event_groups.h>
#include <freertos/portmacro.h>
#include <freertos/projdefs.h>
#include "esp_system.h"
#include "esp_mac.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "esp_bt.h"
#include "esp_sleep.h"
#include "driver/gpio.h"
#include <driver/i2c.h>
#include <esp_err.h>
#include <hal/gpio_types.h>
#include <hal/i2c_types.h>
#include "esp_blufi_api.h"
#include "ble.h"
#include "wifi.h"
#include "sensor_func.h"
#include <bme280.h>
#include "max1704x.h"
#include "esp_blufi.h"
#include "i2cdev.h"
#include "esp_idf_lib_helpers.h"
#include "sdkconfig.h"
#include "max.h"
#include "esp_console.h"
#define BLE_BUTTON GPIO_NUM_10
#define SDA_PIN GPIO_NUM_0
#define SCL_PIN GPIO_NUM_1
#define DEEP_SLEEP_PERIOD ((10 * 1000) / portTICK_PERIOD_MS) // 15 minutes in milliseconds
#define I2C_MASTER_NUM I2C_NUM_0
#define I2C_MASTER_FREQ_HZ 400000
#define I2C_MASTER_TX_BUF_DISABLE 0
#define I2C_MASTER_RX_BUF_DISABLE 0
#define WRITE_BIT I2C_MASTER_WRITE /!< I2C master write /
#define READ_BIT I2C_MASTER_READ /!< I2C master read /
#define ACK_CHECK_EN 0x1 /!< I2C master will check ack from slave/
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave /
#define ACK_VAL 0x0 /!< I2C ack value /
#define NACK_VAL 0x1 /!< I2C nack value */
volatile int value = 0;
volatile bool nvs_cleared = false;
volatile bool button_pressed = false;
volatile bool switch_case = false; // false for WiFi, true for BLUFI
void clear_nvs_partition() {
if (!nvs_cleared) {
esp_err_t ret;
}
void switch_mode() {
switch_case = !switch_case; // Toggle the mode
}
void button_callback(void* arg) {
button_pressed = true;
}
int do_i2cdetect_cmd(int argc, char **argv);
void i2c_master_init()
{
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = SDA_PIN,
.scl_io_num = SCL_PIN,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ
};
ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf));
ESP_ERROR_CHECK(i2c_driver_install(I2C_MASTER_NUM, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0));
}
int do_i2cdetect_cmd(int argc, char **argv) {
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n");
for (int i = 0; i < 128; i += 16) {
printf("%02x: ", i);
for (int j = 0; j < 16; j++) {
int ret;
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (i + j) << 1 | WRITE_BIT, ACK_CHECK_EN);
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 10 / portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmd);
}
void app_main(void) {
}
`
I also have a bme280 running with the official library
`/*
*/
#include <bme280.h>
#include <driver/i2c.h>
#include <esp_err.h>
#include <hal/gpio_types.h>
#include <hal/i2c_types.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <freertos/event_groups.h>
#include <freertos/portmacro.h>
#include <freertos/projdefs.h>
#include <freertos/task.h>
#include "sensor_func.h"
#include "esp_log.h"
#include "esp_http_client.h"
#include <max1704x.h>
#define SERVER_URL "http://10.245.30.119:3000/insert-data"
#define SDA_PIN GPIO_NUM_0
#define SCL_PIN GPIO_NUM_1
#define TAG_BME280 "BME280"
#define I2C_MASTER_ACK 0
#define I2C_MASTER_NACK 1
volatile double temp = 0.0;
volatile double hum = 0.0;
volatile double press = 0.0;
volatile bool data_ready = false; // Flag to indicate new data is ready
s8 BME280_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
s32 iError = BME280_INIT_VALUE;
}
s8 BME280_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
s32 iError = BME280_INIT_VALUE;
esp_err_t espRc;
}
void BME280_delay_msek(u32 msek)
{
vTaskDelay(msek/portTICK_PERIOD_MS);
}
void send_data_http(double temperature, double humidity) {
esp_http_client_config_t config = {
.url = SERVER_URL,
};
esp_http_client_handle_t client = esp_http_client_init(&config);
if (client == NULL) {
ESP_LOGE(TAG_BME280, "Failed to initialize HTTP client");
return;
}
}
void bme_reading(void pvParameters)
{
/ --------------------------------------- INIT BME280 -------------------------------------- */
struct bme280_t bme280 = {
.bus_write = BME280_I2C_bus_write,
.bus_read = BME280_I2C_bus_read,
.dev_addr = BME280_I2C_ADDRESS1,
.delay_msec = BME280_delay_msek
};
}
void bme280_sensor_func(const char *device_name)
{
}
`
Beta Was this translation helpful? Give feedback.
All reactions