View previous topic :: View next topic |
Author |
Message |
Carlos
Joined: 16 Mar 2006 Posts: 19
|
Posted: Sun Oct 19, 2014 9:15 am Post subject: I2C commercial slave library addon |
|
|
Hello,
I work with the commercial I2C slave library addon.
Code: | comment = BASCOM-AVR USI I2C slave library
libversion = 2.0.7.7
date = 8 Jan 2014
|
This configuration works well - the Master sends with 'I2creceive" 2 Bytes to the Slave and receives an amount of A bytes in reply.
Code: | Master Slave
Derivate: ATMega1284 ATMega8
I2C-Lib: Lib "I2C_TWI.LBX"
Transmit/Rec: I2creceive Slave_ad, Config Twislave = &H70 , Btr = A , Bitrate = 100000
Buf(1) , 2 , A
|
This configuration doesn't work so well, when A > 2:
The Master sends with 'I2creceive" 2 Bytes to the Slave and receives 2 Bytes in reply.
But when A>2 then the Slave only send 2 Bytes - no more!
Where can I configure that the Slave sends more than 2 Bytes to the Master?
In the previous configuration I can define how many Bytes the Slave sends to the Master with Btr=A.
Code: | Master Slave
Derivate: ATMega1284 ATTiny2313
I2C-Lib: Lib "I2C_TWI.LBX"
Transmit/Rec: I2creceive Slave_ad, config USI = twislave , address = &H70
Buf(1) , 2 , A
|
But that doesn't seem to work here. Does anyone have any Ideas what to change to receive more than 2 bytes?
best greatings,
Ernst
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sun Oct 19, 2014 10:32 am Post subject: |
|
|
Hi,
I also use the i2cslave lib and in my configuration the master can send between 1 and 32 Bytes. I solved it by just Setting the Bytes received to > 32 Bytes and using the i2cstop isr to decide what to do with the data recieved, if the data is a Multi Byte command or the first Byte received if the command is a single Byte.
something like:-
Code: |
Twi_stop_rstart_received: 'Single byte commands
Select Case I2c_command 'En/Dis RFID Reader
Case Is = _rfid_dis
Reset Rfid_enable 'Disable RFID reader
I2c_command = 0
Case Is = _rfid_en
Set Rfid_enable 'Enable RFID Reader
I2c_command = 0
Case Is = _rfid_clear 'Clear RFID Nr
Rfid_number = 0
I2c_command = 0
' Case Is = _reset 'Reboot uC
' Reboot_uc = 1
' I2c_command = 0
Case Is = _firmware_update 'Firmware update command
Firmware_update = 1
I2c_command = 0
End Select
return
Twi_gotdata:
If Twi_btw = 1 Then 'First byte written is command
I2c_command = Twi
Else
I2c_recieved(twi_btw) = Twi
End If
If I2c_command = _irda_send And Twi_btr = _i2c_packet_size_receive Then
Isr_temp = Memcopy(i2c_recieved(2) , Irda_send(1) , _i2c_packet_size_receive )
I2c_command = 0
End If
return
Twi_master_needs_byte:
Select Case I2c_command
Case Is = _read_rfid
Twi = Rfid_number_array(twi_btr ) 'Return RFID byte
If Twi_btr = _i2c_packet_size_rfid Then
I2c_command = 0
End If
Case Is = _irda_rec
Twi = Irda_rec(twi_btr ) 'Return IRDA byte '
If Twi_btr = _i2c_packet_size_send Then
I2c_command = 0
End If
Case Is = _version
Twi = _myversion
I2c_command = 0
Case Else 'Send 00 if things
Twi = &H00 'are screwed up
End Select
return
|
regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
Carlos
Joined: 16 Mar 2006 Posts: 19
|
Posted: Sun Oct 19, 2014 12:18 pm Post subject: |
|
|
thank you Ian,
but that was not the question.
If the Master works with "I2C_TWI.LBX" and Slave works also Twislave than the communication is o.k.
But when the Slave works with "I2c_USI_Slave.Lib" (Attiny2313) then the Slaves givs only 2 correct
Byes back, tha other bytes are not true!
the master sends:
I2creceive Slave_ad, Buf(1) , 2 , A
how can I set the number of bytes(A) , which then sends the slave back to the Master?
[/img] |
|
Back to top |
|
|
Carlos
Joined: 16 Mar 2006 Posts: 19
|
Posted: Tue Oct 21, 2014 5:36 pm Post subject: |
|
|
Mark has created a new update.
I have tested it. Now it is running.
The new update for the i2c package will be provided by Mark this week for general usage.
problem solved
Best greatings,
Ernst |
|
Back to top |
|
|
|
|
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 You cannot attach files in this forum You cannot download files in this forum
|
|