Hi,
ich baue grad eine Servo-Steuerung über I2C! Also die Komunikation zwischen 2 IC´s gehtbei mir! hier mal der Code!
Slave:
Code:
$regfile = "m8def.dat" ' specify the used micro
$crystal = 12000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 32 ' default use 32for the SW stack
$framesize = 40 ' default use 40 for the frame space
'SCL is PORTD.4 (T0)
'SDA is PORTD.2 (INT0)
'Use 10K pull up resistors for both SCL and SDA
Config I2cslave = &B01000000 ' same as &H40
Dim Bfake As Byte
Do
Loop
I2c_master_needs_data:
Bfake = 60
_a1 = Bfake
Return
'When the master writes a byte, the following label is always called
'It is your task to retrieve variable _A1 and do something with it
'_A1 is register R16 that could be destroyed/altered by BASIC statements
'For that reason it is important that you first save this variable
I2c_master_has_data:
Bfake = _a1
Print "Data: " ; Bfake
Return
_slave_address = &H40 + Switches ' set the proper address
Master:
Code:
$regfile = "m16def.dat"
$framesize = 32
$swstack = 32
$hwstack = 32
$crystal = 4000000
'or use the TWI !
Config Scl = Porta.1
Config Sda = Porta.2
Do
I2cstart
I2cwbyte &H40
I2cwbyte &H91
I2cstop
Wait 3
I2cstart
I2cwbyte &H40
I2cwbyte &H3C
I2cstop
Wait 3
Loop
Lesezeichen