Hello,
I ue a Q2686H with firmware 6.63 and OpenAT4.21 and I would read information from Accelerometer MMA7455L(freescale.com) with slave address 0x1D, and i definition of opening I2C is OK , handle=0, but on Read or Write data the return function is :ADL_RET_ERR_PARAM, but this code is the same for LIS3LV02DQ (ST.com) accelerometer and the comunication is perfect.
The Code is :
s32 MMAGpioHandle;
/*çççççççççççççççççççççççççç ACCELEROMETER ççççççççççççççççççççççççççççççççççççççççççççççççç*/
adl_busI2CSettings_t MyI2CConfig =
{
0x1D,//Chip addrres MMA
ADL_BUS_I2C_CLK_STD
};//I2C Standard clock speed 100kbps
u8 asse_x,asse_y,asse_z;
typedef struct
{
u32 Address; // Read/Write Start Address
// 12 less significant bits used for M24C32
// 13 less significant bits used for M24C64
u32 Length; // Data buffer length
u8 Data [1]; // Data buffer
} drv_Write_t;
typedef struct
{
u32 Address; // Read/Write Start Address
// 12 less significant bits used for M24C32
// 13 less significant bits used for M24C64
u32 Length; // Data buffer length
u8 Data [1]; // Data buffer
} drv_Read_t;
drv_Write_t g_pWrite;
drv_Read_t g_pRead;
s32 MyI2CHandle;
static adl_busAccess_t * drv_MMA7455L_ComputeBusAccess ( u32 Address );
// Driver Read function
static void drv_MMA_Read ( drv_Read_t * pRead );
// Driver Write function
static void drv_MMA_Write ( drv_Write_t * pWrite );
/* ççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççççç */
static adl_busAccess_t * drv_MMA7455L_ComputeBusAccess ( u32 Address )
{
// Compute Bus Access structure from provided opcode & address
static adl_busAccess_t I2CBus_Access = { 0, 0, 0, 0, ADL_BUS_SIZE_BYTE };
u8 AddressMax = 32;
// Check if address is required
if ( Address != 0xFFFF )
{
// Set address length
I2CBus_Access.AddressLength = 8;
// Set address
I2CBus_Access.Address = Address << ( AddressMax - I2CBus_Access.AddressLength );
}
else
{
// Reset address
I2CBus_Access.AddressLength = I2CBus_Access.Address = 0;
}
TRACE (( 1, "MMA Driver] compute access (address : %x (length %d))", I2CBus_Access.Address, I2CBus_Access.AddressLength ));
// Return structure
return &I2CBus_Access;
}
// Driver Read function
static void drv_MMA_Read ( drv_Read_t * pRead )
{
s32 result;
adl_busAccess_t * I2CBus_Access = drv_MMA7455L_ComputeBusAccess ( pRead->Address );
/* I2C bus read */
result=adl_busRead ( MyI2CHandle,
I2CBus_Access,
pRead->Length,
pRead->Data );
switch(result)
{
case OK :
TRACE((1,"Read OK"));
break;
case ADL_RET_ERR_UNKNOWN_HDL:
TRACE((1,"read ADL_RET_ERR_UNK_HDL"));
break;
[b] case ADL_RET_ERR_PARAM:
TRACE((1,"read ADL_RET_ERR_PARAM"));
break;[/b] case ADL_RET_ERR_BAD_STATE:
TRACE((1,"read ADL_RET_ERR_BAD_STATE"));
break;
}
DUMP ( 1, pRead->Data, pRead->Length );
}
// Driver Write function
static void drv_MMA_Write ( drv_Write_t * pWrite )
{
s32 result;
adl_busAccess_t * I2CBus_Access = drv_MMA7455L_ComputeBusAccess ( pWrite->Address );
/* I2C bus write */
result = adl_busWrite ( MyI2CHandle,
I2CBus_Access,
pWrite->Length,
pWrite->Data );
switch(result)
{
case OK :
TRACE((1,"Write OK"));
break;
case ADL_RET_ERR_UNKNOWN_HDL:
TRACE((1,"Write ADL_RET_ERR_UNK_HDL"));
break;
[b] case ADL_RET_ERR_PARAM:
TRACE((1,"Write ADL_RET_ERR_PARAM"));
break;[/b] case ADL_RET_ERR_BAD_STATE:
TRACE((1,"Write ADL_RET_ERR_BAD_STATE"));
break;
}
}
void read_axis()
{
g_pRead.Address=0x06;//OutX_8bit
g_pRead.Length=1;
g_pRead.Data[0]=0;
drv_MMA_Read ( &g_pRead );
asse_x=g_pRead.Data[0];
g_pRead.Address=0x07;//OutY_8bit
g_pRead.Length=1;
g_pRead.Data[0]=0;
drv_MMA_Read ( &g_pRead );
asse_y=g_pRead.Data[0];
g_pRead.Address=0x2C;//OutZ_8bit
g_pRead.Length=1;
g_pRead.Data[0]=0;
drv_MMA_Read ( &g_pRead );
asse_z=g_pRead.Data[0];
}
void Init_MMA7455L()
{
s32 i,result;
MyI2CHandle = adl_busSubscribe(ADL_BUS_I2C, ( adl_busSettings_u * ) &MyI2CConfig);
g_pWrite.Address=0x16;//Mode Control Register
g_pWrite.Length=1;
g_pWrite.Data[0]=0x49;//Config Measurament Mode pin DRDY = 1 new value
drv_MMA_Write(&g_pWrite);
}
void adl_main()
{
Init_MMA7455L();
read_axis();
}
What is a problem ?
Thanks