Home

Embedded Programming

Making a circuit board do something.

Assignment:

Browse through the data sheet for your microcontroller use your programmer to program your board to do something.

extra credit: try other programming languages and development environments

Group Assignment:

Compare the performance and development workflows for other architectures

Step #1: Datasheet Deep Dive

I was much busier this week than usual while prepping for the grand opening of the manufacturing exhibit collection and STEM park and playground I've been working on for the last two years. 

Knowing this, and since embedded programming is very new to me, I decided to keep things simple this week and program some behaviors on my existing board (the pumpkin-shaped one I designed and milled during week #5). I wanted to be able to use my button to turn my LED on and off. Simple enough, right?

Since the button and light aren’t in direct sequence in my microchip, I can’t achieve this functionality through hardware (essentially closing a circuit by pressing my switch). Instead, my button and light are both controlled by sepaarate digital pins.  This means I have to use software to link them, essentially writing code to define and control their relative behaviors.

My chip is the ATSAMD11C. Here is its explanation and pinout:

Troubleshooting Suggestions

Your LED seems to be acting erratically when you push your button.

You probably haven't debounced yet!

Check out this guide to debouncing from Arduino: https://www.arduino.cc/en/Tutorial/BuiltInExamples/Debounce

This essentially adds a few lines of code so that your board checks twice within a set period of time to confirm that the button has, indeed, been pressed (or not). It should eliminate the inconsistent results.

Your board isn't readable / doesn't register on your computer.

This is probably a hardware error.

First, does the LED light up? Are you receving power? (It's possible to receive power but not data if your USB isn't registering properly, the traces aren't making good contact, or there's an error on your board.) 

Check your board. Now check it again. Backlight it. Check it a third time, under a microscope. Have someone else check it. 

Things to look for include:  whether your components have been attached in the right direction (including pesky LEDs, which can sometimes be difficult to diagnose); whether you have any teeny tiny solder or copper bridges; cold joints, and loose solder. 

I had a pin on my header that looked soldered to the naked eye, but under a microscope wasn't quite perfet. Reflowing fixed the issue!

Also check your adapters! After debugging for a LONG time, I finally determined that my board wasn't registering because by USB adapter was faulty. Although it was feeding power through to my board and others', it wasn't sending data through. I wish I'd diagnosed that far earlier!

Helpful Resources:

  • SAM D11C Datasheet: http://academy.cba.mit.edu/classes/embedded_programming/D11C/atmel-42363-sam-d11_datasheet.pdf
  • Incredibly comprehensive micocontroller programming prrimer: https://mtm.cba.mit.edu/2021/2021-10_microcontroller-primer/fab-arduino/
  • TA Leo's Guide to "Programming an SAMD Chip with Arduino IDE": https://github.com/leomcelroy/fab-notes/blob/main/PROGRAMMING_SAMD_CHIPS_ARDUINO.md
  • TA Anthony's Guide to "How to  Debug Almost Anything" video: https://vimeo.com/manage/videos/762465540
  • Understanding Arduino Coding Language: https://www.arduino.cc/reference/en/ 
  • Alex Ellison's page from 2021:  https://fab.cba.mit.edu/classes/863.21/EECS/people/alexellison/weeks/week7.html
  • Understanding digital pins:  https://docs.arduino.cc/learn/microcontrollers/digital-pins