TWI Master: Reading multiple Bytes with Repeated Start Condition

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to read multiple Bytes with a Repeated Start Condition after sending the register address from a accelerometer/magnetometer (FXOS8700).

 

My Code looks like this:

 

twi_packet_t packet_rx;
uint8_t data_rx[13];
memset(data_rx, 0x00, 13);

packet_rx.chip        = FXOS8700_ADDRESS;
packet_rx.addr[0]     = FXOS8700_REGISTER_STATUS | 0x80;
packet_rx.addr_length = 1;
packet_rx.buffer      = data_rx;
packet_rx.length      = 13;

 

twi_master_read(sensor->p_twi, &packet_rx);

 

How may I send the needed Repeated Start Condition while reading multiple bytes?

 

Comments:

When analyzing the differences between the sample provided by Adafruit (https://github.com/adafruit/Adaf...) with an Arduino and my program ist shows that in my case there is no SR condition adter sendingt the address, whereas the Arduino code does this by calling a Wire.endTransmission();

The datasheet tells me the following:

    

 

I'm using a SAMG55 with ASF 3.35.1.

 

BTW: reading/writing single bytes from/to the device works as expected. And 

This topic has a solution.

Last Edited: Fri. Dec 15, 2017 - 11:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The TWI eeprom ASF example tells me you should be calling twi_master_read.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lars, sorry, this wa a typo... I am actually calling twi_master_read... But no SR...

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

A repeated start is only necessary if there are 2 masters on the bus and the master doesn't want to release the bus.

 

Arduino wire library  :   endTransmission(); Doesn't send a repeated start.   With a void or true argument it sends a stop.  So in this case AdaFruit library sends a stop.  Thus it will send a start to start the read.

 

You probable need a logic analyzer to know what is going on the bus.

 

I thibk you need to write, 1 byte write, the register address, then read the 13 bytes.   The master_read function sends a start, so if you don't send a stop after the 1 byte write, it will be a repeated start.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JSTAMPFL,

 

Thanks, that made it!

 

Kind Regards!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just got a logic analyzer:  Reading multiple bytes with a single master_read does not require a previous write.  The master_read issues the write, then reads.  Also issues a repeated start, that is a start with out a previous stop.

 

Here is the logic analyzer display:

logic analzer output

Here is the code and output:

 

twi code and output

 

Note:  E70 Xpd, AS 7.0.1645, ASF 3.36

Last Edited: Mon. Dec 25, 2017 - 01:27 AM