Hi there, my first thread in arduino forums so sorry if I make any mess.
I've programmed the Arduino Nano (AVR328p) a lot in the ATMEL STUDIO 7 and all I needed was the datasheet. Now im trying to program a Arduino Due (AT91SAM3X8E) and I cant find ANY reference online or in the datasheet how to do the basic stuff. Im using the ASF already to do the startup of the chip, and I think i know how to operate the GPIO's only using the registers. Thats all great. Now I need to use simple timed interruptions and I cant find how. How do I program interruptions, what function do I use, etc?
Thanks
Well thank you so much for the code, gonna start working on it right now. The problem is: Where the hell did you take that from? I searched all datasheet and couldn't find anything close to the "void TC2_Handler()" or the "NVIC_EnableIRQ(TC2_IRQn)". Am I looking at the wrong place? Thank you so much again.
In the IDE window, select File> Preferences. At the bottom of this new window, click in the URL:
C:\Users...\AppData\Local\Arduino15\preferences.txt, select the following path:
packages/arduino/hardware/sam/(your sam compiler version)/cores/arduino/cortex_handlers
Plus you can find CMSIS functions for NVIC control page 164 of Sam3x datasheet.
I do appreciate all the help. Its working flawlessly. One last question:
This type of coding "TC0->TC_CHANNEL[2].TC_RC = 2100;" using pointers, structs and vectors to registers is really odd to me. I understand the you are accessing TC_RC of the channel 2 of the timer 0 and writing but it's really weird for me.
I'm used to call the registers directly by their defined names. Would you please tell me where can I read more about this type of sintax so I could not only read your code but learn how to write it as well? Thank you so much for the help.
This type of coding "TC0->TC_CHANNEL[2].TC_RC = 2100;" using pointers, structs and vectors to registers is really odd to me.
It's a relatively standard practice of overlaying C structure definitions on hardware registers of a peripheral (and you can google that, although I didn't find any really stellar explanations. https://www.edn.com/print/4438698 is pretty good, I guess.
In addition to being common, this method of defining access to peripheral registers is made STANDARD for ARM Cortext processors by ARM's CMSIS specification. (this is REALLY important for defining the registers that are standard to the ARM Core, so they don't wind up with different methods from different vendors, but they also say that it should be done for all the vendor-specific peripherals.)
It also works out to be more efficient in many cases. ARM doesn't have an instruction equivalent to LDS on AVR (load a variable from an absolute memory address) - once you load the base address of a SET of peripheral registers, they can be accessed more easily via the relatively small offsets than they could be accessed individually.