I ran into an issue with my project. I use Renesas RL78 microcontroller and on one I2C bus I have two sensors: digital compass and accelerometer. Accelerometer type is MMA8453 by Freescale.
Datasheet: http://cache.freescale.com/files/sensors/doc/data_sheet/MMA8453Q.pdf
I have no problem with reading data from compass. Accelerometer, however, is a different story. I can't read anything from it - at least I guess I'm not getting anything. Unfortunately I don't have scope or logic analyzer to check out. I get an ACK, but no data.
Here is the function I use for reading register of I2C device:
uint8_t Read_I2C_Sensor_Reg(uint8_t DevAddr, uint8_t RegAddr, uint8_t *Data, uint8_t Numbytes, uint8_t wait)
{
uint16_t status = 0;
uint16_t timeout = 1000; //approx 32uSec
DevAddr <<= 1; //Shifting left by one bit to make room for Read/Write bit
IICA0_Err = 0;
IICA0_Tx_Done |= 1;
status = IICA0_Master_Send(DevAddr, &RegAddr, 1, wait);
while(IICA0_Tx_Done)
{
while(timeout--);
iica0_master_check_status(); //<SCH> checking the transation status, in case if this fails, report andre initiate transaction.
if(IICA0_Err)
{
status = IICA0_Err ; break;
}
}
if (IICA0_Tx_Done == 0)
{
IICA0_StopCondition();
while (SPD0 == 0);
IICA0_Rx_Done |= 1;
status = IICA0_Master_Receive(DevAddr, Data, Numbytes, wait);
while(IICA0_Rx_Done)
{
while(timeout--);
iica0_master_check_status();
if(IICA0_Err)
{
status = IICA0_Err ; break;
}
}
if (IICA0_Tx_Done == 0)
{
IICA0_StopCondition();
while (SPD0 == 0);
}
}
if (status == MD_OK)
return 0;
else
return 1;
}
Did anyone come across this kind of issue? I can post more details later, if needed.