static bool I2C_WriteAccelReg(I2C_Type *base, uint8_t device_addr, uint8_t reg_addr, uint8_t value)
{
i2c_master_transfer_t masterXfer;
memset(&masterXfer, 0, sizeof(masterXfer));
masterXfer.slaveAddress = device_addr;
masterXfer.direction = kI2C_Write;
masterXfer.subaddress = reg_addr;
masterXfer.subaddressSize = 1;
masterXfer.data = &value;
masterXfer.dataSize = 1;
masterXfer.flags = kI2C_TransferDefaultFlag;
/* direction=write : start+device_write;cmdbuff;xBuff; */
/* direction=recive : start+device_write;cmdbuff;repeatStart+device_read;xBuff; */
I2C_MasterTransferNonBlocking(BOARD_ACCEL_I2C_BASEADDR, &g_m_handle, &masterXfer);
/* wait for transfer completed. */
while ((!nakFlag) && (!completionFlag))
{
}
nakFlag = false;
if (completionFlag == true)
{
completionFlag = false;
return true;
}
else
{
return false;
}
}
## I want to transfer 8byte data. but there are just only 1byte. how can put in 8byte data ?
plz help
## masterXferdata is uint8_t
Solved! Go to Solution.
Hi @yhu1992, I hope you're doing well!
You can change the number of bytes sent in a transfer by changing the size element of the masterXfer structure to the desired amount of bytes:
i2c_master_transfer_t masterXfer;
memset(&masterXfer, 0, sizeof(masterXfer));
masterXfer.slaveAddress = device_addr;
masterXfer.direction = kI2C_Write;
masterXfer.subaddress = reg_addr;
masterXfer.subaddressSize = 1;
masterXfer.data = &value;
masterXfer.dataSize = 8; // change this value
masterXfer.flags = kI2C_TransferDefaultFlag;
masterXfer.data is a pointer to the starting address of the data which will be sent, so it can be assigned to an array of uint8_t.
Please let me know if you need any more information.
Best regards,
Sebastian
Hi @yhu1992, I hope you're doing well!
You can change the number of bytes sent in a transfer by changing the size element of the masterXfer structure to the desired amount of bytes:
i2c_master_transfer_t masterXfer;
memset(&masterXfer, 0, sizeof(masterXfer));
masterXfer.slaveAddress = device_addr;
masterXfer.direction = kI2C_Write;
masterXfer.subaddress = reg_addr;
masterXfer.subaddressSize = 1;
masterXfer.data = &value;
masterXfer.dataSize = 8; // change this value
masterXfer.flags = kI2C_TransferDefaultFlag;
masterXfer.data is a pointer to the starting address of the data which will be sent, so it can be assigned to an array of uint8_t.
Please let me know if you need any more information.
Best regards,
Sebastian