Technical Data

This69bytesequencewritesthelast64bytestoaddress0x0000intheeeprom.All69bytesshouldbesenttotheUSBI2Cinonesequence.A
gapwillresultintheUSBI2Crestartingitsinternalcommandsynchronizationloopandignoringthemessage.Afterallbyteshavebeenreceived
theUSBI2CperformstheIC2writeoperationouttotheeepromandsendsasinglebytebacktothePC.Thisreturnedbytewillbe0x00(zero)if
thewritecommandfailedandnonzeroifthewritesucceeded.ThePCshouldwaitforthisbytetobereturned(timingoutafter500mS)before
proceedingwiththenexttransaction.
ReadingfromI2Cdeviceswitha2byteinternaladdressregister
Thisissimilartowriting,exceptthatyoushouldadd1tothedeviceaddresstomakeitanoddnumber.Toreadfromaneepromataddress0xA0,
youwoulduse0xA1astheaddress.(WhentheaddressgoesoutontheI2Cbus,itsthe1inthelowestbitpositionthatindicatesareadcycleis
happening).Themaximumnumberofdatabytesrequestedshouldnotexceed64soasnottooverflowtheUSBI2C'sinternalbuffer.Hereisan
exampleofreading64(0x40)bytesfrominternaladdress0x0000ofaneepromatI2Caddress0xA0.
I2C_AD2 DeviceI2Caddress+Readbit HighbyteofinternalAddress LowbyteofinternalAddress Numberofbytestoread
0x56 0xA1 0x00 0x00 0x40
TheUSBI2CwillperformthereadoperationontheI2Cbusandsend64bytesbacktothePC.ThePCshouldwaitforall64bytestobereturned
(timingoutafter500mS)beforeproceedingwiththenexttransaction.
USBI2CCommands
TheUSBI2Ccommandformatisshownbelow:
I2C_USB USBI2CCommand Data1 Data2
0x5A Seebelow CommandSpecific CommandSpecific
TheUSBI2Ccommandsarealwaysafourbytesequence.TheystartwiththeI2C_USBprimarycommandwhichisfollowedbytheUSBI2C
commanditself.Twodatabytesfollowwhichcanbeanyjunkifnotused,buttheymustbeincludedtomakeupthe4bytecommandsequence.
Thesecommandsare:
Hex Command
Bytes
returned
Purpose
0x01 REVISION 1 ReturnstheUSBI2Cfirmwarerevisionnumber
0x02 NEW_ADDRESS 1 ChangesSRF08I2Caddress
0x03 UNUSED 1 UnusedforCM02compatibilityonlyreturns0x00
0x04 SCAN1 6 Sendmotordatareturnbattery,compass&sonardata
0x05 SCAN2 9 Samebutfor2SRF08's
0x06 SCAN3 12 3SRF08's
0x07 SCAN4 15 4
0x08 SCAN6 21 6
0x09 SCAN8 27 8
0x0A SCAN12 39 12
0x0B SCAN16 51 All16possibleSRF08's
0x10 SETPINS 1 SetsI/Opinshigh/low
0x11 GETPINS 1 GetsthestatusofI/Opins
0x12 GETAD 4 GetsAnaloguevalueonI/O2andI/O3
REVISIONisusedtoreadtheUSBI2Cfirmwarerevision.Itreturnsasinglebyteindicatingtherevisionnumber.Thetwodatabytesareunused
andcanbeanything,buttheymustbesent.
NEW_ADDRESScommandisusedtochangeanSRF08'sI2Caddresstoadifferentaddress.Thenewaddressshouldbeinthefirstofthetwo
databytes.Theseconddatabyteisunusedandcanbeanything,butitmustbesent.ChangingtheaddressontheSRF08requires4separate
transactionsontheI2Cbus.TheUSBI2CknowhowtochangeanSRF08'sI2Caddressandjustneedsyoutosenditthenewaddressusingthis
command.Whenusingit,makesureyouonlyhaveoneSRF08connected,otherwiseyouwillseteverySRF08onthebustothesameaddress.
Thesinglereturnbyteisthenewaddresssentbackwhenthetaskiscomplete.
UNUSEDUnusedforCM02compatibilityonlyreturns0x00.
SCANThiscommandisprovidedforCM02compatibility.ItassumesyouhaveanMD22motorcontroller,aCMPS03compassmoduleanda
numberofSRF08rangefinders.SCAN1assumes1SRF08,SCAN8assumes8SRF08's.ThetwodatabytescontaintheLeftandRightmotor
speedvaluesfortheMD22motorcontroller.AftersendingthenewmotorspeedstotheMD22,theUSBI2Cwillsendareturnframecomprising
thebatteryvoltage(0x00seeabove).Thisisfollowedbytwobytesofcompassbearinghighbytefirst,andthenthreebytesforeachSRF08.
ThefirstofthethreebytesistheSRF08'slightsensorreading.Thenexttwobytesistherangehighbytefirst.
Forexample,iftheSCAN2commandisused,youwouldreceivea9bytereturn:
BatteryVolts
(reads0x00)
Compass
bearinghigh
byte
Compass
bearinglow
byte
SRF08at0xE0
Lightsensor
SRF08at0xE0
Rangehigh
byte
SRF08at0xE0
Rangelowbyte
SRF08at0xE2
Lightsensor
SRF08at0xE2
Rangehigh
byte
SRF08at0xE2
Rangelowbyte
SRF08dataisalwaysreturnedstartingwithaddress0xE0,0xE2,0xE4goinguponeaddressatatimeuntilallrequestedSRF08'sdatahasbeen
sent.
AftersendingthedatabackuptothePC,theUSBI2CautomaticallyissuesanewrangingcommandtoallSRF08s.Therangingcommandused
is82(0x52)whichreturnstheresultsinuS.Toconverttocmdivideby58andtoconverttoinchesdivideby148.