This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI Will Not Return Slave Data

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.

image description

  1. START
  2. Slave Address (0x1D shifted left 1 bit)
  3. WRITE bit
  4. ACK (why doesn't it get closer to 0v?)
  5. no STOP
  6. WHO AM I register (0x0D)
  7. ACK (why doesn't it get closer to 0v?)
  8. STOP (why is there a STOP?)

Here is the screenshot of the read command.

image description

  1. START
  2. Slave Address (0x1D shifted left 1 bit)
  3. ACK (why doesn't it get closer to 0v?)
  4. 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?

Parents Reply Children
No Data
Related