This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Problems determining transmission direction of CAN messages through IF1/IF2

Other Parts Discussed in Thread: HALCOGEN

Hi @ all,

I have got a weird problem determining the transmission direction of CAN messages in the message RAM. Due to auto-code portions in my project I am unable to predetermine the message direction and have to distinguish it during runtime.

Therefor I used the following code snippet:

"for (ctr_msgbox=1;ctr_msgbox<=64;ctr_msgbox++){

if ( canIsMessageBoxValid( canREG1, ctr_msgbox ) ){

// check whether message is a transmit message

while ((canREG1->IF2STAT & 0x80U) ==0x80U){

}/* wait */

buffer = canREG1->IF2CMD;

canREG1->IF2CMD = 0x20; // read arb field from ram only

canREG1->IF2NO = (uint8) ctr_msgbox; // set actual message box number

while ((canREG1->IF2STAT & 0x80U) ==0x80U){

}/* wait */

dir = (uint8) ( (uint32) ((canREG1->IF2ARB & (1<<29) )>>29)); // mask tx/rx bit

if ( dir ){

// if message is tx messages, then send through CAN driver

canTransmit(canREG1, ctr_msgbox, &tx_data[0]);

}

}

}"

This one works fine, but a susequent function doing the same for the receive direction is unable to detect the right tx/rx bit! Is there a structural problem in the code?

It seems as a subsequent call of canIsRxMessageArrived( ) is unable to get a actual value. This leads to a permanent call canGetData() although no new message were transmitted to the system:

"for(ctr_msgbox=1;ctr_msgbox<=64;ctr_msgbox++){

if ( canIsMessageBoxValid( canREG1, ctr_msgbox ) ){

// check whether message is receive message

while ((canREG1->IF1STAT & 0x80U) ==0x80U){

}/* wait */

buffer = canREG1->IF1CMD;

canREG1->IF1CMD = 0x20;

canREG1->IF1NO = (uint8) ctr_msgbox;

while ((canREG1->IF1STAT & 0x80U) ==0x80U){

}/* wait */

dir = (uint8) ( (uint32) ((canREG1->IF1ARB & (1<<29) )>>29));

if ( !dir ){

if ( canIsRxMessageArrived( canREG1, ctr_msgbox ) ){

canGetData(canREG1, ctr_msgbox, &rx_data[0]);

}

}

}

}"

CAN driver was generated with HALCOGEN 03.06.00

Hercules RM48L952ZWT on control card

 

Thanks in advance for any hints and remarks!

 

  • Hi Rene,

    Would it be possible for you to either try the latest HalCoGen 4.0.0  or to post the generated files?
    The version 3.0.6 is quite old now and this could very well be something that was a bug in 3.0.6 and fixed already.

    I'd want to check the actual register reads/writes that are done inside the functions pasted above, the CAN interface register set is pretty picky w. respect to reads & writes.

    Also, are you running the above code from inside an ISR or task where there might be a problem with nesting.  The CAN IF registers really can't be shared by two different tasks where one might interrupt the other.  (IF1 and IF2 in two different tasks are ok, but using IF2 between two different ones would get hairy...)

  • Hi Anthony,

    the update to HalCoGen 4.0.0 did not change anything.

    Nesting was the problem:

    In HalCoGen CAN1 Hi Int was activated and additionally I started the routine mentioned every 100 ms (by rti).

    The deactivation of this interrupt solved the problem.

    Thanks a lot for your advice concerning nesting!

    Best regards,

    René