Page 1 of 1

Wake Up from CAN_BUS

Posted: Thu May 04, 2017 12:50 pm
by Barmaley_GMN
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?

Re: Wake Up from CAN_BUS

Posted: Thu May 04, 2017 6:12 pm
by QMESAR
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.

Re: Wake Up from CAN_BUS

Posted: Fri May 05, 2017 6:18 am
by Barmaley_GMN
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?

Re: Wake Up from CAN_BUS

Posted: Fri May 05, 2017 8:02 am
by QMESAR
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

Re: Wake Up from CAN_BUS

Posted: Fri May 05, 2017 2:16 pm
by Barmaley_GMN

Code: Select all

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

st_bit(pie3, WAKIE);
This way?

Re: Wake Up from CAN_BUS

Posted: Fri May 05, 2017 5:24 pm
by Benj
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

Re: Wake Up from CAN_BUS

Posted: Sat May 06, 2017 6:33 am
by Barmaley_GMN
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.

Re: Wake Up from CAN_BUS

Posted: Sat May 06, 2017 8:55 pm
by Barmaley_GMN
TimerSleep.fcf
(17.5 KiB) Downloaded 401 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.

Re: Wake Up from CAN_BUS

Posted: Mon May 08, 2017 9:42 pm
by Barmaley_GMN

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
}

Re: Wake Up from CAN_BUS

Posted: Fri Jan 25, 2019 9:33 pm
by Barmaley_GMN
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?

Re: Wake Up from CAN_BUS

Posted: Mon Jan 28, 2019 2:50 pm
by Barmaley_GMN
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