Helpful ReplyHot!How do you specify ISR in C?

Page: 12 > Showing page 1 of 2 - Powered by APG vNext Trial
Author
woky
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2017/11/26 11:22:56
  • Location: 0
  • Status: offline
2018/01/12 10:13:29 (permalink)
3 (1)

How do you specify ISR in C?

Hi. I'm newbie to PIC programming. I've PIC24FJ265GA410 with XC16 compiler. When I was experimenting with UART, somwhere I read that I should define TX interrupt like this:
 
void __attribute__((__interrupt__, auto_psv)) _U1TXInterrupt(void) {
    _U1TXIF = 0;
}

 
I've never seen it documented anywhere. PIC24F family manuals only talk about registers and device operation and XC16 manual doesn't deal with peripherals.
 
Currently I need to make and ISR for Interrupt-on-Change on a pin. How do I specify the interrupt handler and more importantly, where's a documentation about how plain C function names translate to ISRs?
 
Thank you.
#1
mbrowning
Just a Member
  • Total Posts : 930
  • Reward points : 0
  • Joined: 2005/03/16 14:32:56
  • Location: Melbourne, FL
  • Status: offline
Re: How do you specify ISR in C? 2018/01/12 13:33:21 (permalink)
+8 (8)
Some people might say read the XC16 User's Guide that was included with the compiler. There might even be a whole chapter on interrupts.

Can't remember. I've slept since then - Mark
#2
PStechPaul
Super Member
  • Total Posts : 1834
  • Reward points : 0
  • Joined: 2006/06/27 16:11:32
  • Location: Cockeysville, MD, USA
  • Status: offline
Re: How do you specify ISR in C? 2018/01/12 14:04:10 (permalink)
0
If that PIC is supported, you might try using the MCC (Microchip Code Configurator), which will generate working (although perhaps not optimal) source code. Harmony might be applicable as well. Further discussion would best be done in the proper sub-forum, perhaps XC16 or MCC. This is not an issue with the MPLABX IDE.

 
#3
Gort2015
Klaatu Barada Nikto
  • Total Posts : 2573
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: How do you specify ISR in C? 2018/01/12 15:40:21 (permalink)
-2 (4)
Get this from Microchip if you want to bang the metal.
Section 30. IO Ports with Peripheral Pin Select (PPS)
post edited by Gort2015 - 2018/01/12 15:43:40

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#4
DavidBLit
Super Member
  • Total Posts : 1547
  • Reward points : 0
  • Joined: 2012/02/18 13:08:48
  • Location: The Land of Confusion
  • Status: offline
Re: How do you specify ISR in C? 2018/01/12 16:52:09 (permalink)
0
Gort2015
Get this from Microchip if you want to bang the metal.
Section 30. IO Ports with Peripheral Pin Select (PPS)

Which has exactly what to do with ISR's in C?

Yeah, "//Code and stuff".
#5
Gort2015
Klaatu Barada Nikto
  • Total Posts : 2573
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: How do you specify ISR in C? 2018/01/13 09:26:07 (permalink)
-1 (3)
No need for the negative vote, the OP wanted to use Change Notification and that document explains that in more detail.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#6
DavidBLit
Super Member
  • Total Posts : 1547
  • Reward points : 0
  • Joined: 2012/02/18 13:08:48
  • Location: The Land of Confusion
  • Status: offline
Re: How do you specify ISR in C? 2018/01/13 18:34:44 (permalink)
+1 (1)
Gort2015
No need for the negative vote, the OP wanted to use Change Notification and that document explains that in more detail.

Hardly.  His only actual questions were:
woky
How do I specify the interrupt handler and more importantly, where's a documentation about how plain C function names translate to ISRs?


Yeah, "//Code and stuff".
#7
NKurzman
A Guy on the Net
  • Total Posts : 15926
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: How do you specify ISR in C? 2018/01/13 23:15:28 (permalink)
+2 (2)
The third paragraph of his post does speak of change notification.
#8
Peter Sikora
Super Member
  • Total Posts : 132
  • Reward points : 0
  • Joined: 2003/11/07 12:46:46
  • Location: Brisbane Australia
  • Status: offline
Re: How do you specify ISR in C? 2018/01/14 11:25:40 (permalink)
0
mbrowning
Some people might say read the XC16 User's Guide that was included with the compiler. There might even be a whole chapter on interrupts.

