View previous topic :: View next topic |
Author |
Message |
apl01
Joined: 18 Dec 2007 Posts: 18
|
Basic I2C for 12F675 problems |
Posted: Wed Dec 19, 2007 1:31 am |
|
|
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
|
|
Posted: Wed Dec 19, 2007 1:53 am |
|
|
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
|
|
Posted: Wed Dec 19, 2007 2:38 am |
|
|
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
|
|
Posted: Wed Dec 19, 2007 12:47 pm |
|
|
If it doesn't work, then post it. |
|
|
|