We are using a MMA8452Q accelerometer connected to an nRF51822 via TWI using the twi_hw_master. Reading the WHO AM I register is the first attempt to get the TWI running but no data is returned.
#define ACCELEROMETER_ADDRESS 0x1C // if SA0 = 0
#define WHO_AM_I_REG 0x0D
data_array[0] = WHO_AM_I_REG;
twi_master_transfer((ACCEL_ADDRESS << 1) | !TWI_READ_BIT, data_array, 1, TWI_DONT_ISSUE_STOP);
twi_master_transfer((ACCEL_ADDRESS << 1) | TWI_READ_BIT, data_array, 1, TWI_ISSUE_STOP);
Here is the screenshot of the write command.
- START
- Slave Address (0x1D shifted left 1 bit)
- WRITE bit
- ACK (why doesn't it get closer to 0v?)
- no STOP
- WHO AM I register (0x0D)
- ACK (why doesn't it get closer to 0v?)
- STOP (why is there a STOP?)
Here is the screenshot of the read command.
- START
- Slave Address (0x1D shifted left 1 bit)
- ACK (why doesn't it get closer to 0v?)
- But then no data is returned
There is no data because NRF_TWI1->EVENTS_ERROR always equals 1 so twi_master_read() is exited before the data is transmitted. It is 0 until the command NRF_TWI1->TASKS_STARTRX = 1 is executed which sends out the first 9 clocks and Slave Address but also sets NRF_TWI1->EVENTS_ERROR = 1. During the write command the instruction TASKS_STARTTX = 1 does not set EVENTS_ERROR = 1 so the write command is not aborted.
Where do I go from here?