Wake Up from CAN_BUS

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Wake Up from CAN_BUS

Postby Barmaley_GMN » Thu May 04, 2017 12:50 pm

Hi!
I need help)
I have Pic 18f2580 and MCP2551 connected to internal CAN-BUS.
I tried wake PIC up by RXINT, but it doesn't work.
How can I wake PIC up by activity in CAN-BUS?

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1089
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 334 times
Been thanked: 544 times
Contact:

Re: Wake Up from CAN_BUS

Postby QMESAR » Thu May 04, 2017 6:12 pm

Barmaley_GMN wrote:I tried wake PIC up by RXINT, but it doesn't work.
How can I wake PIC up by activity in CAN-BUS?


Have you configured the CAN module to wake up on RX messages?
you need to post your minimal Flowchart that shows your configuration of the CAN module.
These users thanked the author QMESAR for the post:
Benj (Fri May 05, 2017 10:57 am)
Rating: 5.56%
 

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Wake Up from CAN_BUS

Postby Barmaley_GMN » Fri May 05, 2017 6:18 am

No. I just set the timer to RXINT and set Sleep()
I don't know if the macro TMR RXINT set configuration bit for wake up by activity on RX can-bus or it makes it for UART RX.
As I see, I need to set REQOP2:REQOP0 = 001 and WAKIF = 1. That's it?

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1089
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 334 times
Been thanked: 544 times
Contact:

Re: Wake Up from CAN_BUS

Postby QMESAR » Fri May 05, 2017 8:02 am

Barmaley_GMN wrote:No. I just set the timer to RXINT and set Sleep()
I don't know if the macro TMR RXINT set configuration bit for wake up by activity on RX can-bus or it makes it for UART RX.
As I see, I need to set REQOP2:REQOP0 = 001 and WAKIF = 1. That's it?


Hi
with out seeing your Flowchart and configuration settings it is hard to help ,
According to the device datasheet in my understanding is that you have to configure a CAN wakup interrupt which will be triggered when there is a message(activity) on the bus and the device is in sleep mode,

As I see, I need to set REQOP2:REQOP0 = 001 and WAKIF = 1. That's it?


I do not think "That's it" as mentioned :D
Attachments
1.JPG
1.JPG (44.76 KiB) Viewed 5353 times
These users thanked the author QMESAR for the post:
Barmaley_GMN (Sat May 06, 2017 8:56 pm)
Rating: 5.56%
 

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Wake Up from CAN_BUS

Postby Barmaley_GMN » Fri May 05, 2017 2:16 pm

Code: Select all

cr_bit(cancon, REQOP2);
cr_bit(cancon, REQOP1);
st_bit(cancon, REQOP0);

st_bit(pie3, WAKIE);

This way?

User avatar
Benj
Matrix Staff
Posts: 14151
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4080 times
Contact:

Re: Wake Up from CAN_BUS

Postby Benj » Fri May 05, 2017 5:24 pm

Hello,

I may be wrong on this but it looks like you just need to use this C code to enable the wake from sleep and reset the interrupt flag.

Code: Select all

cr_bit(pir3, WAKIF)  //Clear interrupt flag if set - re-arm interrupt
st_bit(pie3, WAKIE);  //Enable interrupt
st_bit(intcon, PEIE);  //Enable Peripheral Interrupts
st_bit(intcon, GIE);  //Enable Global Interrupts
These users thanked the author Benj for the post (total 2):
QMESAR (Fri May 05, 2017 5:26 pm) • Barmaley_GMN (Sat May 06, 2017 8:56 pm)
Rating: 11.11%
 

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Wake Up from CAN_BUS

Postby Barmaley_GMN » Sat May 06, 2017 6:33 am

There is mistake

Code: Select all

cr_bit(pir3, WAKIF)  //Clear interrupt flag if set - re-arm interrupt
it is read only bit.
And I haven't managed to make interrupt on CAN-BUS.
It stops transmit, but doesn't wake up the chip.
Now I think the problem is in the another interrupt (I'm using 2 interrupts in one program) When the first (by timer) is run - the second(by wake up) is off. Then the first stop the second run. And the second doesn't work.

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Wake Up from CAN_BUS

Postby Barmaley_GMN » Sat May 06, 2017 8:55 pm

TimerSleep.fcf
(17.5 KiB) Downloaded 180 times

I have managed with wake up. But I used only one interrupt (by CAN activity). Now I have additional problems: after waking up it doesn't go sleep in next cycles.

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Wake Up from CAN_BUS

Postby Barmaley_GMN » Mon May 08, 2017 9:42 pm

Code: Select all

clear_bit(pir3, WAKIF); // clear interrupt

This is right way.

Interrupt
Enable code

Code: Select all

intcon.GIE = 1; // Enable global interrupts
intcon.PEIE = 1; // Enable peripheral interrupts
st_bit(cancon, REQOP0);
cr_bit(cancon, REQOP1);
cr_bit(cancon, REQOP2);
st_bit(pie3, WAKIE);  //Enable interrupt CAN

Handler code:

Code: Select all

if (pir3 & (1 << WAKIF))
{
FCM_%n(); // call selected macro
clear_bit(pir3, WAKIF); // clear interrupt
}
These users thanked the author Barmaley_GMN for the post:
Benj (Tue May 09, 2017 12:15 pm)
Rating: 5.56%
 

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Wake Up from CAN_BUS

Postby Barmaley_GMN » Fri Jan 25, 2019 9:33 pm

I need help!
Code for Pic18f2580 doesn't work with 18f25K80
I see error in text box

Code: Select all

DRL+V7-2.c(6768:23): error: unknown identifier 'REQOP0'
DRL+V7-2.c(6768:23): error: invalid operand 'REQOP0'
DRL+V7-2.c(6768:18): error: failed to generate expression
DRL+V7-2.c(6768:18): error: invalid operand '<<'
DRL+V7-2.c(6768:12): error: failed to generate expression
DRL+V7-2.c(6769:24): error: unknown identifier 'REQOP1'
DRL+V7-2.c(6769:24): error: invalid operand 'REQOP1'
DRL+V7-2.c(6769:19): error: failed to generate expression
DRL+V7-2.c(6769:15): error: invalid operand '~(1 << ( REQOP1))'
DRL+V7-2.c(6769:12): error: failed to generate expression
DRL+V7-2.c(6770:24): error: unknown identifier 'REQOP2'
DRL+V7-2.c(6770:24): error: invalid operand 'REQOP2'
DRL+V7-2.c(6770:19): error: failed to generate expression
DRL+V7-2.c(6770:15): error: invalid operand '~(1 << ( REQOP2))'
DRL+V7-2.c(6770:12): error: failed to generate expression

What can I do?

Barmaley_GMN
Posts: 59
Joined: Mon Aug 04, 2014 12:59 pm
Has thanked: 8 times
Been thanked: 4 times
Contact:

Re: Wake Up from CAN_BUS

Postby Barmaley_GMN » Mon Jan 28, 2019 2:50 pm

I have solved the problem.
18f25K80.h doesn't have these bits in cancon register unlike 18f2580.h
So I can write cancon = 0x20
or add to 18f25k80 bits intto cancon_ro7