I2C and MMA8451 | Cypress Semiconductor
I2C and MMA8451
I am attempting to use a FreeScale MMA8451 so I read with great interest the post "reading adxl345 data on i2c" and found very similar issues. To read a register on the 8451 just like the adxl345 you have to write the register # to I2C, do a restart then read. My code to do this was just as you suggested for the adx part.
status = SCB_I2CMasterSendStart(MMA8451Address,SCB_I2C_WRITE_XFER_MODE);
status |= SCB_I2CMasterWriteByte(reg & 0xff);
status |= SCB_I2CMasterSendRestart(MMA8451Address,SCB_I2C_READ_XFER_MODE);
rtnval = SCB_I2CMasterReadByte(SCB_I2C_ACK_DATA);
status |= SCB_I2CMasterSendStop();
if( status != SCB_I2C_MSTR_NO_ERROR )
rtnval = -1 * status;
This works, but monitoring the I2C bus I see an extra read value 0f 0x00 see the enclosed file (TEK00117.png). If I remove the SCB_I2CMasterReadByte() in the above the extra byte is not there. Where is this extra byte coming from ?
Also the application has BLE, FreeRTOS and will be sleeping. In the main thread I do this:
while( 1 )
// Setup Accelerometer
rtnval = initMMA8451(MMA8451_DEFAULT_ADDRESS); // This is where the register is read
vTaskDelay(5000 *portTICK_RATE_MS );
i = i + 1;
The i = i+1 is to give a breakpoint line. After two time through the loop it gets stuck in the CY_ISR(CyBLE_Bless_Interrupt) handler and won't proceed. Removing the DEEPSLEEP line makes no difference. Any suggestions on how to handle this ?
Thank you for the help