Home About Gallery Blog Fab Academy Contact # Programming ATSAMD11C This is a guide to programming a SAMD11C14 based microcontroller board using tools found in a Fab Lab. Two methods will be covered, programming using Atmel Studio and using Arduino IDE. ## Arduino IDE ### requirements * A ATSAMD11C based microcontroller board * A programmed ATSAMD11C based EDGB programmer [board](http://academy.cba.mit.edu/classes/embedded_programming/SWD/hello.CMSIS-DAP.10.D11C.png) which can be found [here](http://academy.cba.mit.edu/classes/embedded_programming/index.html#programmers) ![](..\img\fab\2\1.jpg) * An SWD programming cable * Arduino IDE software ### Adding the board (SAMD core) In order to program the board using the Arduino IDE, you must add the board first to the list of boards your Arduino IDE can communicate with. We are using the [Mattairtech SAMD Arduino core](https://github.com/mattairtech/ArduinoCore-samd). It is a core that provides Arduino support for SAM D|L|C. In order to use the core, first go to File > preferences ![](..\img\fab\2\2.png) Add the URL blow to the additional boards manager section <code> https://www.mattairtech.com/software/arduino/package_MattairTech_index.json </code> ![](..\img\fab\2\3.png) Tools > board > board manager ![](..\img\fab\2\4.png) Search for the "MattairTech SAM D|L|C Core for Arduino" and click install ![](..\img\fab\2\5.png) When correctly installed, the MattairTech core boards should appear in your list of boards available ![](..\img\fab\2\6.png) ### Board settings After adding the core as a board, the correct settings must be selected as per the ATSAMD11C based board. ![](..\img\fab\2\7.png) for programmer, select "Atmel EDGB" ### programming To program the microcontroller, you must know the pinout for the microcontroller chip and the corresponding Arduino pins. Refer to the Mattairtech SAMD Arduino core documentation linked [here](https://github.com/mattairtech/ArduinoCore-samd/tree/master/variants/Generic_D11C14A) to figure out the Arduino pin numbers. ![](..\img\fab\2\9.png) Example: Pin 1 of the Sam (upper left corner) = Pin PA05 = Arduino pin 5 So in this case, to use that pin, it must be referred to in the code as pin 5. Using the blink example, We are toggling pin 5 on and off for a duration of 1 second. Which means that will go high (output 3.3 volts) for one second and then go low (output 0 volts) for one second, and repeat. <code> // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(5, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(5, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } </code> To upload your code, go to Sketch > upload using programmer ![](..\img\fab\2\10.png) If the program finished uploading successfully, you will get a message that says "done uploading" ![](..\img\fab\2\16.png) For more complex programming, refer to the board examples. After adding the SAM core, you will get some examples specifically made for the ATSAMD11C. You can access the examples by going to File > Examples ![](..\img\fab\2\8.png) ### possible problems and causes By default, the Arduino IDE will display an error message when something goes wrong and the code cannot be uploaded to the microcontroller board. However, when something goes wrong, you want access to all information available to help you debug. To get the maximum amount of information, turn on verbos compilation and upload output in the preferences. File > preferences ![](..\img\fab\2\11.png) #### "Please select a programmer from Tools->Programmer menu" Error message ![](..\img\fab\2\12.png) This error probably means that the selected programmer in Tools > programmer is an incompatible programmer. The SAMD cannot be programmed using a USBtinyISP or ArduinoAsISP, A compatible programmer such as the Atmel ICE or Atmel EDGB must be used. The programmer used for this tutorial is an Atmel EDGB. #### "No Valid JTAG Interface Configured" Error message ![](..\img\fab\2\13.png) This error message means that the Arduino IDE was unable to detect a CMSIS-DAP device. Make sure that the programmer is properly connected, receiving power and is operational. If the error persists, ensure that the PC is recognizing the programmer plugged in. In windows it should appear in the device manager. ![](..\img\fab\2\14.png) #### " ** OpenOCD init failed ** shutdown command invoked" Error message ![](..\img\fab\2\15.png) The displayed error message is "An error occurred while uploading the sketch". This is a very common and generic error message, This is where turning on verbose output becomes helpful as it shows what exactly went wrong and where. By looking at the full message, it shows that the programming failed after initializing the programmer. The programmer was detected by the software and was determined to be working, however the programming target was not found. Ensure the SAM microcontroller board that is supposed to be programmed is powered, operational and is connected to the programmer the correct way using the 10 pin SWD cable.