Skip to content

8a. Embedded Programming

This week, we have been asked to: 1. individually read the data sheed for our microcontroller; 2. use our microcontroller to program our board to do something; and 3. for extra credit, program our board using different languages. Tom Dubick gave us an assignment to complete, where we learned about bare metal programming. I watched “Bare-Metal MCU #1- Intro to Registers” and “Level Up Your Arduino Code- Registers”, and I took notes on them. (The notes are attached below). Tom Dubick also shared a presentation called Bare Metal Programming Part 1. I was generally comfortable with the basic material, but I was pretty lost with the shifts. One acticvity in this assignment had us go into TinkerCAD Circuits and get the built-in LED (pin13) to blink using Arduino code. Then, we were asked to connect the LED to pin 9 (with a limiting 330-Ohm resistor) and code it–also using Arduino code. At the end, we were asked to modfiy the code into bare metal code. The following table shows the sequence of events in this activity.

|TinkercadBuiltInLED|TinkercadPin9| |C++TurnOnLED|C++Pin9| |DecimalTurnOnLED|DecimalPin9|

As I watched the second video “Level Up Your Arduino Code- Registers”, I again used TinkerCAD to set up the same circuit the guys physically built and utilized/referenced in the video. As he took a similar Arduino code and converted it into bare metal code, I did the same in the Arduino IDE on my laptop. I was very confused as to why I was getting an error message (stating that “DDRD was not declared in this scope”) with the exact same code as the guy in the video.

CodeErrorMessage

Notes From Reading Data Sheet for Atmel SAMD11C

As I began reading datasheets this week, I actually read/skimmed through the datasheets for the Atmel TINY412 before reading the datasheet for the Atmel SAMD11C. For our group project, we compared the Atmel SAMD11C to the Atmel Mega328, and this got me really thinking about the differences in all of these chips.

I worked very hard this week at trying to understand the design of our SAMD11 Programmers that were made in Week 6. Before startig any of my work, I wanted to see if I could look at and compare the traces on the SAMD11 programmer. I used the pinout of the SAMD11 that Dr. Harris posted on his site, SAMD11C MultiUse Board to try and identify and write out what each pin’s purpose was. The following image shows the (very) rough diagram I made.

SenseOfSAMD

I decided to make a note of a few things I was able to mentally connect with my SAMD11 programmer and things I found interesting overall.

-The SAMD11 uses a single power supply from 1.62V- 3.63V. I assumed this was the reason we had to have a 3.3 voltage regulator on the board, and a switch that allowed a change from 3.3V to 5V. After speaking with Dr. Harris about the switches on the SAMD11 programmer, he stated that once the board was a programmer, it could output 5V to a target board. We kept the switch on the 3.3V while we converted the SAMD11 PCB into a programmer (loaded the bootloader and programmer code).

-EEPROM stands for “electronically erasable programmable read-only memory”. This area is used for memory storage. There is also ROM, PROM, EPROM. These areas are different from RAM in that they do not require a power supply to withold it.

-UART stands for “universal asynchronous receiver-transmitter”. This is the way that the microcontrollers (the SAMD11 and the ATTiny412) communicate from device-to-device. The transmitter (Tx) on one devide communicates with the receiver (Rx) on the other “target” device (and vice versa). This happens with copper traces on the PCBs and jumper wires between PCB’s.

-The internal clock within the SAMD11 is immensely important, and most of the programs depend on this area working properly.

I found the following comparisons between the Atmel Tiny 412 chip and the Atmel SAMD11 chip.

|ATTinyPinout|SAMD11Pinout| |ATTinyBlock|SAMD11Block|

Using My SAMD11C to Program Board To Do Something

This week, I decided to re-post my video of me getting the two LED’s (connected to two different pins on my ATTiny412 PCB) to blink at different rates since that was something different (than simply having one LED blink). However, I was on spring break, and I had time to go into more detail with my PCB’s.

||

