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 CCS Technical Support

[HELP! ]Problem when interface both Ext EEPROM and DS1307

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



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

[HELP! ]Problem when interface both Ext EEPROM and DS1307
PostPosted: Wed Jun 26, 2013 8:36 pm     Reply with quote

Dear all.
I have a problem in my project when trying to interface between PIC18F4680 with both DS1307 and external EEPROM AT24C04A, CCS C version 4.140
Sometime, the data readout from DS1307 is incorrect.
In my header file, I found that defined hardware file for I2C of DS1307 and Ext EEPROM is same Master:

1. Ext EEPROM AT24C04A
Code:

#ifndef EEPROM_SDA
#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3
#endif
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)


2. DS1307

Code:

#define DS1307_SDA  PIN_C4
#define DS1307_SCL  PIN_C3
#use i2c(master, sda=DS1307_SDA, scl=DS1307_SCL)


when i try to change from "MASTER" to "MULTI_MASTER" for this code, it not run.
In my order, pls show me way if i want to configure them to avoid conflicts.
Thanks all.
_________________
Begin Begin Begin !!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 26, 2013 9:12 pm     Reply with quote

i2c is a multi-drop bus. You can connect many i2c slaves to the same bus.
Each i2c slave has a different address. It's 0xD0 for ds1307 and 0xA0
for the eeprom. There is no conflict.

But, you should have only one #use i2c statement.

Make sure your i2c bus pullup resistors are in the range from 1.6K to 4.7K.
For example, you could use 2.2K pullup resistors.
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Wed Jun 26, 2013 9:48 pm     Reply with quote

PCM programmer wrote:
i2c is a multi-drop bus. You can connect many i2c slaves to the same bus.
Each i2c slave has a different address. It's 0xD0 for ds1307 and 0xA0
for the eeprom. There is no conflict.

But, you should have only one #use i2c statement.

Make sure your i2c bus pullup resistors are in the range from 1.6K to 4.7K.
For example, you could use 2.2K pullup resistors.


Thanks PCM programmer.
I changed both to slave but it no change, after i delete one configure #use i2c in ds1307 header file, but it no changed too.
I used 2 R4.7K pullup on bus I2C.
_________________
Begin Begin Begin !!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 26, 2013 10:00 pm     Reply with quote

Quote:
I changed both to slave

What does this mean ? Did you remove 'Master' from the #use i2c()
and change it to 'Slave' ? I hope not.
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Wed Jun 26, 2013 10:52 pm     Reply with quote

PCM programmer wrote:
Quote:
I changed both to slave

What does this mean ? Did you remove 'Master' from the #use i2c()
and change it to 'Slave' ? I hope not.

sorry, i careless when write this, i tried change #use i2c of ds1307 or 24c04, not change both.
_________________
Begin Begin Begin !!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Thu Jun 27, 2013 1:11 am     Reply with quote

Lets take a couple of steps 'back'.

First, an I2C master can always control multiple devices. 'MULTI_MASTER', is for where you put two (or more) masters on one bus.
You just need your I2C setup as a normal MASTER.

Now, you should really simply 'REM' out the I2C setup lines on the second driver. So the bus is setup _once_ in the first driver loaded, and nowhere else.

On the pullups, it all depends on the length of the bus, and the number of devices attached. 4K7, is a fairly 'safe' value for a short bus controlling one device. With two devices, and any length in the bus, a bit lower is generally 'safer'. Go 2K2.

Start by getting your I2C 'setup' line sorted out, and test the bus using the I2C scanner program posted by PCM programmer in the code section. If your hardware is working, it should find both devices. If it doesn't, you have a hardware problem, and this needs to be sorted before worrying about the code.

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