mkw36a512xxx4 i2c Sequential Write

cancel
Showing results for 
Search instead for 
Did you mean: 

mkw36a512xxx4 i2c Sequential Write

Jump to solution
320 Views
yhu1992
Contributor I

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

Labels (1)
Tags (3)
0 Kudos
1 Solution
294 Views
Sebastian_Del_Rio
NXP TechSupport
NXP TechSupport

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

View solution in original post

0 Kudos
1 Reply
295 Views
Sebastian_Del_Rio
NXP TechSupport
NXP TechSupport

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

View solution in original post

0 Kudos