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

Can't make I2C works [Solved]

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



Joined: 11 Mar 2008
Posts: 20
Location: Toulouse, France

View user's profile Send private message

Can't make I2C works [Solved]
PostPosted: Wed Mar 26, 2008 4:03 am     Reply with quote

Hello,
I'm trying to make work a software I2C, to communicate betwen a 18F4620 and a DS1621 (digital thermometer).

I use the ccs DS1621.C driver. I can't see any electrical clock on the pins ...
This is my code :

The project.h
Code:
#include <18F4620.h>
#fuses XT, NOWDT, NOPROTECT
#use delay(clock = 4000000)
#use rs232(baud=38400, xmit=PIN_C6,rcv=PIN_C7)

#define DAL_SCL PIN_B4
#define DAL_SDA PIN_B5



The main.c:
Code:
#include <project.h>
#include <DS1621.C>
void main(void)                                             
   {
signed long d;

set_tris_b(0);
output_b(0);

printf("Temperature\n\r");
init_temp();

while (1) {

d = read_full_temp();
printf("%ld\n\r",d);
delay_ms(1000);
}

}
 



I've looked at the ex_temp.c but it didn't helped me.

I'm with ccs v4 and MPLAB+ICD2

Can you help me ?
Thanks...

ps : I'm running it in my company, so I don't have the windows administrator rights on the PC, is it possible to have problems with that???

ps °2: I have the same problem with the Microchip PICdem2Plus board.


Last edited by gremi on Wed Mar 26, 2008 9:57 am; edited 1 time in total
Matro
Guest







PostPosted: Wed Mar 26, 2008 4:23 am     Reply with quote

You don't have any "#use i2c" line...
Have a look at CCS help in "i2c" item...

Matro.
gremi



Joined: 11 Mar 2008
Posts: 20
Location: Toulouse, France

View user's profile Send private message

PostPosted: Wed Mar 26, 2008 4:39 am     Reply with quote

The #use I2C is in the DS1621.C.
I didn't put it in the post because it's a CCS driver ...
Matro
Guest







PostPosted: Wed Mar 26, 2008 4:57 am     Reply with quote

If you don't use "fast_io" remove these 2 lines
Code:

set_tris_b(0);
output_b(0);


The driver is done for a i2c address at 0x90 but this address can be configured through the DS1621 pins.
Have you the correct one?

Matro.
gremi



Joined: 11 Mar 2008
Posts: 20
Location: Toulouse, France

View user's profile Send private message

PostPosted: Wed Mar 26, 2008 6:16 am     Reply with quote

If I've understood the datasheet, the PIC sends a 0x90 witch is 1001 0000, so the adress is 000, that's why i've set the port b at 0 (A0 (dallas) =PIN B0 (on the pic), A1=>PIN B1, A2=>PIN B2.

Is it good ?


edit : However, I don't see any signal with the scoop ... i don't think that it's an adress problem ...
Matro
Guest







PostPosted: Wed Mar 26, 2008 6:25 am     Reply with quote

Remove the "set_tris" line and replace "output_b(0);" by
Code:

output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);


Matro.
gremi



Joined: 11 Mar 2008
Posts: 20
Location: Toulouse, France

View user's profile Send private message

PostPosted: Wed Mar 26, 2008 6:33 am     Reply with quote

I've done it, but it's still the same ...

Nothing seems to go out of the pic ... I can't see any clock signal (neither data signal) ...


Code:
#include <project.h>
#include <DS1621.C>


#use i2c(master,sda=DAL_SDA, scl=DAL_SCL,stream=dallas)


void main(void)                                             
   {
signed long d;


output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);



printf("Temperature\n\r");
init_temp();

while (1) {

d = read_full_temp();
printf("%ld\n\r",d);
delay_ms(1000);
}

}
Matro
Guest







PostPosted: Wed Mar 26, 2008 6:44 am     Reply with quote

A doubt just comes in my mind.
Did you think about adding the pull-up resistors on SCL and SDA lines?...
(...Of course, it can't be another way...)

Matro.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Mar 26, 2008 7:42 am     Reply with quote

You say there is not signal on the clock line. Is the click line high or low? Do you have 100 ohm series resistors between the PIC & pull-up resistor and the temp sensor? Some designs use series resistors as an ESD protection. If you have them measure the voltage on either end to see if the PIC or the temp sensor is pulling the line. Using a low value pull-up like 1000 Ohm makes measuring current easier.
_________________
The search for better is endless. Instead simply find very good and get the job done.
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Wed Mar 26, 2008 8:04 am     Reply with quote

Add NOLVP to #FUSES.
_________________
David
gremi



Joined: 11 Mar 2008
Posts: 20
Location: Toulouse, France

View user's profile Send private message

PostPosted: Wed Mar 26, 2008 9:42 am     Reply with quote

Matro wrote:
A doubt just comes in my mind.
Did you think about adding the pull-up resistors on SCL and SDA lines?...
(...Of course, it can't be another way...)

Matro.


I've added the pullup resistors ....and it works !!

Thank you very much ;)

Nora



Joined: 23 Mar 2008
Posts: 50

View user's profile Send private message

PostPosted: Mon Mar 31, 2008 7:42 am     Reply with quote

Can someone explain why the pullup resistors are needed?
Thanks-
N_N
Matro
Guest







PostPosted: Mon Mar 31, 2008 8:29 am     Reply with quote

Because that the concept of the I²C.
Every pin connected on the bus (clock or data) is open-collector or open-drain.
So you have to pull-up the 2 lines to be able to see high voltages.
It avoids short-circuit if 2 chips are controling the bus at the same time and allows collision detection.
That is a very quick and simple answer.
You can find a lot of document about I²C physical layer on Internet.
The CAN bus has the same way of working so you can find documentation about it too.

Matro.
w2drz



Joined: 27 Dec 2006
Posts: 55
Location: Western New York - USA

View user's profile Send private message Visit poster's website

New user and pass word to log on
PostPosted: Mon Mar 31, 2008 4:16 pm     Reply with quote

New user and how long to be accepted to post under a user name???

The new user has info regarding the DS1621.C.
and formula being a bit wrong in this routine.

tom

The #use I2C is in the DS1621.C. Question
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