View previous topic :: View next topic |
Author |
Message |
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sat Aug 16, 2014 9:43 am Post subject: i2cslave best practice |
|
|
Hi All,
I'm currently working on a i2c slave board that supports multiple functions (IRDA data send, IRDA data receive, Read RFID Number, Enable/Disable RFID) and have a few questions about the best way to handle the i2c comms.
I already have the i2cslave lib and can communicate with the slave, that's not my problem. My question is what's the best way to handle the i2c comms at a higher level I need to send a command from the master to the slave, the slave should then act on the command or return data something like:-
for Data to send per IRDA
i2cstart, IRDA Send Command, IRDA to send (X Bytes), i2cstop
Get last data packet received from IRDA
i2cstart, IRDA Receive Command, last IRDA packet received (X Bytes), i2cstop
So for some commands I need to switch from Sending a Byte (Command) to receiving data (last IRDA packet received). Looking at other i2c devices they always seem to use a i2crestart to switch from Slave Receiving to i2c Slave sending. So my question is if the i2crestart really necessary? I'm controlling both ends of the i2c bus and don't need compatibility with other systems so I can program it as I want.
Regards
Ian Dobson
(BASCOM-AVR version : 2.0.7.7 ) _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sat Aug 16, 2014 1:54 pm Post subject: |
|
|
Hi,
To answer my own question you need to use :
i2cstart, Write "Write Addres", Write Command, i2crepstart, Write "Read Address", Read Bytes, i2cstop
The i2cslave lib needs to see the read address to work.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Aug 18, 2014 9:19 am Post subject: |
|
|
I2CRECEIVE will do that all in one : sending and receiving.
I would stick to the protocol so the chips will work universal. _________________ Mark |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Thu Aug 21, 2014 9:11 pm Post subject: |
|
|
Hi Mark,
Thanks for the answer. I prefer to use the i2cwbyte/i2crbyte rather than i2csend/i2creceive. It just makes it easier to see exactly whats going on from a protocol Level.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
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
|
|