Komisch ist das schon weil egal was ich bei scl und sda eingebe er meldet immer master needs byte
Master:
Code:$regfile = "M32def.dat" ' the used chip $crystal = 16000000 ' frequency used $baud = 9600 ' baud rate $lib "i2c_twi.lbx" ' we do not use software emulated I2C but the TWI Config Scl = Portc.0 ' we need to provide the SCL pin name Config Sda = Portc.1 ' we need to provide the SDA pin name I2cinit ' we need to set the pins in the proper state Config Twi = 100000 ' wanted clock frequency 'will set TWBR and TWSR 'Twbr = 12 'bit rate register 'Twsr = 0 'pre scaler bits Dim B As Byte , X As Byte Print "TWI master" B = 125 Do ' increase value I2csend &H70 , B ' send the value ' show error Waitms 500 'wait a bit Loop End
Slave:
Code:$regfile = "M32def.dat" ' the chip we use $crystal = 16000000 ' crystal oscillator value $baud = 9600 ' baud rate Print "MCS Electronics TWI-slave demo" Config Twislave = &H70 , Btr = 1 , Bitrate = 100000 ' the code below #else is executed by the compiler when you use version 11175 or higher 'as you might need other interrupts as well, you need to enable them manual Enable Interrupts 'this is just an empty loop but you could perform other tasks there Do nop Loop End 'A master can send or receive bytes. 'A master protocol can also send some bytes, then receive some bytes 'The master and slave must match. 'the following labels are called from the library Twi_stop_rstart_received: Print "Master sent stop or repeated start" Return Twi_addressed_goread: Print "We were addressed and master will send data" Return Twi_addressed_gowrite: Print "We were addressed and master will read data" Return 'this label is called when the master sends data and the slave has received the byte 'the variable TWI holds the received value Twi_gotdata: Print "received : " ; Twi Return 'this label is called when the master receives data and needs a byte 'the variable twi_btr is a byte variable that holds the index of the needed byte 'so when sending multiple bytes from an array, twi_btr can be used for the index Twi_master_needs_byte: Print "Master needs byte : " ; Twi_btr Twi = 65 ' twi must be filled with a value Return 'when the mast has all bytes received this label will be called Twi_master_need_nomore_byte: Print "Master does not need anymore bytes" Return






Zitieren

Lesezeichen