I'm communicating with an ADXL345 Accelerometer using Atmel START / ASF4 calls. Read operations work (single and multi-byte), but write operations always return 0. Here's what I know:
- Read operations (including multi-byte read operations) are working reliably
- The SCL line shows a stable 100KHz rate
- I've added 1K pullups on the SDA and SCL lines. (At 10K, the rising edges were somewhat soft.)
- Processor is a SAML22 Xplained Pro board
My code is (in summary):
uint32_t err; uint8_t reg; err = i2c_m_sync_enable(&ADXL345_0); ASSERT(err >= 0); err = i2c_m_sync_set_slaveaddr(&ADXL345_0, ADXL345_I2C_PRIMARY_ADDRESS, I2C_M_SEVEN); ASSERT(err >= 0); err = i2c_m_sync_cmd_read(&ADXL345_0, ADXL345_REG_DEVID, ®, 1); ASSERT(err >= 0); printf("device ID = %d\n", reg); // works reg = ADXL345_MEASURE; // = 0x08 err = i2c_m_sync_cmd_write(&ADXL345_0, ADXL345_REG_POWER_CTL, reg, 1); ASSERT(err >= 0); // no error is raised err = i2c_m_sync_cmd_read(&ADXL345_0, ADXL345_REG_POWER_CTL, ®, 1); ASSERT(err >= 0); // no error is raised printf("device ID = %d\n", reg); // always returns 0, should be 0x08
'Scope traces below. I'm not sure why i2c_m_sync_cmd_write() is being broken into two operations (that's a second start in the middle, right?). Of course, this could be due to my misreading of the ADXL345 data sheet, but more likely I'm not using i2c_m_sync_cmd_write() properly. Suggestions?