دوستان سلام
من برای ارتباط بین دو میکرو ازطریق I2C مداری رو طراحی و اجرا کردم .
کدهاش رو در بسکام نوشتم.
در عمل هرچی سروکله زدم نتونستم این ارتباط رو برقرار کنم ممنون میشم بگید ایراد کارم کجاست؟
کدهای نوشته شده برای Slave , master اینا هستن:
من برای ارتباط بین دو میکرو ازطریق I2C مداری رو طراحی و اجرا کردم .
کدهاش رو در بسکام نوشتم.
در عمل هرچی سروکله زدم نتونستم این ارتباط رو برقرار کنم ممنون میشم بگید ایراد کارم کجاست؟
کدهای نوشته شده برای Slave , master اینا هستن:
'Master
$regfile = "M16def.dat"
$crystal = 4000000
$swstack = 128
Config portB =OUTPUT
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5 , E = Portb.1 , Rs = Portb.0
enable interrupts
Config Sda = Portc.1
Config Scl = Portc.0
Dim dd As Byte , Slave As Byte
Slave = &H51
do
dd = &B00000000
locate 1,1
lcd "Before:"
locate 1,9
lcd bin(dd)
i2cstart
I2creceive slave, dd,2,2
i2cstop
locate 2,1
lcd "Next :"
locate 2,9
lcd bin(dd)
loop
End
$regfile = "M16def.dat"
$crystal = 4000000
$swstack = 128
Config portB =OUTPUT
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.3 , Db6 = Portb.4 , Db7 = Portb.5 , E = Portb.1 , Rs = Portb.0
enable interrupts
Config Sda = Portc.1
Config Scl = Portc.0
Dim dd As Byte , Slave As Byte
Slave = &H51
do
dd = &B00000000
locate 1,1
lcd "Before:"
locate 1,9
lcd bin(dd)
i2cstart
I2creceive slave, dd,2,2
i2cstop
locate 2,1
lcd "Next :"
locate 2,9
lcd bin(dd)
loop
End
پورت b0 در Slave به یک LED وصل شده تا ببینم میکرو Slave داره چیکار میکنه

'slave
$regfile = "M16def.dat"
$crystal = 4000000
$swstack = 128
Config portB =OUTPUT
$LIB "I2C_TWI.LBX"
Config Sda = Portc.1
Config Scl = Portc.0
Config Twi = 200000
Dim XX As Byte , Slave As Byte , s as Integer , ss as Integer
XX = &B00000000
ss = 1
Slave = &H51
do
xx=xx+&B00000001
ss=ss+1
for s=1 to ss
portb.0 = 1
waitms 10
portb.0 = 0
waitms 30
next s
portb.0 = 1
waitms 2000
i2cstart
I2csend slave , XX ,2
i2cstop
if ss= 10 then
ss=1
endif
loop
End
$regfile = "M16def.dat"
$crystal = 4000000
$swstack = 128
Config portB =OUTPUT
$LIB "I2C_TWI.LBX"
Config Sda = Portc.1
Config Scl = Portc.0
Config Twi = 200000
Dim XX As Byte , Slave As Byte , s as Integer , ss as Integer
XX = &B00000000
ss = 1
Slave = &H51
do
xx=xx+&B00000001
ss=ss+1
for s=1 to ss
portb.0 = 1
waitms 10
portb.0 = 0
waitms 30
next s
portb.0 = 1
waitms 2000
i2cstart
I2csend slave , XX ,2
i2cstop
if ss= 10 then
ss=1
endif
loop
End