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

I2c problem..

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



Joined: 24 Nov 2004
Posts: 3
Location: Korea, Seoul

View user's profile Send private message MSN Messenger

I2c problem..
PostPosted: Mon Nov 29, 2004 7:42 am     Reply with quote

hi~
i'm studying I2C by using two pic that one is master and others is slave..
but..My problem is result
command transfered to slave is not same result on slave..
in slave , result was random..
i'm not sure what is my proble..
plz..help me..
And if you can, could you give me some example for transferring by using two pics (i'm using 16f874)..


[code]
#include <16F874.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP,PUT

/* Delay for 4 mhz crystal */
#use delay (clock=4000000)

/* Setup RS232 */
#use rs232(baud=9600, xmit=PIN_c6,rcv=PIN_c7)

/* Setup I2C */
#use I2C(MASTER, sda=PIN_C4, scl=PIN_C3, SLOW)

main()
{
int8 i2c_command ;

while (true)
{
for(i2c_command=0x00; i2c_command<=0xff; i2c_command++){
delay_ms(1000);
printf("Outputting: %c", i2c_command);

/* Master */
i2c_start(); // Start condition
i2c_write(0xa0); // Device address
delay_ms(50);
i2c_write(i2c_command); // Write Command
i2c_stop(); // Stop condition
}
i2c_command=0x00;

}
}



<slave>
/* Standard Include for 16F877 Chip */
#include <16F874.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP,PUT

/* Delay for 4 mhz crystal */
#use delay (clock=4000000)

/* Setup RS232 */
#use rs232(baud=9600, xmit=PIN_c6,rcv=PIN_c7)

/* Setup I2C */
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xa0, SLOW, FORCE_HW)

#INT_SSP
void ssp_interupt ()
{
byte incoming;
incoming = i2c_read();
printf("\n\rRead byte 1: %x\n\r", incoming);
incoming = i2c_read();
printf("Read byte 2: %x\n\r\n\r", incoming);
}


main()
{
delay_ms(1000);
printf("Running");

enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
while (true)
{

}
}

[/code]
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 29, 2004 9:53 am     Reply with quote

Take a look at "ex_slave.c"
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