I don't know why you were voted up on this one so many times. I didn't find it helpful at all. If I do a search in the XC16 compiler users guide I get nothing on "_U1TXInterrupt" so reading the guide cover to cover would shed no light on this function declaration. It would have been more helpful to tell the guy where to look for mention of _U1TXInterrupt. It was only that I bought Lucio Di Jasio Programming 16-bit micro controllers in c that I became aware of where to find the function name. it certainly doesn't come up in a search of DS39969B and neither does it come up in a search of DS39707A.And to be fair eve De Jasio doesn't like the messy version "void __attribute__((__interrupt__, auto_psv)) _U1TXInterrupt(void)"most of his examples simply use" void _ISR _U1TXInterrupt(void); "and I quote on page 69 he states interrupt vectors can be found in  "interrupt vectors Table of the PIC24 (defined in the data sheets) and as coded in the linker script"The only problem is there is no interrupt vectors table that I can see on DS39707A that mentions  U1TXInterrupt.So @woky I would suggest to get De Jasio's book as a guide on where to start if you are new to PIC24 programming. It has many worked examples for you to follow to get a foot hold.
post edited by Peter Sikora - 2018/01/14 11:30:38
#9
jtemples
Super Member
  • Total Posts : 10787
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: How do you specify ISR in C? 2018/01/14 11:31:43 (permalink) ☄ Helpfulby Peter Sikora 2018/01/14 12:20:07
+3 (3)
conelec
If I do a search in the XC16 compiler users guide I get nothing on "_U1TXInterrupt" so reading the guide cover to cover would shed no light on this function declaration.

 
14.4.2
 Interrupt Vector Tables
For tables of interrupt vectors by device family:
• In MPLAB X IDE, for newer versions of the compiler, open the Dashboard window
and click on the Compiler Help button.
• On the command-line, see the docs subdirectory of the MPLAB XC16 C compiler
install directory (Section 4.2 “MPLAB X IDE and Tools Installation”). Open the
XC16MasterIndex file and click on the “Interrupt Vector Tables Reference” link.

#10
Peter Sikora
Super Member
  • Total Posts : 132
  • Reward points : 0
  • Joined: 2003/11/07 12:46:46
  • Location: Brisbane Australia
  • Status: offline
Re: How do you specify ISR in C? 2018/01/14 12:06:03 (permalink)
+1 (1)
@jtemples I would not and did not find that section looking for the key words _U1TXInterrupt. Only a search of "vector tables" would find this information. You have to remember that for someone new, it is like looking at Ancient Egyptian hieroglyphics. Until somehow you can translate what you are seeing into a language you can understand you have no idea of the meaning of what you are looking at. There is no such thing as a stupid question. It's how we all learn and that's what this forum is about, teaching and learning.Thanks for being a good teacher.
To the other contributors, be fair to question posters we can't all know everything. This is not a competition. Point them in the right direction with helpful, worked examples with lots of comments to make the intention clear and unambiguous.
#11
NKurzman
A Guy on the Net
  • Total Posts : 15926
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: How do you specify ISR in C? 2018/01/14 12:06:17 (permalink)
+4 (4)
You are looking for one stop shopping for what you need. It is not written that way. The compiler manual tells you the syntax it needs for an interrupt. The IC documentation tells you what interrupts your particular chip has. These are reference documents, not how to guide.
How to books would combine them for the chip the author is writing about.
#12
mbrowning
Just a Member
  • Total Posts : 930
  • Reward points : 0
  • Joined: 2005/03/16 14:32:56
  • Location: Melbourne, FL
  • Status: offline
Re: How do you specify ISR in C? 2018/01/14 12:36:37 (permalink)
+1 (1)
I don't know why you were voted up on this one so many times.

I'm surprised myself. But I was answering the comment "I've never seen it documented anywhere."
 
I've never used XC16, but I know where to look for answers. It seems new users don't realize there is documentation installed right alongside the compiler. Admittedly it is hidden a bit.

Can't remember. I've slept since then - Mark
#13
Peter Sikora
Super Member
  • Total Posts : 132
  • Reward points : 0
  • Joined: 2003/11/07 12:46:46
  • Location: Brisbane Australia
  • Status: offline
