提交 95123681 编写于 作者: J Jason K 提交者: GitHub

Merge pull request #754 from stickbreaker/master

Correct 10bit Device address handling.
...@@ -177,10 +177,13 @@ i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * dat ...@@ -177,10 +177,13 @@ i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * dat
//CMD WRITE(ADDRESS + DATA) //CMD WRITE(ADDRESS + DATA)
if(!index) { if(!index) {
i2c->dev->fifo_data.data = address & 0xFF; if(addr_10bit){// address is leftshifted with Read/Write bit set
dataSend--; i2c->dev->fifo_data.data = (((address >> 8) & 0x6) | 0xF0); // send a9:a8 plus 1111 0xxW mask
if(addr_10bit) { i2c->dev->fifo_data.data = ((address >> 1) & 0xFF); // send a7:a0, remove W bit (7bit address style)
i2c->dev->fifo_data.data = (address >> 8) & 0xFF; dataSend -= 2;
}
else { // 7bit address
i2c->dev->fifo_data.data = address & 0xFF;
dataSend--; dataSend--;
} }
} }
...@@ -286,9 +289,12 @@ i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * data ...@@ -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); i2cSetCmd(i2c, cmdIdx++, I2C_CMD_RSTART, 0, false, false, false);
//CMD WRITE ADDRESS //CMD WRITE ADDRESS
i2c->dev->fifo_data.val = address & 0xFF; if (addr_10bit) { // address is left-shifted with Read/Write bit set
if(addr_10bit) { i2c->dev->fifo_data.data = (((address >> 8) & 0x6) | 0xF1); // send a9:a8 plus 1111 0xxR mask
i2c->dev->fifo_data.val = (address >> 8) & 0xFF; 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); i2cSetCmd(i2c, cmdIdx++, I2C_CMD_WRITE, addrLen, false, false, true);
nextCmdCount = cmdIdx; nextCmdCount = cmdIdx;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册