I did start recently to experiment with the Atmel SAM D21G; while looking for a more powerful microcontroller, that could replace the ATMega used in many board like the Arduino. The Arduino Zero has as main microcontroller, an Atmel SAM D 21; which is able to be programmed via Arduino IDE. Awesome.
Getting started
Next step is to make my own design; so I started with the bare chip. They are sold in various store, so you won't have much of a problem to find them. The chip is sold as QFP or QFN, with different number of pins; pick the size and version that satisfy your needs; I did start with a 48 pin QFP
Atmel SAM-D Page
First problem: the chip is very small, and unless you use a breakout board, it is not possible to make any connection. You have another option: there are adapters from QFP to DIP; which allow you to use a simple breadboard to start, while you decide the design and all the other details of your design.
The adapter is easy to find; although Ebay seems to have the cheapest of all.
TQFP48 QFP48 to DIP48 Programming Adapter Socket
You also need a breadboard, which will host the temporary circuit, some capacitors (the schematic posted below will show the values for each capacitor), male/male and male/female wires and a regulated 3.3V adapter, since the chip maximum voltage is 3.6V.
The last thing that you need is software to program the chip, and hardware to talk to the chip via computer. Since the chip does not have yet the bootloader; even if you connect the USB connections from the chip, you can't do anything with it (the computer won't even see it as peripheral in some case).
As software, you need 2 items:
- Bootloader (to put code on the chip via serial or USB port)
- IDE to put the bootloader on the chip.
The bootloader is provided by Atmel; good news! You get the whole package, including the source code, so you can modify it as you prefer. Dowload it from the Atmel site
Atmel SAM-BA Bootloader
The IDE is also provided by Atmel; you need to create an account on the site, and it is free. Download it and install the software.
The hardware is what will put the software on your chip. For the SAM-D21, you can get an Atmel-ICE. This allow you to put code and bootloader on the chip, and also to debug in realtime; which is super useful.
Atmel ICE debugger
Keep in mind, that the base version of the ICE, has a 10 pin connector with a very small pitch (0.25), compared to the regular .5 pitch, found in most connectors. So if you want to use the 10 pin connector, either you need to buy the more expensive kit (120 Vs 65, but you get various adapters, which cover multiple cases, so you can program different chips).
The alternative is to get some adapter, that change the pitch from .25 to .5, make your own cable or use the 6 pin connector (more about this later on). It is up to you to decide if the extra connectors are worth the 50 dollars extra on the device price.
Power up the chip
Now it is time to connect the chip; the first thing is to connect the pins to the breadboard (you can use headers or solder the wires directly on the adapter). In the beginning, you will need to connect the pins related to power and ground.The 48 pin version, has 4 set of pins, plus Core
- Pin 5 and 6 for analog Vin and GND
- Pin 17 and 18 for Digital Vin and GND
- Pin 35 and 36 for the second Digital Vin and GND
- Pin 42 and 44 for the main Vin and GND
- Pin 43 for VDD Core (it has no related ground)
It is important to know that you need to connect ALL the power and ground lines, and you also need capacitors, to stabilize the input to the processor. The diagram below show the values of the capacitors and how to connect them.
A good approach is to put one capacitor (either 0.1 microFarad or 1 microFarad) for each line; I did follow this approach and the system is stable.
Connect the regulated 3.3V source and the chip is ready to go. Do not power up yet the chip.
Software setup and Bootloader
The software setup is pretty simple; download Atmel Studio and install it; once done, run it for the first time. Keep in mind that Atmel Studio works only on Windows, so keep that in mind.The bootloader once downloaded, will be available as .hex file (for the SAM-D21G18A, the file is in the "load sam-ba/samd21g18a" folder.
Hardware programmer setup
The device is very simple; one side has the USB connector that goes to your computer, the other side has 2 connectors, marked AVR and SAM. You will need the SAM connector. The ICE is shipped with a small ribbon cable, which has a 10 pin (.25 pitch) on both sides, and a 6 pin (.5 pitch) connector, which is used mainly for SPI programming, while using AVR. This won't work with SAM port, unless you make some changes.The first thing to notice is that pin 10 (reset), is not carried over to the 6 pin connector, so if you do not have available the 10 pin adaptor (from .25 pitch to .5 pitch), you need to make a hack on the cable.
Expose the wire, from the leftover of the ribbon coming from the 10 pin connector, and solder a wire; this will be the wire to connect to the Reset pin of the SAM-D21.
Now, for the pinout of the 6 pin connector, you have the following:
Which correspond on the 6 pin connector as following (:
The plastic key will be on the left, if you look at the connector from the back. The VTG pin wire will be red.
Now you need to connect with wires, the pins from the socket adapter: SWDCLK is on pin 45, while SWDIO is on pin 46. SWO is not required, so you can let it be. The 2 GND goes to the GND of the breadboard, while VTG goes on the positive of the breadboard (where you supply the regulated 3.3V)
You also need the Reset pin from the Socket adapter, which is located on pin 40; connect this pin to the cable that you attached to the reset pin on the flat cable.
Once the connections are done, you are ready to start program the chip.
Chip programming - Install bootloader
You should have Atmel studio already up and running; now you can connect the USB cable from the ICE to the computer. The drivers will be installed automatically (be sure to install first Atmel studio, before you plug the ICE; otherwise Windows will have problems to find the drivers).
You will see a solid red light on the ICE. Now power up the socket adapter, and you should see a solid green light on the ICE, if the connections are correctly done.
Now in Atmel studio, go to the menu " Tools" and select "Device Programming".
In the tool dropdown, you will see the Atmel ICE, in the device, choose ATSAMD21G18A (in your case, whatever model you purchased); and as interface choose SWD and click Apply.
You will see settings appearing in the lower part of the window; just leave everything as is, and click "Set"
Now, click on "Read", under "Target Voltage", you should see 3.3V or a similar value. Now click "Read", under "Device Signature", and you should see the hex value of your blank SAM D21. Congrats!
If you have problems, check that the connections are correct, check that al the power lines and ground are connected; and verify that the pin from the ICE are correctly paired with the socket adapter pin. Be sure that the connector plugged in the ICE is in the SAM position, not AVR (you may break the ICE if the connector is mixed up, so be careful).
Check also that the socket adapter has the chip in the correct position (the chip has a circle on the top left corner to show where pin 1 is located; the socket usually have an identifier, like a triangle in the upper left corner. Pin 1 will be on the left row, pin 48 on the top row, so position the chip accordingly.
Once that the device signature is read, you can put the bootloader on it.
Go to the Memories section, and choose the hex file that you want to burn (there are 3 version: one for usb, one for UART and the third use both), based on your design, then click on "Program".
Congratulations! you should see a message on the bottom of the window that tell you that the bootloader has been burned correctly. Now you can program the device via UART or USB.
I will prepare a follow up where I will show how to write simple applications for the microcontroller, and how to upload them via USB or UART.