Learning C Programming for AVR Resources

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What books / references have you found the most useful for learning C, or as reference book for C (my interest in C is solely for embedded applications like AVR)?

-I'm about 400-500 hours into learning how to program AVRs. I'm a EE but until recently my practice has been in a totally different field. Nothing here is conceptually difficult, its mostly my ability to memorize syntax, registers, and tracking down functions (that were included by 3 layers down in header files) that is slowing me down. 

-I've found AVR Programming by Elliot Williams a good starter, but it doesn't teach much more C than is strictly needed to demo the AVR features. 
-I've also been working through Effective C by Robert Seacord. It's very formal, with very few examples, and is generally not focused on embedded. 

 

With no updates in almost 5 years, is AVR-LIBC dead? 

What are you using as an AVR library? I've pretty much been using avr-gcc, make, avrdude, but see the lack of work on these projects as a serious red flag that I would possibly be better off learning other tools that support the latest products. I am considering using newer AVRs that don't have header files in AVR-LIBC.

 

For what it matters I'm operating in a Windows environment.

 

Appreciate your thoughts. 

 

-Zach

Zach

Last Edited: Wed. Nov 25, 2020 - 12:00 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to AVRFreaks. Unless you are allergic to IDEs then download and install AVR Studio 7 (Now Microchip Studio), it has all that you need for programming and debugging apart from the actual hardware debugger such as Atmel ICE. (Link here https://www.avrfreaks.net/forum/...)

 

As far as books are concerned THE BOOK recommended by C expert is the original "C Programming Language Ansi C  by K and R" (Kernigham and Ritchie)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Tue. Nov 24, 2020 - 03:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1. Programming- regardless of language, embedded etc is a specific skill. Knowing how to approach a programming problem and having the tools to decompose and solve the problem is learning in itself.

2. C language. C is the same whether it is on an embedded platform or on a PC. Again, a specific skill.

3. Embedded programming. Having  hardware background helps, but understanding the interface between the real world and the microprocessor is one skill. Understanding the constraints of an embedded platform is another.

 

If avr-libc is dead, what has replaced it?? It was my understanding it is still alive and well.

 

For me, the AVR specific stuff is knowing how to use the IDE and hardware specifics of the devices. Similarly, I am very familiar with many ARM based devices, but every manufacturer's chips are different. The ARM part of it is minimal.

 

For an IDE, I use PlatformIO. So whether I use an AVR, ARM,RISC-V or Tensilica processor core, the IDE is the same. The compilers are all gcc. Hardware wise they are all very different.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's my list - it includes links to resources here!

 

https://blog.antronics.co.uk/201...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1


zacharythomas wrote:
With no updates in almost 5 years, is AVR-LIBC dead? 
I'm not seeing where you see that??

 

http://svn.savannah.gnu.org/view...

 

But anyway that master branch at savannah is effectively not the "main" master branch these days. That is held by Microchip where most of the "up to date" work is now done to add support for new AVR models. So a view of recent AVR-LibC activity is much better seen by looking at the activity in the Pack Manager of Studio 7.

 

On the general topic of learning C on AVR I think you are better looking at (1) C programming and (2) programming AVRs as two completely separate entities. AVRs (or any embedded micro) is not a good place to "learn C". Do that separate from micros. If you learn the basics of C programming PC programs you will have much more advanced debug tools and much quicker feedback on what happens. Suppose you want to explore the use of ^ (the XOR operator) then nothing is quicker or more immediate than:

 

 

That took me 20 seconds. Sure it was "raw", I guess normally you'd at least use an editor to create the .c file but I now know that 37^53 is 16 (it's perhaps easier if you look at that as 0b100101 ^ 0b110101 = 0b001000 !). To have got to the same place (see 16 output as the result somewhere) on an AVR would be a whole lot more work (though I guess if you used Arduino you could have done a single Serial.println()?).

 

While some people would say it's not a great tutorial a must have C book is "The C programming language (2nd edition)" by Kerninghan and Ritchie. You can learn most of the basics of C from that book.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
I think you are better looking at (1) C programming and (2) programming AVRs as two completely separate entities. AVRs (or any embedded micro) is not a good place to "learn C". Do that separate from micros.

