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

CANbus not working after a few messages

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



Joined: 23 Jun 2010
Posts: 7

View user's profile Send private message

CANbus not working after a few messages
PostPosted: Mon Jul 05, 2010 3:19 am     Reply with quote

Hi. I am working on a CAN bus project. There are two (actually many but for now only two) nodes on bus, each of them is a 18F458 (with MCP2551 of course) connected to LCDs. In one of them, two buttons are connected to ext interrupt 0 and 1 as well (a main node). I use interrupts for CAN communication as well.

Now when I press button 0 at main node, other should display "Kat: 0", and when I press button 1 other should display "Kat: 1". As I continuously press buttons, after a few correct displays at other node, it stops changing the display as I press other button, the same number stays at display. Interestingly, this "a few times" of correct display also changes. Sometimes it goes for 7-8 correct displays, sometimes after only 2 displays (i.e. I press both buttons only once) they stop changing. When I reset the other PIC (and not reset main PIC), it again changes correctly. Can anybody see what is the problem?

I constructed my circuit on breadboards. My compiler version is 4.068.

By the way, do I need to clear interrupts at the end of isr or does compiler clear them automatically?

Thanks for help.

Code:

Removed


Last edited by smoglu on Mon Jul 05, 2010 9:20 am; edited 1 time in total
newguy



Joined: 24 Jun 2004
Posts: 1902

View user's profile Send private message

PostPosted: Mon Jul 05, 2010 7:17 am     Reply with quote

Your problem is that you're doing something (printing to the LCD) which takes a LONG time, inside an interrupt service routine. If a new CAN message arrives before the first ISR has been serviced, bad things can happen (as you've seen).

Change your code to do virtually nothing inside of an ISR. Simply set a flag (eg message_received = TRUE;), which your main() loop will see and act upon. You won't see this problem again.
smoglu



Joined: 23 Jun 2010
Posts: 7

View user's profile Send private message

PostPosted: Mon Jul 05, 2010 9:16 am     Reply with quote

newguy wrote:
Your problem is that you're doing something (printing to the LCD) which takes a LONG time, inside an interrupt service routine. If a new CAN message arrives before the first ISR has been serviced, bad things can happen (as you've seen).

Change your code to do virtually nothing inside of an ISR. Simply set a flag (eg message_received = TRUE;), which your main() loop will see and act upon. You won't see this problem again.


Thank you very much, this method just worked. Problem resolved. Actually, I just realized that compiler was printing warnings saying that interrupts are disabled during that calls like lcd_putc (while compiling the original code). That was causing problem.
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