|
|
View previous topic :: View next topic |
Author |
Message |
Gugz Guest
|
I2C Problems |
Posted: Fri Nov 17, 2006 4:17 pm |
|
|
Hi guys! I'm trying to communicate two 16f877 with I2C, but it just don't work and i have no idea why...
It seems like the master sends the address, but the slave don't recognise it... Can you help me please?
The part of the code from master that utilizes I2C and from slave are:
MASTER:
#use i2c (master, scl = pin_c3, sda = pin_c4)
(....)
i2c_start ();
i2c_write (0xA0);
delay_ms (10);
i2c_write (dado1);
delay_ms (10);
i2c_stop();
SLAVE:
#include <16F877.h>
#device adc=8
#fuses NOWDT,RC, NOPUT, NOPROTECT, BROWNOUT, LVP, NOCPD, NOWRT, NODEBUG
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N, xmit=PIN_B2, rcv=PIN_B1, bits=9)
#use i2c (slave, address = 0xa0, scl = pin_c3, sda = pin_c4)
#int_SSP
SSP_isr()
{
printf ("%d", i2c_read());
}
void main ()
{
enable_interrupts(INT_SSP);
enable_interrupts(global);
while (true);
}
Oh, by the way, I'm trying to send 'dado1' to the slave and to write this in a Virtual Terminal (PROTEUS).
Thanks for the help. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Guest
|
|
Posted: Fri Nov 17, 2006 5:59 pm |
|
|
MASTER:
#use i2c (master, scl = pin_c3, sda = pin_c4)
(....)
i2c_start ();
i2c_write (0xA0);
i2c_write (0x00);
delay_ms (10);
i2c_write (dado1);
delay_ms (10);
i2c_stop();
Still don't work. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 17, 2006 6:05 pm |
|
|
Quote: | #include <16F877.h>
#device adc=8
#fuses NOWDT,RC, NOPUT, NOPROTECT, BROWNOUT, LVP, NOCPD, NOWRT, NODEBUG
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N, xmit=PIN_B2, rcv=PIN_B1, bits=9)
#use i2c (slave, address = 0xa0, scl = pin_c3, sda = pin_c4) |
1. You can't run at 20 MHz with the RC oscillator. It can only run at
up to 4 Mhz maximum. I don't know if Proteus knows this or not.
You should use HS as the fuse for a 20 MHz crystal.
2. Don't set the LVP fuse. It can cause the PIC to lock up if pin B3
is left floating. Again, I don't know if Proteus knows this.
Change the setting to NOLVP.
3. If you're going to use RS232, you should use pins C6 and C7
since these are the hardware UART pins. Also, the standard
number of bits is 8. Don't set it to 9.
4. Do you have the 4.7K pull-up resistors on SDA and SCL ? |
|
|
Gugz Guest
|
Problem solved (in part) |
Posted: Fri Nov 17, 2006 10:02 pm |
|
|
Ok, I forgot the pull-ups resistors... Now it's working... But, still have some weird going on: for example, if dado1 = 52, when i make printf ("%d\r\n", dado1); , the virtual terminal shows:
-06
52
So, why this -06 is showed? Some kind of a junk? |
|
|
|
|
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
|