Absolutely!

 

I think that may have been mentioned just once or twice here before ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
download and install AVR Studio 7 (Now Microchip Studio), it has all that you need for programming and debugging apart from the actual hardware debugger such as Atmel ICE

Absolutely!

 

And devboards complete with hardware debugger are cheap & widely available.

 

zacharythomas wrote:
What are you using as an AVR library?

What do you feel is missing from avr-libc ?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here are great resources: 

Fundamentals of the C Programming Language: https://microchipdeveloper.com/t...

AVR1000b: Getting Started with Writing C-Code for AVR® MCUs (microchip.com)

 

Best regards,
Amund Aune
Applications Engineer @ Microchip Norway
(The postings on this site are my own and don’t necessarily represent Microchip’s positions, strategies, or opinions. For official Microchip Support, please visit https://microchipsupport.force.com/s/)

Last Edited: Tue. Nov 24, 2020 - 02:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zacharythomas wrote:
What books / references have you found the most useful for learning C,
The C textbook selected by the instructor (continuing education, not university, private corporate context) that I've dog-eared and post-it'd though the binding is still in good shape (softcover)

zacharythomas wrote:
 or as reference book for C 
A C reference cited in that C textbook.

zacharythomas wrote:
(my interest in C is solely for embedded applications like AVR)?
Am curious about the replies to that as my context was '99 and embedded Intel 486 (bootstrap) though have since moved to AVR and more.

The book I selected for that is well dated (x86), has moved on (Arm), though is well liked.

zacharythomas wrote:
I'm a EE but until recently my practice has been in a totally different field.
Likewise (education in EE, vocation otherwise)

zacharythomas wrote:
... and tracking down functions (that were included by 3 layers down in header files) that is slowing me down.
Find an IDE you like; some in embedded systems design prefer an editor then attach to that editor or simply operate a shell.

Visual Studio is a juggernaut though less so in embedded; the choice of Visual Studio Isolated Shell by the ones at Atmel did make Atmel Studio nee Microchip Studio stand out from the crowd.

May the ones at Microchip create a Microchip Studio 8 as a Visual Studio extension.

zacharythomas wrote:
I've pretty much been using avr-gcc, make, avrdude, but see the lack of work on these projects as a serious red flag that I would possibly be better off learning other tools that support the latest products.
A concern is FSF AVR GCC is very near a decision point for v11 approximate to northern Spring '21.

Microchip AVR GCC is alive in two forms (GPLv2 with the GCC runtime exception, proprietary in MPLAB XC8 v2 for AVR) though dated (v5, current is v10)

AVRDUDE development is proceeding though releases are infrequent; in-lieu of releases, build AVRDUDE or obtain AVRDUDE in a package.

zacharythomas wrote:
For what it matters I'm operating in a Windows environment.
Been stated that Windows has ten years of life left; Windows 10X on single screen is due northern Spring '21.

 


My copy :

C: A Software Engineering Approach | Peter A. Darnell | Springer

updated :

C A Software Engineering Approach | Peter A. Darnell | Springer

 

Harbison & Steele, C: A Reference Manual, 5th Edition | Pearson

 

Programming Embedded Systems in C and C++ | Barr Group

 

UEStudio is a powerful IDE combined with UltraEdit text editor

due to

UltraEdit / UltraStudio as an alternative to MPLAB-X? | Microchip

Arduino - Visual Studio Marketplace (Visual Studio Code extension)

AVR in VS Code | AVR Freaks

AVR Studio On Mac & Linux? | AVR Freaks

 

avr-gcc and avr-g++ are deprecated now. | AVR Freaks

https://lists.nongnu.org/archive/html/avrdude-dev/

Debian Package Tracker - avrdude

Chocolatey Software | AVR Downloader/UploaDEr 6.3 (AVRDUDE in a Windows package)

 

https://www.avrfreaks.net/forum/another-win10-rant-frustration-part-3?page=3#comment-2950626

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for all the feedback. Great to see that there is so much activity and interest in this community. I hope I can become a contributor in time. 

 

For some context, I prototyped my application with an Arduino Uno (using sketches) and a custom PCB "shield". It worked awesome, but to make it a product is going to require a lot more engineering... i.e., single PCB, support for BACNET (which has an open source C library); and I will need a real UI (used a MATLAB app for monitoring and control commands for the prototype). I'm not opposed to design consultants, but at this point I feel I need to fully understand the product so I can troubleshoot installations, understand failure modes, recognize opportunities for improvement, make cost tradeoffs and know how to warranty the product.

 

Learning

 

  • Per your suggestions, I've ordered a copy of Kerninghan and Ritchi. (I used this book 20 years ago for an undergraduate course programming PICs)
  • I will also check out the microchip developer site resources.
  • I will also check out some of the resources awneil suggests. 

 

AVR-LIBC

 

  • I got the impression AVR-LIBC might be dead from:
  • Per clawson it seems like the "right" place to look is the "Pack Manager" in Microchip Studio. Does that include documentation? I'm using the 2016 documentation, which is not great. 

 

Toolchain

  • I'm not opposed to an IDE or changing tool chain.
  • My toolchain/tools have been Notepad++ / MAKE / AVR-GCC / AVRDUDE / (ATMEL ICE or USBTINY) with AVR-LIBC.
    • It sounds like a toolchain based on MC Studio is a better place to work from. Is it self contained, or do I need *outside* tools like I currently use a whole series of (make, avrdude, etc.) 
  •  Per your suggestions, I will update my Atmel Studio 7 to Microchip Studio 7 and start playing around with the tool chain that that implies. (I am not against IDEs). 

 

Again, appreciate your thoughts. 

 

-Zach

 

Zach

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

zacharythomas wrote:
and I will need a real UI (used a MATLAB app for monitoring and control commands for the prototype).
Some have an operator interface on LabVIEW.

Could consider a web app for the operator's interface; web apps are new to Windows 10X.

zacharythomas wrote:
Per clawson it seems like the "right" place to look is the "Pack Manager" in Microchip Studio. Does that include documentation?
AVR Libc

zacharythomas wrote:
Is it self contained, ...
Yes

zacharythomas wrote:
... or do I need *outside* tools like I currently use a whole series of (make, avrdude, etc.)
No though Microchip Studio does have interfaces such that external tools can interoperate (atprogram.exe is an alternative to AVRDUDE on Windows, AVR GDB proxy in atbackend.exe, MSBuild via the front-end in-lieu of make)

 


Labview Now Free! (For non-profit use) | AVR Freaks

Efficient web server technology for resource-constrained microcontrollers - Embedded.com (WebSocket)

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gchapman wrote:
Atmel Studio nee Microchip Studio

You have that backwards - it's Microchip Studio née Atmel Studio (previously known as AVR Studio)

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

zacharythomas wrote:
tracking down functions (that were included by 3 layers down in header files) 

This is a place where a decent IDE will really help - 'Go To Definition' becomes  just a click of a button!

 

smiley

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

zacharythomas wrote:
Does that include documentation?
The packs are ONLY device support files (effectively one ioXXX.h for each new AVR supported). AVR-LibC is not really a "C lib" in the sense of supporting things like timers, ADC, UART, etc (there's a few scant examples, that's all).It's about providing core services for "non-peripheral" parts of each AVR like the sleep system, the EEPROM and so on. As most of that stuff (until very recently) has not really changed in years there's no real reason the majority of AVR-LibC should have changed in 4-5 years. The one thing that does change from month to month is that Microchip keep releasing new AVRs so there does need to be a header for each one to define all the register names and bits. But don't expect there to be any code that "understands" and actually operates those bits - that comes from other library sources. As the contents of the AVR-LibC manual (https://www.nongnu.org/avr-libc/...) doesn't really consider the device headers (well only in the most sweeping sense) then there's no reason the manual (or the lib) needs to be have been updated. One could describe the core of AVR-LibC as "stable".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zacharythomas wrote:
Great to see that there is so much activity and interest in this community. I hope I can become a contributor in time. 

Yes it is active! Drop in often and get to know the regulars, and when you feel comfortable, poke in an opinion or fact now and then, it will take a while to earn your 100k tag like Cliffs!

Welcome!

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"