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_read() on PIC 12F629

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



Joined: 29 Aug 2007
Posts: 14

View user's profile Send private message

i2c_read() on PIC 12F629
PostPosted: Wed Jan 21, 2009 9:40 am     Reply with quote

Hello,

I am looking at using a PIC12F629 as a slave to do some very simple operations using the I2C bus for a display. However, the help in PCW 4.082 indicates that i2c_read() only works on chips with dedicated hardware. Is true? I've seen code snippits of I2C done with software mode on any many different processors and pins. I just want to verify that the i2c_read function will work.

Thanks!
Ttelmah
Guest







PostPosted: Wed Jan 21, 2009 4:14 pm     Reply with quote

They won't.
It is possible to write an I2C slave, without the hardware, but the CCS functions don't support this, and it really is processor intensive. You would not be able to do anything else on a 629, since the slave _must_ react in very tight timing windows, and even simple display functions would without hardware buffering be very hard to guarantee to finish in time.
I'm afraid that you would be much better off selecting a basic chip with I2C hardware.
I'd put the labour cost to do this reasonably well, to probably be in excess of the cost of 1000 'better' processors...

Best Wishes
elellilrah



Joined: 29 Aug 2007
Posts: 14

View user's profile Send private message

PostPosted: Wed Jan 21, 2009 11:54 pm     Reply with quote

Ttelmah wrote:
They won't.
It is possible to write an I2C slave, without the hardware, but the CCS functions don't support this, and it really is processor intensive. You would not be able to do anything else on a 629, since the slave _must_ react in very tight timing windows, and even simple display functions would without hardware buffering be very hard to guarantee to finish in time.
I'm afraid that you would be much better off selecting a basic chip with I2C hardware.
I'd put the labour cost to do this reasonably well, to probably be in excess of the cost of 1000 'better' processors...

Best Wishes


Thanks. It's strange, because I just found some code running on a 16F688 that has the following:

#use i2c(MASTER, sda=SDA_PIN, scl=SCL_PIN, FORCE_SW)
...
msb_byte = i2c_read(0);

that reads from EEPROMS using i2c_read(). The program seems to work perfectly, the i2c_read() works fine. So perhaps I have a chance of getting this to work?
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PostPosted: Thu Jan 22, 2009 12:40 am     Reply with quote

In your first post you said:
Quote:

I am looking at using a PIC12F629 as a slave
And now you say:
Quote:

...that reads from EEPROMS using i2c_read()


Ttelmah said it won't be viable to implement a I2C slave on the pic, as you querried in the first post. Your second post you are questioning the implementation of a I2C master. Which is it....?
Ttelmah
Guest







PostPosted: Thu Jan 22, 2009 3:33 am     Reply with quote

Spot on.
The key to understand, is that the _master_, controls the timings on the I2C bus. If it runs slow, or has to do something else, it doesn't matter. The bus just runs slow. However the slave, _must_ respond inside the timings being generated by the master (there is an ability to 'delay' the end of the response (clock stretching), but this already requires the slave to be responding, and have held the clock line low.
You can implement an I2C master on the 12F629, as easily as anything. A _slave_, is the hard bit.
Talking to an EEPROM as a master, with the 629, is 'easy'. There are probably several hundred examples here on chips similar to this, that will work fine. Receiving I2C as a slave, and writing it to a display, is a whole different 'can of worms'...
If (for instance), the bus is running at 100KHz, the slave device, has just 10uSec, in which it must either have read the data bit, or have held the clock line low.

Best Wishes
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PostPosted: Thu Jan 22, 2009 4:07 am     Reply with quote

If you have to use the 629, you could buffer the incomming data and only after the complete receiption of a message, do the display function. The 629 can then have a ready flag which the master will have to poll before starting a transmission.
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PostPosted: Thu Jan 22, 2009 4:09 am     Reply with quote

I see Ttelmah has already mentioned buffering... Shocked
elellilrah



Joined: 29 Aug 2007
Posts: 14

View user's profile Send private message

PostPosted: Thu Jan 22, 2009 4:39 pm     Reply with quote

crystal_lattice wrote:
If you have to use the 629, you could buffer the incomming data and only after the complete receiption of a message, do the display function. The 629 can then have a ready flag which the master will have to poll before starting a transmission.


Sorry for the confusion between master and slave. I need to have my larger CPU (16F887) run as master and the 629 as a slave. Having the buffer receive the data, then displaying it makes sense. Having another line like chip select or ready flag is an even better idea. It would be helpful to keep the data transactions under control.

From what it sounds like I should move up to a 16F688 or the like for my smaller 629 CPU to do this job. That way I can have 3 pins for transaction control to set a ready flag, then SDA and SCL. If I issue a i2c_read() on the slave, then will the smaller CPU sit indefinitely until the master sends the byte across? Or is the CCS I2C slave programmed to time out as a slave read?
zcashion
Guest







PostPosted: Tue Oct 06, 2009 7:19 pm     Reply with quote

If you plan on using a third line for a chip select, then you should probably switch to SPI communication. Using a chip select pin circumvents the need for sending the address byte that is necessary with I2C.

As for your question on I2C_read. This command is dependent upon whether you are operating in Master or Slave mode. In Master mode it generates a clock. In Slave mode it waits indefinitely for a clock from the master. This is why there is an option to restart the watchdog timer in the #use i2c command.

Cheers
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Oct 07, 2009 10:05 am     Reply with quote

Simply put, if you want to use a PIC as a slave then select one that has the hardware to support it. Otherwise, you're in for a very bad headache and loss of hair.

Ronald
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