BasicX 24 Chip Hangs When USB-to-Serial cable unplugged then plugged back in.

Started by trevio2100 April 14, 2009

The BasicX 24 Chip Hangs When a USB-to-Serial cable is unplugged then plugged back in. I have created a simple version of code to re-create the issue.

The following basicx code will open the COM1 serial port. It will then flash a light on and off on PIN 5 while the code is looping. The code is downloaded to my BX24 Chip (hosted on a BX24 Development Station) via a USB-to-Serial cable. The code executes correctly because the light flashes on and off. When the USB-to-Serial cable is unplugged the code will continue to execute correctly (the light will continue to flash on/off). After waiting 10 seconds, I plug the USB-to-Serial cable back into my laptop the light will stop flashing. ie. the program hangs.

I would like to know if there is any way to avoid this crash other than using the WatchDog commands.
Option Explicit

Dim InputBuffer(1 To 34) As Byte ' 14-byte buffer.
Dim OutputBuffer(1 To 10) As Byte ' 1-byte buffer.

Public Sub Main()

Call OpenSerialPort(1,19200)
dim count as byte

'HACK: reset timer reset after 2 seconds of inactivity
'Call OpenWatchDog(7)

count = 0
'Call Watchdog() HACK
count = count + 1

if(count=2) then
Call PutPin(5, bxOutPutLow)
count = 0
Call PutPin(5, bxOutPutHigh)

end if

call delay(1.0)

End Sub
Sub OpenSerialPort(ByVal PortNumber As Byte, ByVal BaudRate As Long)

Call OpenQueue(InputBuffer, 34)
Call OpenQueue(OutputBuffer, 10)
Call OpenCom(PortNumber, BaudRate, InputBuffer, OutputBuffer)
End Sub

> ... when a USB-to-Serial cable is unplugged then plugged back in...

My guess is that the action simulates ATN and the processor module goes
into IDE control mode. If you have the IDE running when you do that,
try clicking the Execute icon to see if it then starts running. If so,
a fix might be to put a pullup resistor (1k - 100k) on pin 4.