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

Post Reply
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

Post 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?

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Wake Up from CAN_BUS

Post 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.

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

Post 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?

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: Wake Up from CAN_BUS

Post 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
Attachments
1.JPG
1.JPG (44.75 KiB) Viewed 9799 times

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

Post by Barmaley_GMN »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Wake Up from CAN_BUS

Post 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

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

Post 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.

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

Post by Barmaley_GMN »

TimerSleep.fcf
(17.5 KiB) Downloaded 398 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

Post 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
}

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

Post 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?

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

Post 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

Post Reply