I've been having a somewhat similar problem, except, I'm running with the generic license on a AtMega328P and using just debug.print... it is a slightly modified version of Don's "Hello, world" example he posted to me 14 December 2008 in the zx-1281 topic.
While trying to understand my problem, I found that with "SignOn ON" and the CallTask cmdTask, taskStack commented out, getDeviceID() returns 0f0f0f0f. Running the Calltask, getDeviceID() returns 1e950f (correct device). When SignOn is OFF, getDeviceID() workes correctly with or without the Calltask. I also found at times, when SignOn had never been specified (on a new device), letting CallTask (ZXCmdMode) run, would not allow the program to start from power up. I had to download the application to restart. I tried with v4.1.7 compiler, Signon displays ZBasic v4.1.3 ..
Also, verified the ZB_REQUEST_SYM and StatusCom(!) do loop mentioned previously had no effect.
It appears SignOn Off solves all the issues.
Regards,
..jay
Modified code...
Code: Select all
Option TargetDevice ATMega328P
Option DeviceParameter package "PDIP-28"
Option DeviceParameter clockFrequency 14745600
Option ConsoleSpeed 57600
Option DeviceParameter rtcFrequency 512
Option DeviceParameter rtcScale 2
Option DeviceParameter swUartDivisor 64
Option DeviceParameter swUartMinSpeed 300
Option DeviceParameter swUartMaxSpeed 19200
Option DeviceParameter swUartBaseSpeed 0
Option DeviceParameter timerSpeed1Divisor 1
Option DeviceParameter timerSpeed2Divisor 8
Option DeviceParameter ZBasicBootloader true
Option SignOn Off
#define RedLed = D.2
#define GreenLed = D.3
Private msg as StringVectorData({ " says...", " Hello, world" })
Private device as String
Private Const cmdChar as Byte = &H04
Private Const stackSize as Integer = 200
Private taskStack(1 to stackSize) as Byte
Sub Main()
Dim j as Integer
' launch the ATN detection task
CallTask cmdTask, taskStack
' get the device identification string
device = getDeviceID()
' loop forever displaying the hello world message
j = 1
Do
Call Hello(j)
Loop
End Sub
'
'' Hello
'
' This subroutine displays one of two strings depending on the
' passed index (of which only the least significant bit is used).
'
Private Sub Hello(ByRef idx as Integer)
' advance the string index and limit its value
idx = (idx + 1) And 1
' display the indexed string, for string 0, add the device identifier prefix
If (idx = 0) Then
Debug.Print device;
End if
Debug.Print msg(idx + 1)
#if defined(RedLED) And defined(GreenLED)
' for devices with LEDs, flash the red and green LEDs for a half second each
Call PutPin(RedLED, zxOutputLow)
Call Delay(0.25)
Call PutPin(RedLED, zxOutputHigh)
Call PutPin(GreenLED, zxOutputLow)
Call Delay(0.25)
Call PutPin(GreenLED, zxOutputHigh)
#else
' for devices without LEDs, simply delay for a second
Call Delay(1.0)
#endif
End Sub
'
'' getDeviceID
'
' Retrieve the device identifer and return it as a string.
'
Private Function getDeviceID() as String
Dim idLen as Integer
Dim i as Integer
Dim id(1 to 10) as Byte
' note that the 'id' array will be null terminated
Call System.DeviceID(id)
' determine the length of the identification string
idLen = 0
For i = 1 to UBound(id)
If (id(i) = 0) Then
Exit For
End If
idLen = idLen + 1
Next i
' create a string containing the identification string
getDeviceID = MakeString(id.DataAddress, idLen)
End Function
'
'' cmdTask
'
' The sole purpose of this task is to check the input queue for the ATN
' character and, when found, invoke the ZX command mode.
'
Sub cmdTask()
Do
If (StatusQueue(CByteArray(Register.RxQueue))) Then
Dim c as Byte
Call GetQueue(CByteArray(Register.RxQueue), c, 1)
If (c = cmdChar) Then
Call ZXCmdMode() '
End If
End If
Call Sleep(0)
Loop
End Sub