Developing in C on the AVR ATmega328P

3 minute read

Introduction

While the Arduino tool set, (both the Arduino IDE and Arduino software framework) are outstanding for quickly developing a working prototype, they do so with a combination of a graphical-user-interface (GUI), the C++ language and Arduino-only classes. This in itself, isn’t a problem, one can be quite efficient and productive using this approach.

This approach is an issue if you are at a university or job which expects a standards-based C language proficiency. It is also an issue, if your class or job, requires understanding how to use command-line-interface (CLI)-based tools. The C language, and not C++, is the basis of a significant number of embedded systems development.

This set of entries are written to help you learn how develop embedded ANSI C programs for the AVR family and specifically the ATmega328P (Arduino Uno R3). While doing so, it will also use a set of tools which can serve as the basis of an intermediate-level software programmer.

Pages of Significant Interest

Course Material

Developing in C for the ATmega328P

Beginning tutorial using Labs_10C_Class content to help someone replace the Arduino C++ software framework with a Standard C approach.

A broader-based approach using the AVR_C repository is recommended for a detailed approach to learning C for the AVR-family of microcontrollers.

All entries below begin with “Developing in C for the ATmega328P: “

  1. Getting Started
  2. Setup Introduction
    1. Raspberry Pi and VS Code Setup (Best Method)
    2. Linux Setup (Advanced)
    3. macOS Setup (Advanced)
    4. Windows/WSL Setup (Deprecated)
    5. Windows 10 Setup (Advanced)
  3. Using git
  4. Edit
  5. Build
  6. Upload
  7. AVR_C Library Functions
  8. Using a Serial Monitor
  9. Functions - Serial input/output
  10. Function - analogWrite()
  11. Functions - Serial input/output
  12. Function - digitalWrite()
  13. Function - pinMode()
  14. Function - digitalRead()
  15. Struct - buttons[]
  16. Function - analogRead()
  17. Hints
  18. Mapping Values
  19. Using Data Types and Math
  20. Marking Time and Measuring Time
  21. User Functions
  22. Multi-tasking the Arduino - Part 1
  23. Function - tone()
  24. Using PROGMEM
  25. structures
  26. Code vs. Cost
  27. Pointers
  28. Servos
  29. I/O Ports
  30. Make, Makefile and env.make
  31. Better Serial Input
  32. Using the GNU Linker to Enhance printf()
  33. Serial Applications for Embedded Development
  34. Using the GNU Linker to Enhance printf()
  35. Better Serial Input
  36. A Second Serial Port
  37. Raspberry Pi and VS Code Setup Part 1
  38. Raspberry Pi and VS Code Setup Part 2
  39. Raspberry Pi and VS Code Setup Part 3
  40. Buffer Overflow

AVR Datasheet Notes

Technical tutorial using specific capabilities of the ATmega328P chip. This content is intended to help somone understand how to use the datasheet to implement a specific function using the ATmega328P.

  1. AVR Datasheet Note: Blink
  2. AVR Datasheet Note: PWM
  3. AVR Datasheet Note: analogWrite

Programming Examples

Intermediate tutorials focused on using the AVR-gcc library or examples from the library.

  1. Comparison of Languages
  2. AVR-gcc Note: Simple Project
  3. Using the Standard C Framework
  4. Writing Multitasking Programs
  5. Using Makefiles to Automate Development

Hardware Debugging

Technical tutorials on using Bloom, gdb, debugWIRE, a hardware debugger such as the Microchip SNAP or the one on the ATmega328PB Xplained Mini board to debug programs on the microcontroller.

  1. Hardware Debug: Using gdb to debug
  2. Hardware Debug: Setup Bloom and gdb to Debug
  3. Hardware Debug: Examples of Bloom with gdb to Debug
  4. Hardware Debug: Hints on Solving Issues Bloom and gdb
  5. Hardware Debug: Exploring the ATmega328PB Xplained Mini
  6. Hardware Debug: Command and Configuration Reference for Bloom and gdb

Reference Content on C

Reference books which are important for understanding C

  1. The C Programming Language Kernighan and Ritchie - available in PDF and paper copy
  2. Barr Group: Embedded C Coding Standard
  3. SEI CERT C Coding Standard
  4. Arduino Resources page
  5. comp.lang.c FAQ

Comments powered by Talkyard.