Re: How do you specify ISR in C? 2018/01/14 12:39:50 (permalink)
+1 (1)
@NKurzman I don't see it as one stop shopping. This is a forum where everyone becomes an author and like De Jasio and in my opinion should try and provide the missing links and be helpful. What would have been wrong with pointing the OP in the direction he has to look, like @jtemples provided. Simply telling them to read the manual is not helpful. I have spent many days reading manuals to try and find answers to to seemingly obscure problems. The first place I always start is a search for keywords. If keywords don't come up and I can't find reference to them, then I ask forums like these. With a bit of luck someone provides an answer I can understand. I can also see the up voting an down voting can be used as a tool of intimidation rather than providing a means to flag a relevant answer. I try and remain courteous even though the tone at times may seem otherwise because unlike De Jasio's book you are all giving up your time freely.
#14
NKurzman
A Guy on the Net
  • Total Posts : 15926
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: How do you specify ISR in C? 2018/01/14 14:48:30 (permalink)
+4 (4)
Then Start with i can not find the information and where you looked.  There is a large number of questions posted to the forum that are basically can you look this up in the manual for me.  That is why you will see did you read the manual/data sheet a lot. (not so much for Harmony) If you have found a book that is helpfully then I would say post that. others will read you post.  The manuals are tech documents.  The are not always easy to read or easy to find things in.  The help given was the manual an chapter.  That is way it got upvoted,  Fishing lessons, not Fish.
#15
jtemples
Super Member
  • Total Posts : 10787
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: How do you specify ISR in C? 2018/01/14 15:49:24 (permalink)
+1 (1)
Simply telling them to read the manual is not helpful.

 
To be fair, mbrowning said, "read the Interrupts chapter of the manual," which is the best advice in my opinion.  It's not a very long chapter, and it has the answer to the question.
#16
Peter Sikora
Super Member
  • Total Posts : 132
  • Reward points : 0
  • Joined: 2003/11/07 12:46:46
  • Location: Brisbane Australia
  • Status: offline
Re: How do you specify ISR in C? 2018/01/14 16:07:32 (permalink)
0
woky
Currently I need to make and ISR for Interrupt-on-Change on a pin. How do I specify the interrupt handler and more importantly, where's a documentation about how plain C function names translate to ISRs?

The guy joined in Nov 2017 has only one post apart from this one. He is not obviously an abuser of the forum.
He asked a valid question which was not answered by the first answer and that first answer that was voted up was next to useless. Based on that I think he was treated unfairly and disrespectfully. @Gort2015 tried to answer part of that question and was voted down. @jtemples was the only one who provided a concrete answer. "where's a documentation about how plain C function names translate to ISRs?"
I am all in agreement with the saying "Teach a man to fish and he will never go hungry" I am sorry but the first answer did nothing to address the question and was belittling the OP. There was no need for it.
#17
JPortici
Super Member
  • Total Posts : 207
  • Reward points : 0
  • Joined: 2012/11/17 06:27:45
  • Location: 0
  • Status: online
Re: How do you specify ISR in C? 2018/01/15 04:32:07 (permalink)
+1 (1)
conelecThe first place I always start is a search for keywords.



and the keyword was "interrupt". jtemples' quoted a bit from the manual which you should know about if you really read it. The manual gives a generic way on how to write an interrupt routine and what attributes you may want to pass. then it tells you where to look for the default ISR names for your device. what else do you need? did you want him to write your code for you?
 
you sound like a bad student calling him a bad teacher
#18
1and0
Access is Denied
  • Total Posts : 7990
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: How do you specify ISR in C? 2018/01/15 05:49:51 (permalink)
+3 (3)
Jack_M
conelecThe first place I always start is a search for keywords.

and the keyword was "interrupt".

Search that keyword "interrupt" and one will immediately find sections 14.3 and 14.4, which are only four pages, and arrive at the answer to the question.  The entire chapter on interrupts has only 13 pages.
 
Jack_M
what else do you need? did you want him to write your code for you?

Some people come here expecting to be handed the fish on a silver platter and to be spoon-fed too. :(
 
post edited by 1and0 - 2018/01/15 06:07:52
#19
Peter Sikora
Super Member
  • Total Posts : 132
  • Reward points : 0
  • Joined: 2003/11/07 12:46:46
  • Location: Brisbane Australia
  • Status: offline
Re: How do you specify ISR in C? 2018/01/15 11:40:10 (permalink)
+2 (2)
I can see that my mistake was to comment on the quality of a posters answer. I will refrain from doing so in the future. Apologies to anyone who took it personally.
#20
Page: 12 > Showing page 1 of 2 - Powered by APG vNext Trial
Jump to:
© 2018 APG vNext Trial Version 4.5