Developing in C for the ATmega328: Exploring the ATmega328PB

Where I demonstrate how to use the ATmega328PB Xplained Mini from Microchip to understand how to program in Standard C.

Sources

ATmega328PB XPLAINED Mini Board Image

ATmega328PB XPLAINED Mini Board Image

Introduction

Due to its size and shape, I wasn’t a fan of this board, however, for the price, its fantastic! Why the conflicting thoughts? The good is that this board has an embedded hardware debugger which solves the controller board/debugger tool issue and it only costs $12! The bad is the board is physically large without adding extra value, thus it requires two breadboards to easily interface. All this said, I would recommend this board over any other, if you plan to do any hardware debugging.

The Atmega328PB is an enhanced version of the P version, it adds an UART, the ability to handle capacitor buttons and 2 extra timer/counters. Elliot Williams has a nice Overview of the chip.

Add to avr-gcc and avrdude

Here is a good description of how to add support for ATmega328PB to avr-gcc and avrdude. Just in case, it disappears, here is the text as well, along with my comments:

avr-gcc

  1. Download ATmega’s support pack from Microchip’s website. Simply search for “mega_DFP”, typically near the top.
  2. Unzip the relevant files. I wasn’t able to use unzip. I used Ark, a GUI file extractor and extracted the three individual files to the Desktop.
unzip -j Atmel.ATmega_DFP.x.y.zzz.atpack \
gcc/dev/atmega328pb/avr5/crtatmega328pb.o \
gcc/dev/atmega328pb/avr5/libatmega328pb.a \
include/avr/iom328pb.h

For the next two steps, I used sudo cp… to copy the files into /usr….

  1. Place the .o and .a files in /usr/avr/lib/avr5/

  2. Place the .h file in /usr/avr/include/avr/

  3. Add the following to /usr/avr/include/avr/io.h. Just below the 328P.

#elif defined (__AVR_ATmega328PB__) || defined (__AVR_ATmega328__)
#  include <avr/iom328pb.h>

All set. Ready to compile.

avrdude

Add the following to /etc/avrdude.conf, right below the definition for ATmega328P.

part parent "m328"
	id          = "m328pb";
	desc        = "ATmega328PB";
	signature   = 0x1e 0x95 0x16;

	ocdrev      = 1;
;

I added a line similar to AVR_PORT to the Makefile, this makes it easy to switch between programming environments. From the github site: You will need to add:

export AVR_PORT=/dev/ttyACM0 # replace this port name with the one you are using
export AVR_MCU=atmega328pb # replace this mcu name with the one you are using

in your .bashrc or .zshrc file. The Makefile will pick this for serial communications with the Uno and for compiling/loading to the proper processor (be sure to source or restart after editing the rc file). The Uno requires a atmega328p and the XPLAIN board has a atmega328pb.

Comments powered by Talkyard.