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 support@ccsinfo.com

TBE2 interrupt (UART2) causing address error exception

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



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

TBE2 interrupt (UART2) causing address error exception
PostPosted: Wed Nov 13, 2013 1:31 pm     Reply with quote

Processor: dsPIC33FJ256GP710A
Compiler: v4.141

Finally managed to track down what is happening but I have no idea why. Simply trying to use the TBE2 interrupt to send a message out via UART2 immediately causes an address error exception. Code is way too big to post here.

I'm leaning toward the interrupt vector for TBE2 being wrong. Any ideas?
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Wed Nov 13, 2013 2:28 pm     Reply with quote

Tiny update: interrupt vector is fine. TBE2 isr fires exactly once, then the address exception is thrown either upon exit from the isr, or shortly thereafter.
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Wed Nov 13, 2013 2:34 pm     Reply with quote

Try increasing the stack size.

Best Wishes
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Wed Nov 13, 2013 2:42 pm     Reply with quote

Stack was ridiculously oversized already. Doubling it has no effect. Edit: as does quadrupling it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Wed Nov 13, 2013 2:56 pm     Reply with quote

OK. Worth checking. You say 'ridiculously oversized'. You do realise that the stack on PIC33's, has to hold a lot of variables used locally by functions, not just the return addresses?. So a program with say function stack usage of just ten levels, may well need 500+ bytes of stack space. The default from CCS is often too small, especially if a lot of arithmetic is used. It's also possible to make any stack size overflow if (for instance), there is accidental recursion.
Your best bet, is to trap the exception interrupt and find what address the exception is coming from.

Best Wishes
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Wed Nov 13, 2013 3:29 pm     Reply with quote

Thanks for the tips, will try and deduce the address right away. Right now my stack size is 4096 (I know, too lazy to go back and find something more reasonably sized), but I tried 8192 and 16384 with no change in behaviour.
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Thu Nov 14, 2013 2:03 am     Reply with quote

OK. Yes I'll accept your stack _is_ 'ridiculously large'....

The default, is undersized when code starts to get more complex, and often throws this problem.

You don't need to 'deduce' the address, but just read it. It is on the stack, if you add code to trap the error.

Best Wishes
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Thu Nov 14, 2013 10:27 am     Reply with quote

After the return from the first TBE2 isr, the program counter is pointing to 0x7FFFC, which isn't valid for the processor. Someone at CCS is digging through the list file to try & find a reason why.

...Will report when I know more.
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Thu Nov 14, 2013 11:46 am     Reply with quote

Have you looked at section 11 of the errata sheet?.
Does your TX interrupt do this?.

It is not stated what the effect of the premature interrupt will be if you load data at this point (I'd have guessed data corruption, rather than major crashing), but it does mean you possibly need to rethink using the TBE interrupt, Possibly use a timer interrupt at the character time, and send in this, rather than using TBE.

Best Wishes
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Thu Nov 14, 2013 12:12 pm     Reply with quote

Not applicable as I'm not using that mode, but out of desperation I did try the workaround. No change in behaviour.

The TBE2 code is identical to code associated with TBE/UART1. UART1's TBE code works flawlessly, UART2's causes an address exception.

CCS is on it. Seems as though I piqued their curiosity yesterday. Sent them the register dump they requested a few hours ago, with no reply yet.
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Fri Nov 15, 2013 2:22 pm     Reply with quote

Problem gets stranger....

So that I could work on other aspects of the project, I commented out the code that was causing the problem (a periodic transmit of a message on UART2, which in turn employed the TBE2 interrupt to actually send the message). As it was, the project did work prior to the tweaks. All I did was clean some things up.

Now that the rest of it is cleaned, I decided to try uncommenting the offending code. ....And the TBE2 isr() no longer generates an address exception.

I'm grateful that the problem has gone away, but I really hate that I don't know why!

Edit: the TBE2 isr() code didn't change either.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Nov 15, 2013 3:00 pm     Reply with quote

1. I'm convinced that address errors can be traced down to the primary cause, at least if they occur repeatedly.

As Ttelmah mentioned, it might be a silicon bug.

2. I think, the guesses about a stack overflow are essentially wrong. A stack overflow would trigger a trap on it's own.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Fri Nov 15, 2013 4:03 pm     Reply with quote

The problem with things that mysteriously "fix themselves" is that sooner or later, they tend to "un-fix themselves" (usually at a very inconvenient time). Be sure and let us know if you do find out what the actual cause is on this one Very Happy

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
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