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

I2C Problems

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







I2C Problems
PostPosted: Fri Nov 17, 2006 4:17 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Nov 17, 2006 4:54 pm     Reply with quote

How to create a master program that will talk to the CCS example file,
Ex_Slave.c:
http://www.ccsinfo.com/forum/viewtopic.php?t=28473&start=1

Possible reasons why Proteus could have problems:
http://www.ccsinfo.com/forum/viewtopic.php?t=28744
Guest








PostPosted: Fri Nov 17, 2006 5:59 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Nov 17, 2006 6:05 pm     Reply with quote

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)
PostPosted: Fri Nov 17, 2006 10:02 pm     Reply with quote

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?
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