interrupt RTC atmel  - Page 1
Forum section: electronics / general

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 06:04:44 pm
content: Hi !I am beginner and I am having a lot of difficulty to implement interrupts in Atmel.Basically, I used the RTC module to implement a time base of the ?C.I would like to afterwards generate interrupts at regular intervals to executing a of my functions in parallel operation of the main program.But the problem is I can not find a concrete example that allows me to put in place an interruption.So I use the function initalisation above but afterwards how to implement an interruptionOn the Internet, I understand the need establish a routine ISR service.Code:ISR (RTC_Handle){// Here with calling my function}But I also find things this way:Code:NVIC_EnableIRQ (RTC_IRQn);NVIC_SetPrioroty(RTC_IRQn,2);but after with this, where do I place my code?I'm lostCan someone explain to me how this works with an example without using the functions of atmel?Thanks

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 06:44:40 pm
content: Do you actually have GCLK configured? What frequency it is running at?Also, "Atmel" is a manufacturer, you may want to mention a specific device that you are using.And edit your posts so that code is properly wrapped in [ code ] tags.

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 08:32:34 pm
content: Quote from: losst on September 14, 2016, 06:51:53 pmYou can't not worry about clocks. You indicated that you want RTC to be clocked from GCLK. You need to have an actual clock source attached to that GCLK, otherwise noting will happen.

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 08:43:08 pm
content: I want to use an internal clock source to the microcontroller. Then I want to generate interrupts at regular time intervals from the time base, to run in the background another function together my program runs

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 08:46:42 pm
content: You still need to connect that internal clock to the GCLK.I have sample projects for a number of Atmel MCUs. Here is one for D10https://github.com/ataradov/mcu-starter-projects/tree/master/samd10It blinks an LED in the timer (not RTC, just a regular timer,) interrupt.

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 09:01:22 pm
content: When I look at your project I do not understand the functions that are used for interruptsI see :Code:void irq_handler_tc1(void){if (TC1->COUNT16.INTFLAG.reg & TC_INTFLAG_MC(1)){HAL_GPIO_LED_toggle();TC1->COUNT16.INTFLAG.reg = TC_INTFLAG_MC(1);}}So in my case it's:Code:void irq_handler_rtc(void){if(RTC->MODE0.INTFLAG.bit.CMP0){my_function();}}you flash your LED in the background due to an interruption to TC. But what is that:TC_INTFLAG_MC (1)In my case the function will be:this feature only runs? there is no need to call it, it runs only?

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 09:07:25 pm
content: Quote from: losst on September 14, 2016, 09:01:22 pmWell, replace HAL_GPIO_LED_toggle() with my_function(). Although running big chunks of code in the interrupt is generally a bad idea.Quote from: losst on September 14, 2016, 09:01:22 pmIt is a bit corresponding to the interrupt flag.Quote from: losst on September 14, 2016, 09:01:22 pmI don't understand the question.

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 09:12:29 pm
content: Because it is an interrupt handler, it is called by the MCU when interrupt happens. That's how interrupts work.

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 09:17:55 pm
content: In your function your counter starts at 0 and counts up to 15 625 (= 8000000/1000/256) * 500Then when the counter reaches this value an interrupt is generated through online NVIC_EnableIRQ (TC1_IRQn); . It is from this that the function runs: void irq_handler_tc1 (void) and flashes the led? but the LED will operate when the counter reaches the value of the TC

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 09:22:06 pm
content: Quote from: losst on September 14, 2016, 09:17:55 pmThis allows MCU to call your interrupt handler when interrupt is triggered. Basically this tells the MCU that you have defined a valid handler.Quote from: losst on September 14, 2016, 09:17:55 pmirq_handler_tc1() will be called every time there is a flag that this interrupt is pending.AndCode:TC1->COUNT16.INTFLAG.reg = TC_INTFLAG_MC(1);clears that flag, so that interrupt handler is not called again right after it exits.

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 09:22:40 pm
content: What is then the difference between the IRQ interrupts and ISR?

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 09:24:15 pm
content: ISR() is not a thing, at least not for ARM processors. It all depends on your environment and startup code. I don't know what ISR() does in your case, it it up to whoever wrote that code.

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 09:27:44 pm
content: How do I download your entire project and test it with all these files?

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 09:29:06 pm
content: Go herehttps://github.com/ataradov/mcu-starter-projectsand press big green button "Clone or download".

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 09:52:57 pm
content: But the fact of using this interruption that does not disturb the operation of the main program? It is executed well in the background, in parallel?

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 09:53:24 pm
content: I don't know. That depends on the frequency of the clock source connected to the GCLK.It is better to verify if you are not sure anyway. Just toggle the pin on the ISR and check how fast it toggles in real life.

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 09:58:31 pm
content: Quote from: losst on September 14, 2016, 09:52:57 pmNo, it is an interrupt. It interrupts execution of the main program, does its thing, and then continues with the main program. You can't execute two things in parallel on a single core CPU.

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 10:00:30 pm
content: I do not understand well, you advise me to perform the same test you by integrating my function in your program and check that the LED flashes. I'll try that.

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 10:09:10 pm
content: Interrupt handler names are not predefined, they must match the ones in the startup code. If you integrated your function into my code, then "RTC_IRQHandler" should be called "irq_handler_rtc" (see startup_samd10.c).

author: dannyf
author_rank: Super Contributor
timestamp: September 14, 2016, 10:13:36 pm
content: "But the problem is I can not find a concrete example that allows me to put in place an interruption."Having example code helps but is not necessary. Read the device datasheet and the compiler manual about the following:1. How to set up the rtc.2. How to set up the interrupt.3. How to service the interrupt.Regardless of platforms or even the interrupts I involved, those are always the steps that you have to go through.

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 10:18:25 pm
content: Now those famous clock to control my RTC and the time of interruption so I can still see my LED light off and I have to edit the registry 'RTC-> MODE0.COMPreg' but for my clock how do I do? GCLK-> = CLKCTRL.reg GCLK_CLKCTRL_GEN (0)At the moment it flashes extremely quickly we did not even perceive the LED off

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 10:23:38 pm
content: Quote from: losst on September 14, 2016, 10:18:25 pmSomewhere else in your code you configure GCLK to run from some frequency. Again, if you use my code, then default RC oscillator is used, but sys_init() function disables prescaler, so resulting clock is 8 MHz. Now you need to select appropriate divider in your peripheral setting (16 at the moment). And then select compare value to get your desired interval.My timer code selects 256 as a divider, you may want to use similar value.

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 10:34:50 pm
content: Now when I try to incorporate into my project it tells me that my function is redundant "multiple definition of RTC_Handler". Do not declare as protoype in the header?The only place where it is if it is in startup_samd ...RTC_Handler void (void) __attribute__ ((weak, alias ("Dummy_Handler")));

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 10:37:23 pm
content: What function is redundant?

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 10:38:30 pm
content: multiple definition of RTC_Handler

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 10:39:42 pm
content: Well, find those definitions and figure out which one you really need. I have no idea what you use as your base program.

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 10:42:58 pm
content: This means that I use this function elsewhere in my program? But this is the first time I use an interrupt.

author: ataradov
author_rank: Super Contributor
timestamp: September 14, 2016, 10:43:47 pm
content: Well, you use some library (ASF?). This library may have defined this function already.

author: losst
author_rank: Contributor
timestamp: September 14, 2016, 10:56:13 pm
content: ok it's good it works ASF was a library that was included in the project.Thank you. Thank you for the time you gave me thank you now I know how to walk interrupts!