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 Slave, i2c_poll returns

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







I2C Slave, i2c_poll returns
PostPosted: Tue Jan 16, 2007 9:59 am     Reply with quote

Hello all,

I use a 16F877 as a slave and a very simple code.
I poll data in a while ( while (!i2c_poll) ) and then do an i2c_read
When with the master board (another system) I send data on the i2c bus, my program goes in the while (so, i2c_poll found some data to get). I then do an i2c_read, but it hangs here. i2c_read does not return. OK1 is outputed on the RS232, but not the OK2
Does anybody have an idea of what it could be ?
Regards,

Matt.
Code:

#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
 
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xA0)
 

void main()
{
      puts("I2C TRACES");
i2c_start();
 
while(!i2c_poll())
{
   puts("OK1");
   test = i2c_read();
   puts("OK2");
}
i2c_stop();
while (true)
   {
 
   }
}
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 11:20 am     Reply with quote

I would suggest you use the hardware that is on the PIC to do your I2C reception. You are using a software I2C and the hardware will be much more effective. Put some code in the ISR and start your experimenting there. There are boat loads of posts regarding this stuff and you can get a good start from them.

Ronald
Matt.
Guest







PostPosted: Wed Jan 17, 2007 2:09 am     Reply with quote

Even with ISR it does not work. I guess it is a hardware problem ...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 17, 2007 2:28 am     Reply with quote

Your slave code is incorrect. I2c slaves don't do start and stop bits.
The master does those operations.

Also, when you specify "SLAVE" in the #use i2c statement, the compiler
will automatically use the hardware i2c module, if the hardware pins are
also specified.

Look at the CCS example file on how to do an i2c slave. It's called
Ex_Slave.c and it's in this folder: c:\Program Files\Picc\Examples
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