Skip to content

Correct 10bit Device address handling. #754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions cores/esp32/esp32-hal-i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,13 @@ i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * dat

//CMD WRITE(ADDRESS + DATA)
if(!index) {
i2c->dev->fifo_data.data = address & 0xFF;
dataSend--;
if(addr_10bit) {
i2c->dev->fifo_data.data = (address >> 8) & 0xFF;
if(addr_10bit){// address is leftshifted with Read/Write bit set
i2c->dev->fifo_data.data = (((address >> 8) & 0x6) | 0xF0); // send a9:a8 plus 1111 0xxW mask
i2c->dev->fifo_data.data = ((address >> 1) & 0xFF); // send a7:a0, remove W bit (7bit address style)
dataSend -= 2;
}
else { // 7bit address
i2c->dev->fifo_data.data = address & 0xFF;
dataSend--;
}
}
Expand Down Expand Up @@ -286,9 +289,12 @@ i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data
i2cSetCmd(i2c, cmdIdx++, I2C_CMD_RSTART, 0, false, false, false);

//CMD WRITE ADDRESS
i2c->dev->fifo_data.val = address & 0xFF;
if(addr_10bit) {
i2c->dev->fifo_data.val = (address >> 8) & 0xFF;
if (addr_10bit) { // address is left-shifted with Read/Write bit set
i2c->dev->fifo_data.data = (((address >> 8) & 0x6) | 0xF1); // send a9:a8 plus 1111 0xxR mask
i2c->dev->fifo_data.data = ((address >> 1) & 0xFF); // send a7:a0, remove R bit (7bit address style)
}
else { // 7bit address
i2c->dev->fifo_data.data = address & 0xFF;
}
i2cSetCmd(i2c, cmdIdx++, I2C_CMD_WRITE, addrLen, false, false, true);
nextCmdCount = cmdIdx;
Expand Down