Close

Nearing the end of my AVR adventures

ken-yapKen Yap wrote 3 days ago • 2 min read • Like

AVR at the bare silicon level using my OOS (Old Old Stock) that is, because I still have a couple of Arduinos, but programming with them will be through the Arduino HAL which hides the low-level hardware stuff.

I found another AVR MCU in my junk box, and it's an ATMEGA163L. I was curious what modifications I would have to make to my build to compile code for it. Turns out, not much. Here's the section my Makefile which looks at the command line argument MCU=ATMEGA163 to choose different settings for the build.

MCU?=AT90S8515
CSRCS=clock.c ds3231.c i2c.c
BUILDFLAGS=-DX8_000_000 -DLOWON -DSIXSEGMENT -DRAISEDZERO # -DDS3231

ifeq "$(MCU)" "AT90S8515"
CSRCS+=at90s8515.c
BUILDFLAGS+=-DAT90S8515
# CRTs are inside the avr-gcc distribution
CRT=crtat90s8515.o
MCUOPT=-mmcu=avr2
endif

ifeq "$(MCU)" "ATMEGA163"
CSRCS+=atmega163.c
BUILDFLAGS+=-DATMEGA163
# CRTs are inside the avr-gcc distribution
CRT=crtatmega163.o
MCUOPT=-mmcu=avr5
endif

The MCU?=AT90S8515 establishes the default to be overriden by a command line assignment to MCU. The next two lines set the default source file list and BUILDFLAGS. As you can see the only things that change are the CRT startup file, a define that affects the source compiled, and the MCU architecture requested of the avr-gcc compiler. Fortunately the on-chip features I used are present in both MCUs. Atmel (now Microchip) did a decent job of family compatibility.

The 163 is the forerunner of the 164 which fixed some silicon bugs, hence not recommended for new designs. The L suffix means I have to change the declared crystal frequency to 4 MHz later. Unfortunately the 163/164 while still available in the DIP-40 package, have a different pinout from the AT90S8515. I'm loath to have 5 boards made only to use 1, or pay money for some NOS ATMEGA164s, so I might wire this up on perfboard (ugh!). I'll only need a 7805 regulator, a crystal and its load capacitors, a couple of bypass caps, and the reset RC circuit. I may live to regret using perfboard ☹️. We shall see.

Like

Discussions