View previous topic :: View next topic |
Author |
Message |
arnadan
Joined: 11 Nov 2013 Posts: 13
|
Ex_PCD_Bootload.c with Interrupt |
Posted: Fri Jan 10, 2014 1:15 am |
|
|
I can successfully build and run Ex_PCD_Bootloader.c and Ex_PCD_Bootload.c. The Ex_PCD_Bootload.c has the following very simple main function:
Code: | void main()
{
delay_ms(100);
printf("\r\nApplication Version 1.0\r\n");
printf("\r\nYou can put whatever code you want here.");
printf("\r\nSo enjoy!");
while(TRUE);
} |
Now I am trying to extend that simple example by a timer as follows:
Code: | void main()
{
delay_ms(100);
printf("\r\nApplication Version 1.0\r\n");
printf("\r\nHere is some code now:");
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_8);
set_timer2(0xCF2B); //Setzwert für 10ms-Ueberlauf
enable_interrupts(INT_TIMER2); //Timer2 Interrupt freigeben
while(TRUE);
}
#INT_TIMER2
void Timer2_ISR(void)
{
printf("\r\nHello timer world\r\n");
} |
But now my timer never seems to be called. Something wrong with interrupt vectors? Any ideas on how to get this simple example working?
Any help appreciated. Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 10, 2014 1:20 am |
|
|
Where is your line to enable Global interrupts ? |
|
|
arnadan
Joined: 11 Nov 2013 Posts: 13
|
|
Posted: Fri Jan 10, 2014 1:40 am |
|
|
Yes I just noticed that I forgot that. Added it now:
Code: |
void main()
{
delay_ms(100);
printf("\r\nApplication Version 1.0\r\n");
printf("\r\nHere is some code now:");
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_8);
set_timer2(0xCF2B); //Setzwert für 10ms-Ueberlauf
enable_interrupts(GLOBAL); //Timer2 Interrupt freigeben
enable_interrupts(INT_TIMER2); //Timer2 Interrupt freigeben
while(TRUE);
}
#INT_TIMER2
void Timer2_ISR(void)
{
printf("\r\nHello timer world\r\n");
} |
But still it doesn't work.
Notice: As mentioned above this is the Ex_PCD_Bootload.c sample from CCS, so it is relocated in program memory. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 10, 2014 2:02 am |
|
|
I question how that compiles, or if you tested it, because according to the
PCD compiler manual the correct form is:
Quote: |
enable_interrupts(INTR_GLOBAL); |
|
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Fri Jan 10, 2014 2:06 am |
|
|
arnadan wrote: | Yes I just noticed that I forgot that. Added it now:
Code: |
void main()
{
delay_ms(100);
printf("\r\nApplication Version 1.0\r\n");
printf("\r\nHere is some code now:");
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_8);
set_timer2(0xCF2B); //Setzwert für 10ms-Ueberlauf
enable_interrupts(GLOBAL); //Timer2 Interrupt freigeben
enable_interrupts(INT_TIMER2); //Timer2 Interrupt freigeben
while(TRUE);
}
#INT_TIMER2
void Timer2_ISR(void)
{
printf("\r\nHello timer world\r\n");
} |
But still it doesn't work.
Notice: As mentioned above this is the Ex_PCD_Bootload.c sample from CCS, so it is relocated in program memory. |
You are using printf both inside and outside the interrupt handler. This is a novice mistake. Easy rule of thumb - don't put printf's in interrupt handlers. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
arnadan
Joined: 11 Nov 2013 Posts: 13
|
|
Posted: Fri Jan 10, 2014 2:13 am |
|
|
OK: Printf in interrupt not a good idea, but its only a test program. Interrupts are enabled correctly. How I know this:
If I compile and download the program using ICD-U64 programmer everything works fine!
ONLY if I relocate the program (by including PCD_Bootloader.h) the program does not work anymore.
Maybe I should not have posted my example at all but just simple asked:
Can anybody provide a CCS Ex_PCD_Bootload.c sample (which is in the samples directory) that does contain some interrupt handler? |
|
|
arnadan
Joined: 11 Nov 2013 Posts: 13
|
|
Posted: Thu Jan 16, 2014 12:30 am |
|
|
After contacting their support CCS found the root cause of my problem:
"There is a compiler bug with the jump_to_isr() function when compiling a multiple compilation unit that is causing the problem you have having."
Thank you CCS for the support. Hope this bug will be fixed soon. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1345
|
|
Posted: Thu Jan 16, 2014 7:47 am |
|
|
You can work around that by #including the .c files at the bottom of your main file and setting the project to only compile the main file. Not the most elegant method, but I do it all the time (there are other bugs with multi-comp) |
|
|
arnadan
Joined: 11 Nov 2013 Posts: 13
|
|
Posted: Fri Feb 07, 2014 6:30 am |
|
|
The bug has meanwhile been fixed by CCS. But as Jeremiah wrote there seem to be other bugs with multi-comp. So thanks Jeremiah for your suggestion: that's the way I am going to build my projects. now! |
|
|
|