Arduino Mega2560 board => ZBasic

Discussion of issues related to writing ZBasic applications for targets other than ZX devices, i.e. generic targets.
Post Reply
petervanlievenoogen
Posts: 5
Joined: 11 October 2007, 2:23 AM
Location: Belgium

Arduino Mega2560 board => ZBasic

Post by petervanlievenoogen »

I have a Arduino Mega2560 board but I don't like writing in "C"
I use to work with ZX24 ZBasic.
Is it possible to use the ZBasic compiler for this board with a Generic licence?
Is there a guide line to change the bootloader to ZBasic?
Can I try this with the evaluation license?

greeting from Belgium :-)
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Arduino Mega2560 board => ZBasic

Post by dkinzer »

petervanlievenoogen wrote:Is it possible to use the ZBasic compiler for [the Arduino Mega2560] board with a Generic licence?
Yes, it is. The Arduino Mega has a 6-pin IPS connector like many other Arduino boards. You can use this connector to program the bootloader or you can use it to program the application if you don't want to use a bootloader.
petervanlievenoogen wrote:Is there a guide line to change the bootloader to ZBasic?
You can find a lot of information on the Internet about how to program a bootloader into an Arduino. You will need an In-System Programmer (ISP) of some type to do this. One option is to use another Arduino for that purpose as described at the page below:
http://arduino.cc/en/Tutorial/ArduinoISP
petervanlievenoogen wrote:Can I try this with the evaluation license?
Yes. The evaluation license is identical to the purchased license except that it is time-limited.
- Don Kinzer
petervanlievenoogen
Posts: 5
Joined: 11 October 2007, 2:23 AM
Location: Belgium

Post by petervanlievenoogen »

Thank you dkinzer,

I will try it on my board.

regards
Peter
cerickson
Posts: 45
Joined: 20 May 2008, 15:50 PM
Location: Waikoloa Village, HI, USA
Contact:

Re: Arduino Mega2560 board => ZBasic

Post by cerickson »

dkinzer wrote:
petervanlievenoogen wrote:Is it possible to use the ZBasic compiler for [the Arduino Mega2560] board with a Generic licence?
Yes, it is. The Arduino Mega has a 6-pin IPS connector like many other Arduino boards. You can use this connector to program the bootloader or you can use it to program the application if you don't want to use a bootloader.
petervanlievenoogen wrote:Is there a guide line to change the bootloader to ZBasic?
You can find a lot of information on the Internet about how to program a bootloader into an Arduino. You will need an In-System Programmer (ISP) of some type to do this. One option is to use another Arduino for that purpose as described at the page below:
http://arduino.cc/en/Tutorial/ArduinoISP
petervanlievenoogen wrote:Can I try this with the evaluation license?
Yes. The evaluation license is identical to the purchased license except that it is time-limited.
Are there any changes to the Arduino Mega 2560 board that are required to convert it to Zbasic?

Are there any special compiler directives required to run Zbasic on the Arduino Mega 2560?

Are there any special limitations or considerations involved with running Zbasic on an Arduino Mega 2560?

I have already purchased the Zbasic Generic Target License.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

Sorry for overlooking your questions. Did you get it going or do you still need some hints?
- Don Kinzer
cerickson
Posts: 45
Joined: 20 May 2008, 15:50 PM
Location: Waikoloa Village, HI, USA
Contact:

Post by cerickson »

dkinzer wrote:Sorry for overlooking your questions. Did you get it going or do you still need some hints?
I still have my three questions.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Arduino Mega2560 board => ZBasic

Post by dkinzer »

cerickson wrote:Are there any changes to the Arduino Mega 2560 board that are required to convert it to Zbasic?
No modifications to the board itself are required but you may need to or want to change the "fuse" settings. See AN-103 - Preparing ZBasic Generic Target Devices for more details. If you're going to use a ZBasic-compatible bootloader (see discussion further below), I would recommend these fuse settings: ext=0xfd, hi=0xd6, lo=0xd7. If you're going to program your app into the device using an ISP, the Arduino Mega 2560 fuse settings of ext=0xfd, hi=0xd8, lo=0xff are probably fine.
cerickson wrote:Are there any special compiler directives required to run Zbasic on the Arduino Mega 2560?
Yes. From the perspective of ZBasic, the Arduino Mega 2560 is just a generic ATmega2560 so the information in Chapter 5 of the ZBasic Language Reference Manual applies.

