transfer data from array to regdata, and regdata to array

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

transfer data from array to regdata, and regdata to array

472 Views
kerim
Contributor I

transfer data from array to regdata but it doesn't work can you help me

int8_t BMP180_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{

	s32 iError = 0;
	u8 array[I2C_BUFFER_LEN]= {0};
	u8 stringpos = 0;
	array[0] = reg_addr;

	//Used in the function I2C_MasterTransferBlocking(...)

	i2c_master_transfer_t masterXfer;

	//Allocate memory for the masterXfer variable
	memset(&masterXfer, 0, sizeof(masterXfer));

	masterXfer.slaveAddress   = dev_addr; // Adresse du device BMP180
	masterXfer.direction      =  kI2C_Write;
	masterXfer.subaddress     = reg_addr; // adresse du registre à écrire;
	masterXfer.subaddressSize = 1;
	masterXfer.data           = array;
	masterXfer.dataSize       = cnt;
	masterXfer.flags          = kI2C_TransferDefaultFlag;

	// transférer les données de reg_data vers array

	// Appeler la fonction  I2C_MasterTransferBlocking(...) de la librairie fsl_i2c
	I2C_MasterTransferBlocking(I2C_MASTER_BASEADDR, &masterXfer);
    iError = I2C_MasterTransferBlocking(I2C_MASTER_BASEADDR, &masterXfer);

    for (stringpos=0; stringpos<cnt; stringpos++)
    		{
    	array[stringpos]= *(reg_data + stringpos);
    		}

	return (s8)iError;
}

/*	\Brief: This function is used for I2C bus read
 *	\Return : Status of the I2C read
 *	\param dev_addr : The device address of the sensor
 *	\param reg_addr : Address of the first register, will data is going to be read
 *	\param reg_data : contains the data read from the sensor
 *	\param cnt : The no of byte of data to be read
 */

s8 BMP180_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
	s32 iError = 0;
	u8 array[I2C_BUFFER_LEN] = {0};
	u8 stringpos = 0;
	array[0] = reg_addr;
	i2c_master_transfer_t masterXfer;

	memset(&masterXfer, 0, sizeof(masterXfer));
	masterXfer.slaveAddress   = dev_addr;
	masterXfer.direction      = 0x1U; // trouvez la constante définie dans fsl_i2c.h qui correspond
	masterXfer.subaddress     = reg_addr;
	masterXfer.subaddressSize = 1;
	masterXfer.data           = 0; //adresse du tableau array;
	masterXfer.dataSize       = cnt;
	masterXfer.flags          = kI2C_TransferDefaultFlag;

	I2C_MasterTransferBlocking(I2C_MASTER_BASEADDR, &masterXfer);
	iError = I2C_MasterTransferBlocking(I2C_MASTER_BASEADDR, &masterXfer);
	// transférez les données de array vers regdata

	for (stringpos=0; stringpos<cnt; stringpos++)
		{
		*(reg_data + stringpos)=array[stringpos];
		}
	return (s8)iError;
}
0 Kudos
Reply
0 Replies