I purchased the libraries as I want to design an I2C slave connection for an existing firmware which already runs perfect.
Unfortunately the manual which comes with the libraries is pretty sparse and the sample codes didn't get me any further either.
I have to write (master to my new slave) 1 or 2 or 4 bytes and provide back 1, 2, 4 bytes which the master has to read.
There are two variables TWI_btw (for received bytes) and TWI_btr (for send bytes) which look like they can be used to increment the data which I have in an array.
When (if at all) do these get reset to 0 (or 1)? Is it when the I2C receives a correct address? Does the channel stay open or only for the amount of bytes specified in the config BTR=x?
If I specify BTR=4 (4 bytes) in the config, is there a way to get this working if I only transfer 1 or 2 bytes or do I have to invent an end transmission signal?
Thanks a lot for any help you may be able to provide!
'address 70 , read 4 byte
(max)
Config Twislave = &H70 , BTR = 4 , BITRATE = 100000, GENCALL=1, USERACK=ack
'=======I2C slave sub-routines ================================
'the following labels are called from the library
Twi_stop_rstart_received:
'nothing to do here
Return
Twi_addressed_goread:
'nothing to do here
Return
Twi_addressed_gowrite:
'nothing to do here
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:
I2C-data = TWI(TWI_btw)
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:
TWI = SensData(TWI_btr)
Return
'when the mast has all bytes received this label will be called
Twi_master_need_nomore_byte:
TWI_btr=0 '????????
Return
[b:165f0bd2b2][color=red:165f0bd2b2](BASCOM-AVR version : 2.0.7.6 )[/b:165f0bd2b2][/color:165f0bd2b2]
↧