HOME

 

Make: AVR Programming Lab Setup

 

Pix

(Click to enlarge)

Overview

Add'l Info

This is the lab configuration as described in the book Make: AVR Programming.

The differences between the book and my lab include:

- breadboard microcontroller ATmega328P is used instead of older ATmega168 (the book was updated in 2015)

- I'm not using the internal 1MHz or 8MHz clocks because the current Arduino IDE v1.8.13 no longer supports speed selection for the Arduino Uno core. Instead I'm using an external 16MHz oscillator/crystal so that means giving up pins 9 and 10 which are the last two pins, PB6 and PB7, of PORTB. You have to slightly change some of the code you write so that it uses "0b00111111" instead of "0b11111111" to refer to just the first 6 bits/pins and not all 8; easy peasy

 

The book's author recommends a USB/FTDI device for Chapter 5. The one I use can be found here so you can communicate to the Serial Monitor on the breadboard ATmega328P from your PC; your Arduino Uno has been temporarily downgraded to a chip programmer so the Serial Monitor will not work. Order a couple of the devices... trust me, you'll be glad you did.

The Arduino Uno has a built-in USB-to-RS232 serial interface so you can both upload sketches and run Serial Monitor as a feedback/troubleshooting tool.

 

Your breadboard ATmega328P does not have a separate chip for such, so we use a USB/FTDI device to communicate from the PC's serial communication program (I like Tera Term v4.1) to the ATmega328P microcontroller.

As per the Make book, you connect the USB/FTDI TX port to the ATmega328P's RX port, and then the former's RX port to the latter's TX port. 5v and GND help, too.

 

The USB/FTDI will try to power both your Arduino UNO and your breadboard ATmega328P in addition to itself. It will do so for a while before it burns out. (Ask anyone that has worked with serial boards.) Check periodically that both USB cables (USB/FTDI and Uno) are plugged into your USB hub.

Once you have loaded the ArduinoISP sketch (File|Examples|11.ArduinoISP|ArduinoISP), set the board to "Arduino Uno" under "Tools|Board", and set the "Tools|Programmer" setting to the default of "AVRISP mkII", you can upload the "ArduinoISP.ino" sketch to the Uno. Afterwards you will need to change the Programmer to "Arduino as ISP" to burn any sketches onto the ATmega328P on the breadboard via the Uno acting as a programmer.

Note that you will need to insert a 10uF electrolytic cap into GND and RESET on the UNO, with the negative side of the cap pointed at GND. This device is only inserted after the Uno has been programmed as ISP Programmer. Even though we will be using WinAVR to flash the ATmega328P on the breadboard via the Uno instead of the Arduino IDE, the Uno still needs to remain in the ISP Programmer mode with the cap installed.

You will notice a gray jumper and an orange jumper connecting GND and 5v between the Uno and your lab breadboard system. This will allow your Uno to power the breadboard circuits.

In the adjacent photo you can see the ATmega328P with its 16MHz oscillator/crystal on pins 9 & 10. At the top of the breadboard are 8 LED/resistor combos, of which only 6 can be used on PORTB because we're using an external crystal/oscillator.

To the right you can see a momentary tactile switch.

In the bottom center is a buzzer board instead of a small speaker I'm using for the Chapter 5 serialOrgan.c lab.

Breadboards and jumper wires. Here are my recommendations: http://zed80.com/Z80-RETRO/Resources/Parts/Z80_Parts.htm

 

The adjacent pinout image shows the 6 or 8 pins of PORTB, 6 or 7 pins of PORTC, and the 8 pins of PORTD.

PORTB pins 6 and 7 are unavailable on the ATmega328P if you are using a 16MHz crystal in those locations.

 

 

The adjacent pinout image shows the additional functions of the ATmega328P that have been exploited by the Arduino IDE.

The Legend in the upper left corner can be very helpful.

PORTD is the only port that contains 8 usable pins except that pins 2 and 3 are used by the USB/FTDI device to communicate with the ATmega328P, hence the reason the book's author went with PORTB.

 

 

The adjacent diagram shows the 8 pins that comprise PORTD, the DDRD data direction register that defines the pins as input (0) or output (1), and the individual PINs that can be read. Setting a binary 1 on every pin in PORTx will turn on the Pull-up resistor function (for every pin) which will stop the pins from floating between GND and VCC. This is important if they are to be used as inputs. See page 45 of Get Going with AVR.

All pins example: "PORTD = 11111111;"  or  "PORTD = 0xFF;".

One pin example: "PORTB |= (1<<2);" for pin PB2.

NEW                    OLD

   

Serial port USART0 block diagram for Chapter 5 Serial I/O.

The USART has to be initialized before any communication can take place. The initialization process normally

consists of setting the baud rate, setting frame format and enabling the Transmitter and Receiver. See page 185 of the new (2020) datasheet.

 

Page 179/180 of 2020 ATmega328PU datasheet

Page 144 of 2015 ATmega328P datasheet

Tag: Make: AVR Programming

HOME