I also worked on my RGB LED PCB, and (with some crucial hacking help from Dr. Harris), I was eventually able to get the RGB to fade through rainbow colors. In email communications with Dr. Harris, he directed me to three websites to research and help me determine the correct code to use.

  1. Pololu Arduino library for APA102 addressable RGB LEDs
  2. Brightness Examples
  3. Former Fab Student “David”

Dr. Harris suggested that I try to “hack” my board by making the following three modifications before “re-vamping” my PCB schematic and design.

  1. Cut the traces connecting the ATTiny412 and both the SDA and SCK pins on the Dotstar RGB LED.
  2. Add resistors (lower in value– between 150-Ohm to 450-Ohm) where the traces were cut.
  3. Remove the 1K-Ohm resistor before the dotstar completely.

I made these modifications (shown below), and BOTH of my RGB LED PCB’s worked beautifully. It was around 2am, and I was so (quietly) excited– so as not to wake others in the house.

|Hack0|Hack1| |Hack2|Hack3|

This video shows my RGB LED “rainbow” sequence.

||

This week, I also decided to return to the “FinalFinal PCB” I had started in Week 6, and after learning a little more about pull-up resistors, I wanted to see if I could get the serial monitor to show a 0/1 when the button is pressed/released. I knew this was something we were going to have to do later, and I felt like I was getting close. The following video shows my SAMD11 sending a “1” to the serial monitor. My hope is that I can get the value to change when the button is pushed.

||

While I know the button is working, I am still working on the code at this time (Monday, March 21).

Using Other Programming Languages

After watching the two assigned videos this week– “Bare-Metal MCU #1- Intro to Registers” and “Level Up Your Arduino Code- Registers”– I realized that I could use my “FinalFinalPCB” for this week’s assignment. At this point, I had two LED’s blinking at different rates on this particular PCB. I felt like this would be the easiest code to modify (as most of the examples provided have been of a “Blink” code) at this point. I heavily relied on the notes I took for the videos, and on scrap paper, I began writing the new code out by hand.

|MyCodeStart|MyCodeScratch|

I created a new sketcch in Arduino, copied and pasted my “Combined Code” into this new sketch. Tom Dubick suggested that I create the circuit in TinkerCAD and test my code there. So I began setting up my circuit in TinkerCAD (as shown below).

WrongTinkerCADSetup

I GREATLY struggled at how to wire this circuit. As I discussed the difficulties I was having with fellow Fab Academy student (Andrew Jiang), I realized that it is impossible to use an ATTiny in my TinkerCAD circuit with the Arduino board as the programmer. The Arduino board in TinkerCAD has not had the jtag2-updimaster conversion! I went back to my notes from the videos and began to convert the Arduino code.

Below this copied and pasted code, I began to “translate” my code into C++. The following shows my logic/progression through this process.

Image Description
MyCode1 First, I changed the “DigitalWrite” to a “PORTD __”. I used my notes to determine which placement in the “D-bit” I was dealing with.
MyCode2 Under “Void Setup”, where pins are declared as “Outputs or Inputs”, I declared them as “DDRD ___”.
MyCode3 I changed the “Delay” to “for (long i = 0; i < 1000000; i++) {}”.
MyCode4 I wanted to see if I had correctly “re-written” the code, I asked colleague, Adam Durrett (computer and electrical engineer) to look over it. At that time, he suggested that I chanfe the “for (long i = 0; i < 1000000; i++) {}” to “for (int i = 0; i < 1000000; i++) {}”. He further explained that “int’s” can be more than a million (into the billions). While a million works for the time being, it was better to have the “pause/delay” go into the billions.

I was able to “verify” my code in the Arduino IDE, and it worked. While I had Adam Durrett, I asked him why I was getting an error code from the previous session, and he was able to locate a missing semicolon.

Group Project This Week

This week, our group assignment is to compare the performance and development workflows for other architectures. We decided to compare the SAMD11C to the Atmel Mega 328. Please visit our site.

Link to Files


Last update: May 23, 2022