Skip to content

Commit

Permalink
mcp960x: fix incorrect I2C addressing
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleRus committed Apr 13, 2022
1 parent a43fa64 commit ccdacdd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/mcp960x/mcp960x.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ esp_err_t mcp960x_init_desc(mcp960x_t *dev, uint8_t addr, i2c_port_t port, gpio_
{
CHECK_ARG(dev);

if (addr != (MCP9600_ADDR) && addr != (MCP9601_ADDR))
if (addr < (MCP960X_ADDR_BASE) || addr > (MCP960X_ADDR_DEFAULT))
{
ESP_LOGE(TAG, "Invalid I2C address");
return ESP_ERR_INVALID_ARG;
Expand Down
10 changes: 8 additions & 2 deletions components/mcp960x/mcp960x.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@
extern "C" {
#endif

#define MCP9600_ADDR 0x40
#define MCP9601_ADDR 0x41
/**
* Basic I2C address. Device support 8 addresses, ranging from 0x60 to 0x67.
*/
#define MCP960X_ADDR_BASE 0x60
/**
* Default I2C address (ADDR pin is floating).
*/
#define MCP960X_ADDR_DEFAULT 0x67

#define MCP960X_FILTER_OFF 0
#define MCP960X_FILTER_MAX 7
Expand Down
2 changes: 1 addition & 1 deletion examples/mcp960x/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string.h>

#define I2C_PORT 0
#define I2C_ADDR MCP9601_ADDR
#define I2C_ADDR MCP960X_ADDR_DEFAULT
#define SENSORS_COUNT 4

/* 5 pins for 4 sensors */
Expand Down

0 comments on commit ccdacdd

Please sign in to comment.