In particular, you need to specify several device parameters. Most of them derive from the main clock frequency - 16MHz on the Arduino Mega 2560. The set of device parameters below will probably work fine, just add them to the top of the primary .bas file (the one with the Main() in it). You can also specify device parameters in the .pjt file but the form is slightly different (see the discussion of the --device-parameter option).

Code: Select all

Option DeviceParameter package "TQFP-100"
Option DeviceParameter clockFrequency 16000000
Option DeviceParameter rtcFrequency 500
Option DeviceParameter rtcScale 1
Option DeviceParameter swUartDivisor 8
Option DeviceParameter swUartMinSpeed 300
Option DeviceParameter swUartMaxSpeed 19200
Option DeviceParameter swUartBaseSpeed 2400
Option DeviceParameter timerSpeed1Divisor 1
Option DeviceParameter timerSpeed2Divisor 8
This set of device parameters was generated using the "Target Options" dialog, available via the Options|Target Options menu item after you've selected the target generic device. See Section 9.6 Setting Target Options for more information.
cerickson wrote:Are there any special limitations or considerations involved with running Zbasic on an Arduino Mega 2560?
The only limitations are those imposed by the device itself and its main clock frequency.

There is a question of how you're going to get the application code into the Arduino Mega 2560 device. One option is to use an AVR-compatible In-System-Programmer (ISP) device like the Atmel ATAVRISP2 (unfortunately, no longer manufactured) or equivalent. You can also use another Arduino with a special AVR ISP sketch to program AVR devices. A Google search with suitable keywords will return useful links.

Another alternative is to first install a ZBasic compatible bootloader. Source code and a build script for such a bootloader is provided in the zboot directory of the ZBasic installation directory. Of course, you need an ISP device to put the bootloader on the AVR (see the preceding paragraph) but after that you can download your application to the device in a manner similar to that used for ZX devices. If you do install a ZBasic-compatible bootloader you'll need one additional device parameter:

Code: Select all

Option DeviceParameter ZBasicBootloader true
- Don Kinzer
cerickson
Posts: 45
Joined: 20 May 2008, 15:50 PM
Location: Waikoloa Village, HI, USA
Contact:

Post by cerickson »

Thanks!
kurakaira
Posts: 77
Joined: 21 March 2007, 1:21 AM
Location: Finland

Generic Mega2560

Post by kurakaira »

Works great ,,, as long as You keep below ConsoleSpeed of 57600 ... 115200 does not work for my boards , is it a generic target issue or something i have overlooked ?
I have not tested if this affects other UART's on the Mega2560 . . .

Code: Select all

Option TargetDevice ATmega2560
Option DeviceParameter clockFrequency 16000000
Option DeviceParameter rtcFrequency 500
Option DeviceParameter rtcScale 1
Option DeviceParameter swUartDivisor 8
Option DeviceParameter swUartMinSpeed 300
Option DeviceParameter swUartMaxSpeed 19200
Option DeviceParameter swUartBaseSpeed 2400
Option DeviceParameter timerSpeed1Divisor 1
Option DeviceParameter timerSpeed2Divisor 8
Option DeviceParameter ZBasicBootloader True

Option ConsoleSpeed 115200  ' 57600 works fine
Option RTC on
Option Signon on
Option TxQueueSize 100
Option RxQueueSize 40
Option Console Com1

Const Led as byte = B.7

Sub Main()

Debug.Print "Hello From 2560"

Do
Debug.Print "Hello ."
Call PutPin(Led, 1)
Call Delay(1.0)
Call PutPin(Led, 0)
Debug.Print "It Really Works :)"
Call Delay(0.5)
Loop
End Sub
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Generic Mega2560

Post by dkinzer »

kurakaira wrote:115200 does not work for my boards , is it a generic target issue or something i have overlooked ?
At 16MHz, the mega2560 (and all other mega devices) cannot produce 115.2K baud accurately enough - the actual baud rate is about 2.1% off. That likely explains the problem you're having. Generally speaking, you need a baud rate significantly less than 2% off in order to communicate effectively.

If you use the Target Options dialog you can see what the error is for the various standard baud rates given a particular CPU frequency.
- Don Kinzer
Post Reply