|
|
View previous topic :: View next topic |
Author |
Message |
iVoVa
Joined: 12 Mar 2011 Posts: 7
|
Proteus I2C have a problem, help me ! |
Posted: Wed Mar 16, 2011 11:16 pm |
|
|
Code: | #include<18F4520.h>
#include"DEF_18F4520.c"
#fuses HS
#use delay(clock = 4000000)
#use I2C(MASTER , SDA = PIN_C4, SCL = PIN_C3)
#use FAST_IO( A B)
#use FAST_IO ( C D )
#define slave_address 0x41
int8 data_in ;
void i2c_send(data_in)
{
i2c_start();
i2c_write(slave_address);
i2c_write(data_in);
i2c_stop();
}
void main()
{
while(true)
{
data_in = input_B();
i2c_send(data_in);
}
} |
Code: | #include<18F4520.h>
#include"DEF_18F4520.c"
#fuses HS
#use delay(clock = 4000000)
#use I2C(SLAVE , SDA = PIN_C4, SCL = PIN_C3, address = 0x41)
#use FAST_IO(B)
int8 data_out ;
#INT_SSP
void i2c_isr()
{
int8 state;
state = i2c_isr_state();
if(state<0x80)
{
if (state == 1)
{
data_out = i2c_read();
output_b(data_out);
}
}
if(state >= 0x80)
{
}
clear_interrupt(INT_SSP);
}
void main()
{
trisb = 0x00;
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
while(true)
{
}
} |
Port B at Slave do not show the input from Master. Please help me to fix my problem. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 16, 2011 11:33 pm |
|
|
Your program has some mistakes. For example, you have an odd
number as the i2c slave address. But it must be an EVEN number.
Also, the pull-up resistors on your schematic should be changed to
4.7K (4700 ohms).
If you can't make your program work, then I suggest that you use the
CCS example file code, Ex_Slave.c, for the Slave PIC. It's in this directory:
Quote: |
c:\Program Files\picc\Examples\Ex_Slave.c
|
Use the code in this post for the Master PIC:
http://www.ccsinfo.com/forum/viewtopic.php?t=32368&start=3 |
|
|
iVoVa
Joined: 12 Mar 2011 Posts: 7
|
|
Posted: Thu Mar 17, 2011 5:36 am |
|
|
Thanks PCM so much, you help me get a lot of knowledges.
My program worked. |
|
|
|
|
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
|