CAN initialisation on mcf5235evb ColdFire

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CAN initialisation on mcf5235evb ColdFire

1,717 Views
neodelphi
Contributor I
Hi,

I'm currently working on a ColdFire mcf5235evb. I asked for some help a few weeks ago but I did'nt get any response. I still have problems to make the CAN module working correctly. However I changed a lot of things in my code. I wanted first to activate loopback mode because I don't have another node yet on the bus.

After CAN initialisation procedure, I try to read the value of one buffer control word, to check if the code is 0b1000 (TX not ready), but I get 0b0000 which is strange. I have read the Datasheet many times and I don't find where the problem is. Here is my code:

    // Select clock
    MCF_CAN_CANMCR(CAN_SEL) |= MCF_CAN_CANCTRL_CLKSRC;  
    // Activate CAN module (after the clock selection)
    MCF_CAN_CANMCR(CAN_SEL) &= ~MCF_CAN_CANMCR_MDIS;

    // Timing configuration
    MCF_CAN_CANCTRL(CAN_SEL) = MCF_CAN_CANCTRL_PRESDIV(CAN_PRESCALER)
        | MCF_CAN_CANCTRL_RJW(0)
        | MCF_CAN_CANCTRL_PSEG1(2)
        | MCF_CAN_CANCTRL_PSEG2(2)
        | MCF_CAN_CANCTRL_CLKSRC
        | MCF_CAN_CANCTRL_LPB
        | MCF_CAN_CANCTRL_LBUF
        | MCF_CAN_CANCTRL_PROPSEG(0);

    // Buffers initialisation
    uint32 x = (0x08 << 24) // Code
        | (1 << 22) // Substitue remote request
        | (1 << 21) // Extended mode
        | (1 << 16); // Data length
    MCF_CAN_MBUF0_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF1_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF2_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF3_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF4_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF5_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF6_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF7_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF8_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF9_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF10_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF11_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF12_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF13_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF14_CTRL(CAN_SEL) = x;
    MCF_CAN_MBUF15_CTRL(CAN_SEL) = x;

    MCF_CAN_MBUF0_ID(CAN_SEL) = 1;
    MCF_CAN_MBUF1_ID(CAN_SEL) = 2;
    MCF_CAN_MBUF2_ID(CAN_SEL) = 3;
    MCF_CAN_MBUF3_ID(CAN_SEL) = 4;
    MCF_CAN_MBUF4_ID(CAN_SEL) = 5;
    MCF_CAN_MBUF5_ID(CAN_SEL) = 6;
    MCF_CAN_MBUF6_ID(CAN_SEL) = 7;
    MCF_CAN_MBUF7_ID(CAN_SEL) = 8;
    MCF_CAN_MBUF8_ID(CAN_SEL) = 9;
    MCF_CAN_MBUF9_ID(CAN_SEL) = 10;
    MCF_CAN_MBUF10_ID(CAN_SEL) = 11;
    MCF_CAN_MBUF11_ID(CAN_SEL) = 12;
    MCF_CAN_MBUF12_ID(CAN_SEL) = 13;
    MCF_CAN_MBUF13_ID(CAN_SEL) = 14;
    MCF_CAN_MBUF14_ID(CAN_SEL) = 15;
    MCF_CAN_MBUF15_ID(CAN_SEL) = 16;

    // RXGMASK0, RX14MASK0 and RX15MASK0
    // 0 = don't care
    MCF_CAN_RXGMASK(CAN_SEL) = 0x00000000;
    MCF_CAN_RX14MASK(CAN_SEL) = 0x00000000;
    MCF_CAN_RX15MASK(CAN_SEL) = 0x00000000;
   
    MCF_CAN_IMASK(CAN_SEL) = 0x00000000;
   
    // Leave freezemode
    MCF_CAN_CANMCR(CAN_SEL) &= ~MCF_CAN_CANMCR_HALT;

Another thing I don't understand: when I try to leave freeze mode, the HALT flag becomes 0 but the FRZ flag stays at 1 - FRZACK=0. ERRSTAT and ERRCOUNT stays at 0, only the flag IDLE is high. If anybody see something bad, please tell me ! Thanks for your help.

Olivier Heriveaux
Labels (1)
0 Kudos
2 Replies

322 Views
neodelphi
Contributor I
Hi ! Thank you for your answer. I had a look at your example, but I found the problem by having a deeper look inside the headers. I made a confusion between the datasheet and the headers. In datasheet is written that the Control/status register of the first message buffer is located at the address 0x80 (+ offset). That's why I wrote this code:

    uint32 x = (0x08 << 24) // Code
        | (1 << 22) // Substitue remote request
        | (1 << 21) // Extended mode
        | (1 << 16); // Data length
    MCF_CAN_MBUF0_CTRL(CAN_SEL) = x;

But in reality the MCF_CAN_MBUF0_CTRL macro writes a 16 bit word, so it must be used to write the high part of Control/Status register. This is the corrected code:

    uint16 x = (0x08 << 8) // Code
        | (1 << 6) // Substitue remote request
        | (1 << 5) // Extended mode
        | 1; // Data length
    MCF_CAN_MBUF0_CTRL(CAN_SEL) = x;

Maybe a little change in datasheet could avoid such confusion. What do you think about this ?
 
+-----------------+             +-----------+----------+
| Control/Status  |      =>     | Control   | Status   |
+-----------------+             +-----------+----------+

Now I get a nice CAN signal on my Oscilloscope :smileyvery-happy: and I'm waiting for my friend to receive the message !

Thanks !
Olivier Heriveaux
0 Kudos

322 Views
carlos_chavez
NXP Employee
NXP Employee
Hello Olivier,
 
Have you taken a look at our ColdFire Initialization Template for the MCF5235?  It can be found at: http://www.freescale.com/webapp/sps/download/license.jsp?colCode=MCF523XSC&location=null&fpsp=1.  Within the ColdFire Initialization Template there is a CodeWarrior Project and under that there is a target called FAT (Factory Acceptance Test).  In the FAT target, you will find a FlexCAN Test that we use to send test messages betwee the two CANs on the EVB.  You can easily modify it to make it do an internal loopback.  This should provide you with a good start.
 
Please let me know if you have any further questions and I will be happy to answer them.
 
Regards,
Carlos
0 Kudos