Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User7878
Level 1
Level 1
Hi there,
I´m trying to create a program were I need to receive messages and send others for CANOPEN.
In the CANOPEN I have in the identifier message the command and the ID target.
The first seven bits is the ID target and the rest ( 4 bits) are the command.
My problem is the following:
I had configure the CANBUS to two messages (LM01 to transmit and LM02 to receive) and in the main function I force again those configuration ( this was only made to test if before the CAN002_Init() function it was able to change the ID).
In the configuration panel, the ID was 10 in the standard identifier for both LM0x.
This is the commands for CANOPEN :

#define NMT 0x0000
#define EMERCY 0x0080
#define T_PDO1 0x0200
#define T_PDO2 0x0300
#define T_PDO3 0x0400
#define T_PDO4 0x0500
#define T_SDO 0x0600

#define R_PDO1 0x0180
#define R_PDO2 0x0280
#define R_PDO3 0x0380
#define R_PDO4 0x0480
#define R_SDO 0x0580

#define HEART_BEAT 0x0700

My main function is:
int main(void) {
// status_t status; // Declaration of return variable for DAVE3 APIs (toggle comment if required)

DAVE_Init(); // Initialization of DAVE Apps
ID = 0x10; // board identifier

CAN002_MessageHandle0_1.Identifier = ID;
CAN002_MessageHandle0_1.IDEMask = 0;
CAN002_MessageHandle0_1.IDExten = 0;
CAN002_MessageHandle0_1.IDMask = 0;
CAN002_MessageHandle0_1.MsgObjEN = CAN002_ENABLE;
CAN002_MessageHandle0_1.MsgObjType = (CAN_MsgType) 1;

CAN002_MessageHandle0_2.Identifier = ID; // the ID is 0x10
CAN002_MessageHandle0_2.IDEMask = 0;
CAN002_MessageHandle0_2.IDExten = 0;
CAN002_MessageHandle0_2.IDMask = 0x07F; // for satndart MASK ID
CAN002_MessageHandle0_2.MsgObjEN = CAN002_ENABLE;
CAN002_MessageHandle0_2.MsgObjType = (CAN_MsgType) 0;

// it was commented in the DAVE. C the functions below. this was to test if before the CAN INIT was possible to change the ID. it´s possible.

CAN002_Init();
// MUX configurations
DAVE_MUX_Init();

mail = osMailCreate(osMailQ(mail), NULL);

tid_thread0 = osThreadCreate(osThread(osTimer_thread), NULL);
tid_thread1 = osThreadCreate(osThread(t1_thread), NULL);
tid_thread2 = osThreadCreate(osThread(t2_thread), NULL);
tid_thread3 = osThreadCreate(osThread(t3_thread), NULL);
tid_thread4 = osThreadCreate(osThread(t4_thread), NULL);

osKernelStart();
osDelay(osWaitForever);

while (1) {

}
return 0;
}

This Thread is to read the ISOFACE IN and put the value into CANBUS

/*----------------------------------------------------------------------------
* Thread 3: Read ISOFACE
*---------------------------------------------------------------------------*/
void t3_thread(void const *argument) {
uint8_t OLD_Isoface_In[4];
static T_MSG *msg;
CAN002_MessageHandleType TempMsgHandle;
status_t Status;
for (;;) {
Read_Isoface();
if (OLD_Isoface_In[0] != Isoface_In[0]) {
OLD_Isoface_In[0] = Isoface_In[0];
// msg = osMailAlloc(mail, osWaitForever);
// msg->b[0]=Isoface_In[0];
// msg->b[1]=Isoface_In[1];
// msg->b[2]=Isoface_In[2];
// msg->b[3]=Isoface_In[3];
// osMailPut(mail, msg);
TempMsgHandle.Identifier = (uint32_t)T_PDO1 + ID; // to config the command with the ID board
TempMsgHandle.MsgObjType = (CAN_MsgType) 1;
TempMsgHandle.MsgObjEN = CAN002_ENABLE;
TempMsgHandle.DataLength = 5;
TempMsgHandle.data[0] = Wr4Byte;
TempMsgHandle.data[1] = Isoface_In[0];
TempMsgHandle.data[2] = Isoface_In[1];
TempMsgHandle.data[3] = Isoface_In[2];
TempMsgHandle.data[4] = Isoface_In[3];


CAN002_UpdateMODataRegisters(&CAN002_Handle0, 1,
TempMsgHandle.DataLength, TempMsgHandle.data);

Status = CAN002_SendDataFrame(&CAN002_Handle0, 1, 20);

if (Status == CAN002_TIMEOUT) {
// Timeout. Data frame is not transmitted
Status = CAN002_ERROR;
CAN002_CancelTransmitReq(&CAN002_Handle0, 1);
}

}

osThreadYield();
}
/* We are done here, exit this thread */
}

The problem is the send messages has always the same identifier (0x10) when what´s was expected was " .identifier = 0x210"...
What can by done to change the message identifier and send it to CANBUS?


On the receive task I has another issue....
this is my task:
/*----------------------------------------------------------------------------
* Thread 4:Can bus Read
*---------------------------------------------------------------------------*/
void t4_thread(void const *argument) {
status_t Status;
static T_MSG *msg;
INITIALISE_RXOBJ();
uint32_t command = 0;
uint32_t Msg_ID;
for (;;) {

Status = CAN002_ReadMOwithTimeout(&CAN002_Handle0, &CanRecMsgObj, 2,
100);

//Status=CAN002_ReadMsgObj(&CAN002_Handle0,&CanRecMsgObj,2);

if (Status == DAVEApp_SUCCESS) {
Msg_ID = (CanRecMsgObj.Identifier & 0x7f); // forced to do this to filter the ID

if (Msg_ID == ID) {
command = CanRecMsgObj.Identifier & 0x780; //This is to read the command in the ID

switch (command) {
case EMERCY:
msg = osMailAlloc(mail, osWaitForever);
msg->b[0] = CanRecMsgObj.data[0];
osMailPut(mail, msg);

break;

case R_PDO1:

break;
case R_PDO2:
break;
case R_PDO3:
break;
case R_PDO4:
break;
case R_SDO:
break;

}
}

}

osThreadYield();
}


/* We are done here, exit this thread */
}

My question is:
With this, the processor spends time to reads all messages and needs to compare the identifier with is ID to read the message or not.
what was supposed to do is only enter in this function when one messages has is ID in this case 0x10... because the filter is 0x07f and not 0x7ff.... I only mask the 7 lower bits... so the 4 upper bits don´t count for the ID... It´s correct or not?

Can anyone help me with this???
I have this procedure working in the STM32F107 ( only messages with is ID is read by the processor).



Regards
Luis Silva
0 Likes
1 Reply
Not applicable
Hi Luis Silva,

This has been forwarded to our colleague who has experience on this application. Will update you once get the reply.

Best regards,
Sophia
0 Likes