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

Basic I2C for 12F675 problems

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



Joined: 18 Dec 2007
Posts: 18

View user's profile Send private message

Basic I2C for 12F675 problems
PostPosted: Wed Dec 19, 2007 1:31 am     Reply with quote

Hi,

i am trying to use I2C between master and slave. I have read a lot of posts and experimented but cant get comms working. I am trying to get the master to send 0x20 to the slave and then for the slave to receive it and turn on Pin_A2 but nothing happens?

Master

#include <12F675.h>
#device adc=8
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, NOMCLR, NOPUT, NOBROWNOUT
#use delay(clock=4000000)
#use i2c(master,fast,SDA=PIN_A0,SCL=PIN_A1)

void main()
{

while(1){

i2c_start();
i2c_write(0xA0);
i2c_write(0x20);
i2c_stop();
}

}


Slave

#include <12F675.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES RC //Resistor/Capacitor Osc with CLKOUT
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPUT //No Power Up Timer
#FUSES BROWNOUT //Reset when brownout detected
#use i2c(SLAVE, SDA=PIN_A0, SCL=PIN_A1, address=0xA0, FORCE_HW)
#use delay(clock=4000000)

void main()
{
BYTE incoming;

while(1){

incoming = i2c_read();

if(incoming=0x20)
output_high(PIN_A2);


}

}[/quote]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 19, 2007 1:53 am     Reply with quote

The 12F675 does not have an SSP module. The #use i2c() statement
only works with a hardware i2c module. The CCS manual says:
Quote:
The SLAVE mode should only be used with the built-in SSP.

You need to get a PIC that has an SSP or MSSP module.
apl01



Joined: 18 Dec 2007
Posts: 18

View user's profile Send private message

PostPosted: Wed Dec 19, 2007 2:38 am     Reply with quote

Ok, can i use rs232 instead of I2C? I have developed some rs232 code similar to that of the I2C code above which doesn't work should i post a new topic?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 19, 2007 12:47 pm     Reply with quote

If it doesn't work, then post it.
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