CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Ex_PCD_Bootload.c with Interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
arnadan



Joined: 11 Nov 2013
Posts: 13

View user's profile Send private message

Ex_PCD_Bootload.c with Interrupt
PostPosted: Fri Jan 10, 2014 1:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 10, 2014 1:20 am     Reply with quote

Where is your line to enable Global interrupts ?
arnadan



Joined: 11 Nov 2013
Posts: 13

View user's profile Send private message

PostPosted: Fri Jan 10, 2014 1:40 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 10, 2014 2:02 am     Reply with quote

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: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jan 10, 2014 2:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 10, 2014 2:13 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 12:30 am     Reply with quote

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: 1355

View user's profile Send private message

PostPosted: Thu Jan 16, 2014 7:47 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 07, 2014 6:30 am     Reply with quote

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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group