|
|
View previous topic :: View next topic |
Author |
Message |
[email protected]
Joined: 07 Feb 2012 Posts: 19 Location: pakistan
|
I2c Ex_slave (receiving of data problem) |
Posted: Mon Feb 20, 2012 1:19 am |
|
|
I want to communicate 2 pic 18f452 controllers but these are not working correctly. I think there must be problem at slave side. The interrupt is not generating. I'm posting photos and code.
Pull-up resistors are 4.7k
Compiler ccs 4.084
I have to submit on Wednesday. Plz help me to resolve the problem.
Tell me about FORCE_HW & FORCE_SW.
Slave address is 0x60. By adding high bit at most least significant bit for writing from master to slave becomes 0xc0.
The master side is working correctly.
Master:
Code: |
#include<18F452.h>
#use delay(clock = 4000000)
#use I2C(MASTER,SLOW, SDA=PIN_B7, SCL=PIN_B6,FORCE_SW)
#fuses NOWDT,NOPROTECT,NOLVP,XT
void main ()
{
while(1)
{
output_a(0xff);
delay_ms(2000);
i2c_start();
//while(i2c_write(0xc0));
i2c_write(0xC0);
output_a(0xC0);
delay_ms(1000);
i2c_write(0x1);
output_a(0x01);
delay_ms(1000);
i2c_write(0x02);
output_a(0x02);
delay_ms(1000);
i2c_write(0x03);
output_a(0x03);
delay_ms(1000);
i2c_write(0x04);
output_a(0x04);
delay_ms(1000);
i2c_write(0x05);
output_a(0x05);
delay_ms(1000);
i2c_stop();
}
}
|
Slave :
Code: |
#include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use i2c(SLAVE, SDA=PIN_B7, SCL=PIN_B6, address=0x60,FORCE_SW)
BYTE address, buffer[0x10];
#INT_SSP
void ssp_interupt ()
{
BYTE incoming, state;
state = i2c_isr_state();
if(state < 0x80) //Master is sending data
{
incoming = i2c_read();
if(state == 1) //First received byte is address
address = incoming;
if(state == 2) //Second received byte is data
{
buffer[address] = incoming;
output_a(incoming);
}
}
if(state == 0x80) //Master is requesting data
{
i2c_write(buffer[address]);
}
}
void main ()
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
while (TRUE) {}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 20, 2012 2:27 pm |
|
|
Quote: | #include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use i2c(SLAVE, SDA=PIN_B7, SCL=PIN_B6, address=0x60,FORCE_SW)
|
There is no support for a software i2c slave. You must use the hardware
pins for an i2c slave. For an 18F452, this is pin C4 for SDA, and pin C3 for SCL. |
|
|
[email protected]
Joined: 07 Feb 2012 Posts: 19 Location: pakistan
|
thanks |
Posted: Tue Feb 21, 2012 5:36 am |
|
|
I have done it |
|
|
wasimakhlaq
Joined: 07 Feb 2012 Posts: 5 Location: Pakistan
|
Thanks |
Posted: Tue Feb 21, 2012 8:04 am |
|
|
Thanks all of you for your posts and helping us, we're done I2C communication using two PICs..
regards,
wasim |
|
|
|
|
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
|