Richard
Joined: 24 Nov 2004 Posts: 3 Location: Korea, Seoul
|
I2c problem.. |
Posted: Mon Nov 29, 2004 7:42 am |
|
|
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] |
|