Hi Team, Seeking for some assistance for a customer.
Wrapper to communicate on a i2c bus. this one looks like this:
int8_t user_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr) { int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */ uint8_t i = 0; /* * The parameter intf_ptr can be used as a variable to store the I2C address of the device */ /* * Data on the bus should be like * |------------+---------------------| * | I2C action | Data | * |------------+---------------------| * | Start | - | * | Write | (reg_addr) | * | Stop | - | * | Start | - | * | Read | (reg_data[0]) | * | Read | (....) | * | Read | (reg_data[len - 1]) | * | Stop | - | * |------------+---------------------| */ I2CMasterSlaveAddrSet(I2C0_BASE, *(uint8_t *)intf_ptr, false); I2CMasterDataPut(I2C0_BASE, reg_addr); I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_SINGLE_SEND); while (I2CMasterBusy(I2C0_BASE)) { } I2CMasterSlaveAddrSet(I2C0_BASE, *(uint8_t *)intf_ptr, false); if ( len == 1){ I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_SINGLE_RECEIVE); while (I2CMasterBusy(I2C0_BASE)) ; reg_data[0] = I2CMasterDataGet(I2C0_BASE); }else { I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_START); while (I2CMasterBusy(I2C0_BASE)) ; reg_data[0] = I2CMasterDataGet(I2C0_BASE); for(i = 0 ; i < len -2 ; i++){ I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_CONT); while (I2CMasterBusy(I2C0_BASE)) ; reg_data[i+1] = I2CMasterDataGet(I2C0_BASE); } I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_FINISH); while (I2CMasterBusy(I2C0_BASE)) ; reg_data[i+1] = I2CMasterDataGet(I2C0_BASE); return rslt; }
On the scope to see what is happening on the bus is see the following :
The Address is correct and the Data send is also okay but i am wondering why the second slot is not a read slot. The master sends tow times the same. I nee the first slot like we see and the second slot must be a read slot on the same Adress. if you need some more informations pleas let me know. thank you for your help.
Thank you in advance for your help.
-Mark