I'm trying to interface a ZBasic to a MaxSonarEZ1 (http://www.maxbotix.com/uploads/LV-MaxS ... asheet.pdf), and have been running into a rather annoying problem. Whenever I attempt to request a pulse stream and the first data bits reach the ZBasic, it resets itself, or sometimes just freezes. Something bad is clearly happening as the chip receives the pulses, I've tried transistor isolation so it's something more than over current. My code is below,
Thanks for your help,
Nathaniel
Code: Select all
'-----------------------------------------------------------------------------------------------------------------
Public SonarOQ(1 to 2) as byte 'Sonar Queues
Public SonarIQ(1 to 25) as byte
Public datain(1 to 10) as byte 'Dump data bytes from queues here
Public erflag as boolean
Private const TX as Byte = 5 'Connected to serial output of Sonar
Private const RX as Byte = 6 'connected to input of sonar for requesting data
Sub Main()
Call OpenQueue(SonarOQ, 2)
Call OpenQueue(SonarIQ, 25)
Do
Call ClearQueue(SonarOQ) 'Clears the output queue
Call ClearQueue(SonarIQ) 'Clears the input queue
Call DefineCom3(TX, 0, bx0000_1000)
Call OpenCom(3, 9600, SonarIQ, SonarOQ)
Call PutPin(RX, 1) 'Trigger read cycle
Call Delay(0.01)
Call PutPin(RX,0)
Call GetQueue(SonarIQ, DataIn, 5, 0.1, erflag)
'Program never reaches this point with power to the sonar
Debug.Print cstr(erflag) 'Serial transmit a success?
Call Delay(0.01)
Call CloseCom(3, SonarIQ, SonarOQ)
Loop
End Sub