Hi, my name is Xavier.
I have a problem with CAN interruption with MPC5604.
In the first message, i have the interruption, then I read the length of the message , but when i recieve the next message the interruption don´t occur again, only occur when change to another buffer or without reading the length of the message.
I read it with this command:
dummy = CAN_0.BUF[buffer_lectura].CS.B.LENGTH;
This is my code:
#include "MPC5604P.h"
#include "IntcInterrupts.h"
#include "INIT.h"
#include "Definicions.h"
#include "Variables_globals.h"
#define LLIBRERIA
//++++++++++++++++++++++++++++INTERRUPCIONS++++++++++++++++++++++++++++++++++++++++++++++++++
/*----------------- Rutina de servei a la interrupcio del CAN0 BUFFER 8-11 ------------------
/* Interrupcio del PC per a carregar totes les taules en memoria
-------------------------------------------------------------------------------------------*/
static void CAN0_ISR_TAULES (void) {
if (nova_taula == 0) {
nova_taula = 1;
if (CAN_0.IFRL.B.BUF08I == 1) { // TAULA PUNTS I AILLAMENTS
dummy = CAN_0.TIMER.R;
buffer_lectura = 8;
CAN_0.IFRL.B.BUF08I = 1;
}
if (CAN_0.IFRL.B.BUF09I == 1) { // TAULA CONTINUITAT
dummy = CAN_0.TIMER.R;
buffer_lectura = 9;
CAN_0.IFRL.B.BUF09I = 1;
}
if (CAN_0.IFRL.B.BUF10I == 1) { // TAULA CIRCUITS
dummy = CAN_0.TIMER.R;
buffer_lectura = 10;
CAN_0.IFRL.B.BUF10I = 1;
}
if (CAN_0.IFRL.B.BUF11I == 1) { // TAULA DETECCIONS
dummy = CAN_0.TIMER.R;
buffer_lectura = 11;
CAN_0.IFRL.B.BUF11I = 1;
}
nova_taula = 0;
}
else {
//Send_Head(CAN_0.BUF[buffer_lectura].DATA.B[0], Mis_Error, codi_test, 0, 1); // ENVIAR ERROR
CAN_0.IFRL.R |= 0x00000F00;
}
}
/*----------------- Rutina de servei a la interrupcio del CAN0 BUFFER 0-3 -------------------
* Interrupcio del PC per realitzar una nova comanda. General o particular. Amb o sense LOG's
--------------------------------------------------------------------------------------------*/
static void CAN0_ISR_COMANDES (void) { // Interrupcions CAN Buffer 0. Podem detectar que arrivi una operacio, abans d'acabar l'anterior
if (nova_operacio == 0) {
if (CAN_0.IFRL.B.BUF00I == 1) { // Comanda General + LOG
nova_operacio = 1;
buffer_lectura = 0;
LOGS++;
codi_test = CAN_0.BUF[buffer_lectura].DATA.B[1];
//dummy = CAN_0.BUF[buffer_lectura].CS.B.LENGTH; // Read the size of CAN message
CAN_0.IFRL.B.BUF00I = 1;
}
if (CAN_0.IFRL.B.BUF01I == 1) { // Comanda General
nova_operacio = 1;
buffer_lectura = 1;
codi_test = CAN_0.BUF[buffer_lectura].DATA.B[1];
//dummy = CAN_0.BUF[buffer_lectura].CS.B.LENGTH; // Read the size of CAN message
CAN_0.IFRL.B.BUF01I = 1;
}
if (CAN_0.IFRL.B.BUF02I == 1) { // Comanda Propia + LOG
nova_operacio = 1;
buffer_lectura = 2;
LOGS++;
codi_test = CAN_0.BUF[buffer_lectura].DATA.B[1];
//dummy = CAN_0.BUF[buffer_lectura].CS.B.LENGTH; // Read the size of CAN message
CAN_0.IFRL.B.BUF02I = 1;
}
if (CAN_0.IFRL.B.BUF03I == 1) { // Comanda Propia
nova_operacio = 1;
buffer_lectura = 3;
codi_test = CAN_0.BUF[buffer_lectura].DATA.B[1];
//dummy = CAN_0.BUF[buffer_lectura].CS.B.LENGTH; // Read the size of CAN message
CAN_0.IFRL.B.BUF03I = 1;
}
}
else {
//Error = 1;
//Send_Head(CAN_0.BUF[buffer_lectura].DATA.B[0], Mis_Error, 0x01, codi_test, 2); // ENVIAR ERROR
CAN_0.IFRL.R |= 0x0000000F;
}
}
//++++++++++++++++++++++++++++ PRINCIPAL +++++++++++++++++++++++++++++++++++++++++++++++++++++
int main(void)
{
int i = 0;
/* INICIALITZACIONS */
InitCMU_0(); // 8 MHz OSC requires non-default CMU_0 init
InitModesAndClks(); // Initialize mode entries
DisableWatchdog(); // Disable watchdog
initPeriClkGen();
InitGPIO(); // Initialize GPIO Pins
INTC_InstallINTCInterruptHandler(CAN0_ISR_TAULES,70,14); // INIT FlexCAN Interrupt MB 8-11
INTC_InstallINTCInterruptHandler(CAN0_ISR_COMANDES,68,13); // INIT FlexCAN Interrupt MB 0-3
EnableIrq(); // General Enable for ISR
Clr_LedErr();
Set_LedAlim();
// LLEGIR DEL POTENCIOMETRE EL ID
ID = 49; // ID = Carta
ID_Buffers = ID<<4; // ID_Buffers = Carta + 0000
// CONFIGURAR CAN UN COP TENIM EL ID
InitCAN_0();
InitCAN_1();
/* TEST */
while (1)
{
if (nova_operacio) // Nova operacio. Cada interrupcio del BUF04 de CAN
{
nova_operacio = 0;
//dummy = CAN_0.BUF[buffer_lectura].CS.B.LENGTH; // Read the size of CAN message
}
}
}
Solved! Go to Solution.
Hello,
the problem is, that when you read the length of the message, you lock message buffer and this remains lock. Please check the the figure below:
I also recommend you to read chapter Mailbox lock mechanism.
If you have any other questions, please feel free to write me back.
Regards,
Martin
Hello,
the problem is, that when you read the length of the message, you lock message buffer and this remains lock. Please check the the figure below:
I also recommend you to read chapter Mailbox lock mechanism.
If you have any other questions, please feel free to write me back.
Regards,
Martin