CAN bus interrupts on PIC32
CAN bus interrupts on PIC32
I am trying to get CAN bus interrupts working, at the moment without any success.
I have two easyPIC Fusion v7 boards with PIC32MX795F512L mcu cards which are properly connected and successfully pass CAN messages back and forth. I am now trying to add a CAN receive interrupt.
I have enabled interrupts, set the CAN2 interrupt priority and enabled both the CAN2 interrupt and CAN2 Receive Buffer interrupts.
EnableInterrupts();
CAN2IP0_bit = 1; // Set CAN2 interrupt priority
CAN2IP1_bit = 1; // to level 6
CAN2IP2_bit = 1;
CAN2IE_bit = 1;
RBIE_C2INT_bit = 1;
I have also defined an interrupt service routine
void C2Interrupt() iv IVT_CAN_2 ilevel 7 ics ICS_AUTO
{
STATUS_LED = ~STATUS_LED;
}
While CAN messages are received the interrupt service routine is never called.
It is always possible I am doing something dumb...
Can anyone help.
Thanks
I have two easyPIC Fusion v7 boards with PIC32MX795F512L mcu cards which are properly connected and successfully pass CAN messages back and forth. I am now trying to add a CAN receive interrupt.
I have enabled interrupts, set the CAN2 interrupt priority and enabled both the CAN2 interrupt and CAN2 Receive Buffer interrupts.
EnableInterrupts();
CAN2IP0_bit = 1; // Set CAN2 interrupt priority
CAN2IP1_bit = 1; // to level 6
CAN2IP2_bit = 1;
CAN2IE_bit = 1;
RBIE_C2INT_bit = 1;
I have also defined an interrupt service routine
void C2Interrupt() iv IVT_CAN_2 ilevel 7 ics ICS_AUTO
{
STATUS_LED = ~STATUS_LED;
}
While CAN messages are received the interrupt service routine is never called.
It is always possible I am doing something dumb...
Can anyone help.
Thanks
Re: CAN bus interrupts on PIC32
I only see one thing with your code.
I would not call EnableInterrupts() until after all the other setup is complete. It probably doesn't matter, but I don't see anything else glaring.
Please keep us posted on this subject, there is some CAN interest here..
I would not call EnableInterrupts() until after all the other setup is complete. It probably doesn't matter, but I don't see anything else glaring.
Please keep us posted on this subject, there is some CAN interest here..
Re: CAN bus interrupts on PIC32
Thanks for taking the time to reply.
I have tried EnableInterrupts() at the start before any other initialization and after all of the other initialization is complete. Either way no CAN interrupt. My other interrupts including Timers work as intended.
I am still investigating and will update the forum with what I find. Any suggestions would be gratefully received.
Thanks again
I have tried EnableInterrupts() at the start before any other initialization and after all of the other initialization is complete. Either way no CAN interrupt. My other interrupts including Timers work as intended.
I am still investigating and will update the forum with what I find. Any suggestions would be gratefully received.
Thanks again
- dejan.odabasic
- mikroElektronika team
- Posts: 2649
- Joined: 30 Apr 2012 14:20
Re: CAN bus interrupts on PIC32
Hello,
You can look at CAN interrupt as Interrupt Controller inside of "main" Interrupt Controller.
Beside enabling CAN interrupt, you need to specify which of CAN's many interrupts will be enabled.
Please take a look at explanation of CiINT: CAN INTERRUPT REGISTER.
Every enabled CAN interrupt will rise the IFS1bits.CAN2IF.
Please take a look at following document:
http://ww1.microchip.com/downloads/en/D ... 61154C.pdf
On page 90 you can find block diagram of interrupt controller.
Best regards.
You can look at CAN interrupt as Interrupt Controller inside of "main" Interrupt Controller.
Beside enabling CAN interrupt, you need to specify which of CAN's many interrupts will be enabled.
Please take a look at explanation of CiINT: CAN INTERRUPT REGISTER.
Every enabled CAN interrupt will rise the IFS1bits.CAN2IF.
Please take a look at following document:
http://ww1.microchip.com/downloads/en/D ... 61154C.pdf
On page 90 you can find block diagram of interrupt controller.
Best regards.
Re: CAN bus interrupts on PIC32
Hello I realise this is an old thread but where can I find a list of the available SFRs
as per code included from the Interrupt assistant ? They are not in the help file.
I have looked at the Datasheet re: IFS1bits.CAN2IF so if I wish to configure manually what is the syntax ?
e.g.
CAN2IP0_bit = 1; // Set CAN2 interrupt priority
CAN2IP1_bit = 1; // to level 6
CAN2IP2_bit = 1;
CAN2IE_bit = 1;
RBIE_C2INT_bit = 1;
I am using a PIC32MX570F512 with a single CAN controller on board (CAN1).
The TX is fine but I cannot get the RX to work with the CAN1Read function or interrupts.
I would like to look at the errors coming from the CAN registers if possible.
I have had it working on the PIC32MX795 device.
Thanks
Paul
as per code included from the Interrupt assistant ? They are not in the help file.
I have looked at the Datasheet re: IFS1bits.CAN2IF so if I wish to configure manually what is the syntax ?
e.g.
CAN2IP0_bit = 1; // Set CAN2 interrupt priority
CAN2IP1_bit = 1; // to level 6
CAN2IP2_bit = 1;
CAN2IE_bit = 1;
RBIE_C2INT_bit = 1;
I am using a PIC32MX570F512 with a single CAN controller on board (CAN1).
The TX is fine but I cannot get the RX to work with the CAN1Read function or interrupts.
I would like to look at the errors coming from the CAN registers if possible.
I have had it working on the PIC32MX795 device.
Thanks
Paul
Re: CAN bus interrupts on PIC32
Use CTRL+ALT+D to open MCU definition file.
Regards
Regards
Re: CAN bus interrupts on PIC32
Thank you aCkO, I found them in the end, but that shortcut is much easier!
Re: CAN bus interrupts on PIC32
Hello,
I apologize but I did not understand how to solve the problem, I am in the same situation,
I have enabled it as an example above:
and declared my funcion interrup in main file, but my interrupt still does not go
can you help me
please
I apologize but I did not understand how to solve the problem, I am in the same situation,
I have enabled it as an example above:
Code: Select all
CAN2IP0_bit = 1; // Set CAN2 interrupt priority
CAN2IP1_bit = 1; // to level 6
CAN2IP2_bit = 1;
CAN2IE_bit = 1;
RBIE_C2INT_bit = 1;
can you help me
please
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: CAN bus interrupts on PIC32
Hi,
Could you please provide us with more details?
Could you post a minimal project (zipped) for inspection?
Kind regards,
Could you please provide us with more details?
Could you post a minimal project (zipped) for inspection?
Kind regards,
Stefan Filipović
Re: CAN bus interrupts on PIC32
hi Stefan,
tnks for your reply.
I'm using mikroc pro for Pic32 whit 2 evaluation EV board Easy pic fusion, i'm tring can bus communication using the standard can bus example, in the board n°2 i have changed the fw to use the canbus with in interrupt-mode and not in polling mode but not work and unfortunately i' m not sure of my configuration.
i'm also sniffing the can bus and i see the communicaton who start of the first board but the second board not reply, because the interrupt not is active.
in attach my software interrupt
Regard
P
tnks for your reply.
I'm using mikroc pro for Pic32 whit 2 evaluation EV board Easy pic fusion, i'm tring can bus communication using the standard can bus example, in the board n°2 i have changed the fw to use the canbus with in interrupt-mode and not in polling mode but not work and unfortunately i' m not sure of my configuration.
i'm also sniffing the can bus and i see the communicaton who start of the first board but the second board not reply, because the interrupt not is active.
in attach my software interrupt
Regard
P
- Attachments
-
- CAN 2nd - Interrupt.zip
- (214.86 KiB) Downloaded 118 times
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: CAN bus interrupts on PIC32
Hi,
I believe you need to enable this bit as well:
Kind regards,
I believe you need to enable this bit as well:
Code: Select all
MODIE_C2INT_bit = 1;
Stefan Filipović
Re: CAN bus interrupts on PIC32
Tnks,
The interupt are now enabled, but i'm a problem to read the data.
it seem who the library can not read the data buffer.
this is now my configuration:
register initialization:
and ISR:
When the interrupt is generated the Msg_Rcvd is == 0 as it can not rad the data..
TNKS
The interupt are now enabled, but i'm a problem to read the data.
it seem who the library can not read the data buffer.
this is now my configuration:
register initialization:
Code: Select all
CAN2IP0_bit = 1;
CAN2IP1_bit = 1;
CAN2IP2_bit = 1;
RBIE_C2INT_bit =1;
MODIE_C2INT_bit = 1;
CAN2IE_bit = 1;
RXNEMPTYIF_C2FIFOINT1_bit = 1;
EnableInterrupts();
Code: Select all
void Can2_interrupt() iv IVT_CAN_2 ilevel 7 ics ICS_SRS
{
Msg_Rcvd = CAN2Read(&Rx_ID , RxTx_Data , &Rx_Data_Len, &Can_Rcv_Flags); // receive message
LATD = Can_Rcv_Flags;
if ((Rx_ID == ID_1st) && Msg_Rcvd ) { // if message received check id
LATB = RxTx_Data[0]; // id correct, output data at PORTB
RxTx_Data[0]++;
RxTx_Data[1]='c'; //c = 99d
CAN2Write(ID_2nd, RxTx_Data, 2, Can_Send_Flags); // send incremented data back
}
LATA = ~LATA;
}
TNKS
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: CAN bus interrupts on PIC32
Hi,
It worked well on my hardware, please find the test projects I've used for the test in the attachment.
Make sure to add a 120 Ohm resistor between CAN H and L lines as specified by CAN bus protocol. (if you do not have this resistor, you can try with some other)
Kind regards,
It worked well on my hardware, please find the test projects I've used for the test in the attachment.
Make sure to add a 120 Ohm resistor between CAN H and L lines as specified by CAN bus protocol. (if you do not have this resistor, you can try with some other)
Kind regards,
- Attachments
-
- CAN 2nd - Interrupt.zip
- (234.31 KiB) Downloaded 147 times
-
- CAN 1st.zip
- (206.78 KiB) Downloaded 134 times
Stefan Filipović
Re: CAN bus interrupts on PIC32
TNKS Stefan,
all work fine.
P
all work fine.
P
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30