Migration from AVR to Arduino

I'm pretty new to Arduino, but I have been 'playing' with AVR chips for nearly 20 years.

Much of my hobby was the challenge of programming in AVR Assembler rather than C, but I've reached a point in other hobbies which need quick, simple embedded electronics and Arduino offers a a quick, simple solution. I have quite a lot of projects, some of which would be useful to port to Arduino hardware (e.g. a GOTO mount controller that should work well with a 3D printer shield on a UNO).

I have two questions...

First, I assume that if I use the SPI port on an Arduino I can (mostly) treat it as a raw AVR and program it with code I already have using my AVRISP. Is there a summary somewhere of any forbidden pins/functions/pre-wired connections I should check before doing this?

Second, I've written some fairly involved code such as implementing the BBC BASIC VDU codes for control of a number of TFT displays. These allow advanced graphics and have the advantage I'm experienced in using them! As these are in assembler rather than C, is there a guide to incorporating chunks of assembler in Arduino code?

Welcome to the wonderful world of Arduino. It has a few nasty sharp edges here and there, but overall it is a lot of fun.

You can find everything online, the code that Arduino runs before setup() and so on.
Here is the 'main' entrance: ArduinoCore-avr/main.cpp at master · arduino/ArduinoCore-avr · GitHub.

Timer0 is set to a 1ms interrupt for the millis() function. That is the only thing to stay away from. When you use Timer0 for other things, then many Arduino functions will not work properly anymore.

The other timers and maybe the analog input are initialized. But you may use them anyway. When you change something, the Arduino functions might not work normally after that, but if you use only your own code, that is okay.

As far as I know, you can do with the SPI whatever you want.

There are no forbidden pins.
The bootloader and the serial monitor use pin 0 and 1 (for a Arduino Uno). Try to avoid those. However, if you use a programmer to burn the sketch into the AVR chip (using the ICSP header), then you can still use those pins.

The Neopixel library contains assembly for high speed precise timing: Adafruit_NeoPixel/Adafruit_NeoPixel.cpp at master · adafruit/Adafruit_NeoPixel · GitHub.

Can you adapt your code to include it in C++ ?

You can change the "make" process and link assembly into your project, but I think that is not a good idea. Things have been changed and improved over the years, so it might suddenly change.

Nick Gammon has good tutorials. You might like this one: https://www.gammon.com.au/interrupts.

When you are using a professional IDE, then you can use the Atmel Studio for Arduino or the Eclipse IDE with Sloeber extension or UECIDE. I assume that those will make it possible to include assembly. I have decided to stay with the Arduino IDE to avoid that I have to solve compatibility problems.

The Arduino IDE supports assembly. Just add the assembly files to the sketch folder. The must have the .S (make sure it's upper case) extension to be recognized. When you open the sketch in the Arduino IDE, you'll see the .S files as tabs. If you want to add assembly files to your sketch from the Arduino IDE, you can add existing files using Sketch > Add File... or create a new file by clicking the downward pointing triangle button on the right side of the tab bar, then "New Tab".

Here's a forum topic talking about a simple blink sketch using assembly:
https://forum.arduino.cc/index.php?topic=413151.0

You can also add inline assembly to the .ino files of your sketch with asm():

You can do the same in Arduino libraries as well as in sketches.

pert:
The Arduino IDE supports assembly. Just add the assembly files to the sketch folder.

That's very cool. I didn't know that. Learned something new 8)

That's really useful, many thanks.

I am used to Atmel Studio, but I didn't realise I coudl use it directly for Arduino.

I'll study those links on using inline assembler.

I have various mono and colour displays in my parts bin with drivers written for them, so it would be great to use them with Arduino projects.

That said I've already discovered using the libarary 16x2 driver is less fuss than trying to port over mine.

Bit different for an obscure QVGA TFT with graphics though...