TWI: General call 0000000 for read

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

I have two ATmega8 MCUs.

The first one, the TWI master, is on an inverter board.

The second one, the TWI slave, is on a meter board (measuring the battery voltage and current).   

Between the two, there are two transfer modes :

 

[1] Master Transmitter - Slave Receiver (MT-SR)

[2] Master Receiver - Slave Transmitter (MR-ST)

 

The protocol that implements (MR-ST) usually starts with (MT-SR) first by sending SLA+W then a byte (address/index).

A ‘Repeated Start’ follows to start the (MR-ST) transfer that begins by sending SLA+R.

 

In my simple configuration (1 master and 1 slave), if I like to begin with SLA+R directly using the general call 0000000 (GC), is there a status code (for TWSR) that confirms the reception of 00000001 (SLA+R of GC)?

 

As you know, on the datasheet of ATmega8, there is no such status code. But by using the general call in this case (for reading from 1 connected slave only), the prior sending of SLA+W and the address byte may not be needed (and this leads to a faster transfer).

 

Thank you.

 

Kerim

 

Edit1:

By receiving a general call for reading, the slave could be made to know in advance what the master expects to receive from it.

In the other cases of reading that use the specific slave address, the slave needs to receive an address/index/command byte first before it sends the required data bytes.

 

Edit2:

Since this is the first time I use TWI between MCUs (starting with two) and I am in the designing stage, I will likely monitor the status code of the case I presented here, and see if it exists (being different from all other ones) or not. And in case there will be no sure answer here, I will certainly post about what I will get (when the prototypes of the two boards will be ready).

This topic has a solution.

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

TWI general calls are designed for transmitting the same data to multiple slaves:

 

"When a general call is issued, all slaves should respond by pulling the SDA line low in the ACK cycle. A
general call is used when a Master wishes to transmit the same message to several slaves in the system.
When the general call address followed by a Write bit is transmitted on the bus, all slaves set up to
acknowledge the general call will pull the SDA line low in the ack cycle. The following data packets will
then be received by all the slaves that acknowledged the general call. Note that transmitting the general
call address followed by a Read bit is meaningless, as this would cause contention if several slaves
started transmitting different data."

 

ATMega8 Manual, page 215.

 

I do realize that you only have one slave, so in your situation this could still work.  What's the motivation behind using a general call instead of specifically addressing the slave?

 

 

 

KerimF wrote:

In my simple configuration (1 master and 1 slave), if I like to begin with SLA+R directly using the general call 0000000 (GC), is there a status code (for TWSR) that confirms the reception of 00000001 (SLA+R of GC)?

 

As you know, on the datasheet of ATmega8, there is no such status code. But by using the general call in this case (for reading from 1 connected slave only), the prior sending of SLA+W and the address byte may not be needed (and this leads to a faster transfer).

 

Actually, there IS a status code to confirm receipt.  The slave will ACK the general call by pulling SDA low in the ninth clock cycle.  See Table 25-4 Status codes for Master Receiver Mode on page 226 of the ATMega8 manual, code 0x40 for ACK and 0x48 for NACK

 

KerimF wrote:

Edit1:

By receiving a general call for reading, the slave could be made to know in advance what the master expects to receive from it.

In the other cases of reading that use the specific slave address, the slave needs to receive an address/index/command byte first before it sends the required data bytes.

 

This is identical to doing this:

KerimF wrote:

The protocol that implements (MR-ST) usually starts with (MT-SR) first by sending SLA+W then a byte (address/index).

A ‘Repeated Start’ follows to start the (MR-ST) transfer that begins by sending SLA+R.

 

Of course, if the slave is always returning the exact same information / status code, there is no reason to have to set an address/index instructing it what to return.  Just hard code it into the slave.

 

 

My typical approach is to code identical structs in master and slave, and simply copy it from slave to master over twi.  Once received, you have a local copy of the slaves variable and can inspect it and respond according, display it, etc.

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

Thank you for replying.

 

Actually, there IS a status code to confirm receipt.  The slave will ACK the general call by pulling SDA low in the ninth clock cycle.  See Table 25-4 Status codes for Master Receiver Mode on page 226 of the ATMega8 manual, code 0x40 for ACK and 0x48 for NACK

 

But, as you mentioned, 0x40 & 0x48 are status codes that could be checked on the side of the MCU master.

 

What about the one(s), on the slave side, after receiving the general call for read (0b00000001)?

There is no such a code on the table 'Status Codes for Slave Transmitter Mode', likely due to "transmitting the general call address followed by a Read bit is meaningless".

So far, I think the sure answer could be found by a test only.

 

Kerim

 

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

The I2C specification indicates that the General Call address is only valid for R/W = 0:

 

https://www.nxp.com/docs/en/user...

 

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

KerimF wrote:

What about the one(s), on the slave side, after receiving the general call for read (0b00000001)?

 

On the slave side, I suspect it would be:

 

0xA8 - Own SLA+R has been received; ACK has been returned

 

Because...

 

"The Address Match unit checks if received address bytes match the seven-bit address in the TWI
Address Register (TWAR). If the TWI General Call Recognition Enable (TWGCE) bit in the TWAR is
written to one, all incoming address bits will also be compared against the General Call address."

 

 

 

Also, I'm still curious - what's the motivation behind using a general call instead of specifically addressing the slave?

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

awneil wrote:

The I2C specification indicates that the General Call address is only valid for R/W = 0:

 

https://www.nxp.com/docs/en/user...

 

 

Thank you for the reference.

 

It says clearly:

[2] No device is allowed to acknowledge at the reception of the START byte.

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

SolarFreak:

Also, I'm still curious - what's the motivation behind using a general call instead of specifically addressing the slave?

 

In the case of 1 slave, it could be used as a fast 'specific' notification by transferring just one byte.

But as it became clear now, the slave 'shouldn't' acknowledge the reception of 0b00000001 (general call for read).

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

KerimF wrote:

In the case of 1 slave, it could be used as a fast 'specific' notification by transferring just one byte.

But as it became clear now, the slave 'shouldn't' acknowledge the reception of 0b00000001 (general call for read).

 

Now I see the reason for having to test it.  In the case of the ATMega8, it might just respond anyway, even though it shouldn't.  I was actually going to hack together a couple of chips and try this today, just to see what happened, but didn't have the time.

 

Also, thanks for the unintentional reference to the I2C specification and user manual!  Now I have even more reading material that I won't get to!  But it's good to have just in case...