View previous topic :: View next topic |
Author |
Message |
gremi
Joined: 11 Mar 2008 Posts: 20 Location: Toulouse, France
|
Can't make I2C works [Solved] |
Posted: Wed Mar 26, 2008 4:03 am |
|
|
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
|
|
Posted: Wed Mar 26, 2008 4:23 am |
|
|
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
|
|
Posted: Wed Mar 26, 2008 4:39 am |
|
|
The #use I2C is in the DS1621.C.
I didn't put it in the post because it's a CCS driver ... |
|
|
Matro Guest
|
|
Posted: Wed Mar 26, 2008 4:57 am |
|
|
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
|
|
Posted: Wed Mar 26, 2008 6:16 am |
|
|
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
|
|
Posted: Wed Mar 26, 2008 6:25 am |
|
|
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
|
|
Posted: Wed Mar 26, 2008 6:33 am |
|
|
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
|
|
Posted: Wed Mar 26, 2008 6:44 am |
|
|
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
|
|
Posted: Wed Mar 26, 2008 7:42 am |
|
|
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
|
|
Posted: Wed Mar 26, 2008 8:04 am |
|
|
Add NOLVP to #FUSES. _________________ David |
|
|
gremi
Joined: 11 Mar 2008 Posts: 20 Location: Toulouse, France
|
|
Posted: Wed Mar 26, 2008 9:42 am |
|
|
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
|
|
Posted: Mon Mar 31, 2008 7:42 am |
|
|
Can someone explain why the pullup resistors are needed?
Thanks-
N_N |
|
|
Matro Guest
|
|
Posted: Mon Mar 31, 2008 8:29 am |
|
|
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
|
New user and pass word to log on |
Posted: Mon Mar 31, 2008 4:16 pm |
|
|
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. |
|
|
|