CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

I2C transaction with re-start

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

I2C transaction with re-start
PostPosted: Fri Apr 04, 2008 12:52 am     Reply with quote

Colleagues,

I’ve searched the forum on this subject, but I didn’t find anything. Also, I’m relatively new to using PICs as I2C slaves.

Here’s what I want to do. The slave PIC has handful of 1-byte data fields that master PIC can read over I2C. Master sends over I2C a 1-byte command that identifies the data field, then it reads the data field over I2C. Some I2C A/Ds follow this scenario, where master picks a channel, then reads the results of the A/D conversion. Similar thing with EEPROMs, where master first selects the address, then reads the contents at that address.

Code:
- Start condition
- 7-bit slave address, Write
- Command (or A/D channel, or EEPROM address)
- Start condition.  This is the re-start.  Stop condition wasn’t generated after the 1st start.
- 7-bit slave address, Read
- Read the 1st data byte
- … Read further data bytes, if the field has more than one data byte
- Stop condition


Why restart, instead of making two separate transactions?
What will the PIC's SSP do, when it sees a restart?
_________________
Read the label, before opening a can of worms.


Last edited by kender on Fri Apr 04, 2008 1:23 am; edited 1 time in total
Matro
Guest







PostPosted: Fri Apr 04, 2008 1:21 am     Reply with quote

A restart is almost the same thing as a stop and start again. The PIC will operate the same, i.e. close the pending transaction and open a new one.
The interest of the restart is that in multi-master mode the bus isn't released and so another master can't take control of the bus.
If you replace it by a stop then a start, another master should be able to take control of the bus between the stop and the start. So you have to wait to read. But the worst is that the other master should for exemple change the register value or the register pointer value of the same slave. And so the read you will do after waiting will have no signification.
That's why restart exists.

Matro.
Ttelmah
Guest







PostPosted: Fri Apr 04, 2008 3:01 am     Reply with quote

A 'restart', is part of the I2C specifications. It is called a 'repeated start'.
In most devices, it doesn't differ from a stop/start transaction. As Matro says, In a multi-master setup, arbitration is not allowed between a repeated start, and a stop. In the normal examples, the usage, is simply to send an address, then reverse direction, but in fact this is a 'sub example', of this general use, where you can send a start, address, several bytes of data, then change direction, with a repeated start, and carry on receiving data (combined format). However on some systems, a 'stop', resets the internal counters, so on these a repeated start is a required transaction, if addressing from a specific location is required.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group