First LED Blinky not working on SAMD10D14 - Page 1
Forum section: electronics / beginners

author: n4alpaca
author_rank: Newbie
timestamp: October 31, 2017, 04:01:18 am
content: Hello, This will hopefully be the first first microcontroller I get to blink an LED (with you guys' help). I'll start by describing the setup:I have a broken out and bread boarded SAMD10D14 (20 pin SOIC). I have a 47uF electrolytic capacitor on my Vin in addition to an 0.1uF ceramic capactior near the Vin Pin on the breakout board.The voltage sits at about 3.05V via a voltage divider powered by a 5V usb charger. The voltage divider is made of something like a 47 and 68 ohm resistor so there is sufficient current for sure (100mA) as the led only requires at minimum something like 5. I'm also sure it works because it's been tested independently.I'm connecting to the uC with a J-link edu via SWD with 100k pullups on SWCLK, SWDIO and nRST. I can connect and see the registers just fine.I'm using Segger embedded studios.My LED is connected to a 330 ohm resistor and the pin PA05.There aren't any errors, the pin simply doesn't light up as it's supposed to. I check the registers and the value I wrote to them is there.I have no idea what is happening. My code and a picture of the IDE:Thanks for looking!

author: ataradov
author_rank: Super Contributor
timestamp: October 31, 2017, 04:19:09 am
content: Where is the other side of that LED?And use CMSIS header files. I have not checked if your register definitions are correct, but the code looks correct, provided that SEGGER startup does not do something silly.Also, try to define those registers as "volatile unsigned long".

author: ataradov
author_rank: Super Contributor
timestamp: October 31, 2017, 04:22:30 am
content: Actually, you are toggling PA4.Do things like REG = (1<<5); and let compiler shift things for you.

author: n4alpaca
author_rank: Newbie
timestamp: October 31, 2017, 03:28:25 pm
content: Thanks so much! The LED turns on now. I haven't used CMSIS yet, but looking into the include files, it seems as though I would use that instead of my register definitions? I tried using ASF before and I was very very unhappy with the code and file structure that I was provided. Is CMSIS like ASF in that it has a bunch of commonly used functions?

author: ataradov
author_rank: Super Contributor
timestamp: October 31, 2017, 03:34:17 pm
content: Quote from: n4alpaca on October 31, 2017, 03:28:25 pmAbsolutely! Defining your own registers is a huge waste of time, and a way to introduce errors.I have a collection of simple application herehttps://github.com/ataradov/mcu-starter-projects. They may not work for you as is, if you want to stay within Segger ecosystem, but you may pick some stuff from them. For example GPIO manipulation macros (hal_gpio.h) proved to be extremely useful and it will work for you as is.Quote from: n4alpaca on October 31, 2017, 03:28:25 pmSounds about right.Quote from: n4alpaca on October 31, 2017, 03:28:25 pmCMSIS has many layers. The most basic and useful one is just a bunch of header files with excellent register definitions. There is no overhead in using them, and that's what I do in my code. Next levels of CMSIS include code and OSes, and it is not excellent, but you don't have to use it.

author: n4alpaca
author_rank: Newbie
timestamp: November 01, 2017, 01:58:49 am
content: I do Have one more question about the solution to my problem. I read that the pin number corresponds to the position of the bit used to manipulate it. So 1<<5 bit shift left so that we get 0b100000 which is in the register labeled as 5 starting from 0. My question is this, What is in the 0th position? There is no Pin 0, so is it nothing?

author: ataradov
author_rank: Super Contributor
timestamp: November 01, 2017, 02:03:50 am
content: Quote from: n4alpaca on November 01, 2017, 01:58:49 amIt is a bit that would correspond to PA0 (or Px0, in general). Whether this bit is implemented on the device or not is irrelevant. You are working with a relatively small device, so a lot of bits will correspond to noting on the outside of the device.