Skip to content
Snippets Groups Projects
Commit c329a641 authored by Eirik-MS's avatar Eirik-MS
Browse files

added init for i2c DAC

parent 099eeb42
No related branches found
No related tags found
No related merge requests found
#include "i2c_dac_MCP47FEB.h"
#include "i2c_master.h"
#include "esp_err.h"
i2c_master_bus_config_t mpc_dac_init_conf = {
.i2c_port = I2C_NUM_0,
.sda_io_num = MPC_SDA_PIN,
.scl_io_num = MPC_SCL_PIN,
.clk_source = I2C_CLK_SRC_DEFAULT,
.glitch_ignore_cnt = 7,
.intr_priority = 1,
.flags = 0
};
i2c_device_config_t mpc_dac_slave_conf = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = MPC_ADDR_A0,
.scl_speed_hz = MPC_SPEED,
};
i2c_master_bus_handle_t i2c_bus_handler;
i2c_master_dev_handle_t mpc_dac_dev;
void mpc_dac_init(){
//Allocate a bus and a device for the I2C DAC
ESP_ERROR_CHECK(i2c_new_master_bus(&mpc_dac_init_conf, &i2c_bus_handler));
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c_bus_handler, &mpc_dac_slave_conf, &mpc_dac_dev));
}
#define MCP_I2C_ADDRESS 0x60
#define MPC_SPEED 100000
#define MPC_SDA_PIN 21
#define MPC_SCL_PIN 22
#define MPC_ADDR_A0 0x60
#define MPC_ADDR_A1 0x61
#define MPC_ADDR_A2 0x62
#define MPC_ADDR_A3 0x63
void mpc_dac_init();
\ No newline at end of file
......@@ -9,6 +9,7 @@
#include "alarm_buttons.h"
#include "zigbee_configuration.h"
#include "sleep_configuration.h"
#include "i2c_dac_MCP47FEB.h"
// TODO:
// Find a nice way to give a device a unique ID after flashing
......@@ -27,6 +28,9 @@ void app_init(void)
/* Initialize the Zigbee stack */
initialize_zigbee();
/* Initialize I2C for DAC*/
mpc_dac_init();
}
void app_main(void)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment