MCF5213 problems

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

MCF5213 problems

4,998 Views
Simone
Contributor II
Hello everybody!
 
I'm working on a MCF5213, and I'm trying to setting up the Flexcan controller.
I see on the datasheet that the CANMCR register is 32 bit width, but the codewarrior ide says that it's only 16 bit. Who's right?
By the way, isn't there anybody who has a piece of working code to make the preliminary test on the flexcan controller? It would be very appreciated! :smileyhappy:
 
Thanks in advance!
Simone
Labels (1)
0 Kudos
Reply
9 Replies

1,861 Views
Simone
Contributor II
OK, now it works! :smileyvery-happy: THANKS!
I can transmit and receive message in loopback mode.
Now I'll try to send message to the can interface on the pc.
 
Simone
0 Kudos
Reply

1,861 Views
Simone
Contributor II
Hi again Emmanuel!
Ok, I updated the header, and now the initialization seems to work (at least, the right register are changed as it should me).
I wrote this code to transmit 8byte data
Code:
void can_tx(){ unsigned int n,status;MCF_CAN_MBUF_CODE(0) = MCF_CAN_TX_INACTIVE; //MB0 is inactive // Configure MB0 for TXMCF_CAN_MBUF_ID(0) = 0x18FF001E;  // MB0 = TX, Ext. ID      // CAN ID =0x18FF001E, Data Frame                    // IDE = 1 & SRR = 1;             // RTR = 0;// Copy Tx data bytes to the message bufferMCF_CAN_MBUF_BYTE(0,0) = 0x22;MCF_CAN_MBUF_BYTE(0,1) = 0x22;MCF_CAN_MBUF_BYTE(0,2) = 0x11;MCF_CAN_MBUF_BYTE(0,3) = 0x11;MCF_CAN_MBUF_BYTE(0,4) = 0x66;MCF_CAN_MBUF_BYTE(0,5) = 0x66;MCF_CAN_MBUF_BYTE(0,6) = 0x99;MCF_CAN_MBUF_BYTE(0,7) = 0x99;MCF_CAN_MBUF_CTRL(0) = 0x68;MCF_CAN_MBUF_CODE(0) = MCF_CAN_TX_TRONCE;status = MCF_CAN_IFLAG;n=0;while((status & 0x0001)!=1) // polling{if(n++>0x6000)break;status = MCF_CAN_IFLAG; } }

 
at the other end of the cable I have a Can-Pci interface in my pc which (I hope) should work well and monitor Can activity.
I tried the code but it doesn't seem to work...
Is it correct or I'm still missing something? Do you also have a test code for tx-rx?
 
Simone
0 Kudos
Reply

1,861 Views
Nouchi
Senior Contributor II
Hi Simone,

Your code seems to be right, I will just add this statement after buffer inhibition:

while(MCF_CAN_ERRSTAT&(MCF_CAN_ERRSTAT_TXRX+MCF_CAN_ERRSTAT_IDLE)==MCF_CAN_ERRSTAT_TXRX);

to wait buffer really in idle state and check MCF_CAN_TX_TRONCE equal to 0x0C.
Otherwise your code looks like mine, except end of TX are handled by interrupts because I use FreeRTOS.

Emmanuel
0 Kudos
Reply

1,861 Views
Simone
Contributor II
Ehm.....I have a doubt....
In your code there's this part to initialize the message buffers:
 
Code:
for(i=0;i<16;i++)  MCF_CAN_MBUF_CODE(i) = MCF_CAN_RX_INACTIVE;  /* inactive state */

 
but Codewarrior doesn't recognize MCF_CAN_MBUF_CODE definition. In the header mcf5213_can.h that I have there's no reference to the message buffer memory location....
0 Kudos
Reply

1,861 Views
Nouchi
Senior Contributor II
Oooops!!
 
I forgot some extra definitions which doesn't exist in standard CW headers
 
This could be useful
 
Code:
#define MCF_CAN_MBUF_CODE(x) (*(vuint8  *)(void *)(&__IPSBAR[((0x1C0080+(0x10*x)))]))#define MCF_CAN_MBUF_CTRL(x) (*(vuint8  *)(void *)(&__IPSBAR[((0x1C0081+(0x10*x)))]))#define MCF_CAN_MBUF_TIME(x) (*(vuint16 *)(void *)(&__IPSBAR[((0x1C0082+(0x10*x)))]))#define MCF_CAN_MBUF_ID(x)  (*(vuint32 *)(void *)(&__IPSBAR[((0x1C0084+(0x10*x)))]))#define MCF_CAN_MBUF_BYTE(x,y) (*(vuint8  *)(void *)(&__IPSBAR[((0x1C0088+(0x10*x)+y))]))

 
Take a moment to have a look to chapter 25, note some registers are 32 bits wide, but could have 8 or 16bits access.
 
Emmanuel

Message Edited by BugMan on 2006-09-2911:19 AM

0 Kudos
Reply

1,861 Views
francois_boucha
Contributor III
Hi Bugman,

I've looked at your macro:



#define MCF_CAN_MBUF_BYTE(x,y) (*(vuint8  *)(void *)(&__IPSBAR[((0x1C0088+(0x10*x)+y))]))



Let's say I want to access the msg buffer as 16 bits data words.   Is this macro is okay?

#define MCF_FlexCAN_MBUF_WORD(x,y) (*(vuint16 *)(void *)(&__IPSBAR[(0x1C0088+(0x10*x)+(0x2*y))]))

0 Kudos
Reply

1,861 Views
Nouchi
Senior Contributor II
Hi 0xFB,

If you take a look to page 25-17 from the 5213RM, data bytes registers from message buffer seems to be byte access registers,
but, I think it possible to read a couple of them with word access, so, your macro looks OK, you just have to try if it works.

Emmanuel.
0 Kudos
Reply

1,861 Views
Simone
Contributor II
Thanks for your reply! :smileyvery-happy:
I'll try your code immediately!
 
Simone
0 Kudos
Reply

1,861 Views
Nouchi
Senior Contributor II
Hello,
 
If this code can help you:
 
Code:
 MCF_CAN_CANMCR = 0  | MCF_CAN_CANMCR_SOFTRST ;        /* enable Flex CAN module */ while(MCF_CAN_CANMCR&MCF_CAN_CANMCR_SOFTRST);   /* wait end of soft reset */ MCF_CAN_CANMCR = 0  | MCF_CAN_CANMCR_MDIS         /* FlexCAN Disable */  | MCF_CAN_CANMCR_HALT          /* freeze Flex CAN module */  | MCF_CAN_CANMCR_MAXMB(MAX_MB);       /* use MAX_MB messages buffer */ while(MCF_CAN_CANMCR&MCF_CAN_CANMCR_FRZACK);   /* wait for enterfreeze mode */ MCF_CAN_CANCTRL = 0;           /* CLK = EXTAL Freq = 8Mhz */ MCF_CAN_RXGMASK = MCF_CAN_RXGMASK_MI(0x1FF00000); /* set global mask filter extended ID */ for(i=0;i<16;i++)  MCF_CAN_MBUF_CODE(i) = MCF_CAN_RX_INACTIVE;  /* inactive state */ MCF_CAN_CANMCR = 0  | MCF_CAN_CANMCR_HALT          /* freeze Flex CAN module */  | MCF_CAN_CANMCR_MAXMB(MAX_MB-1);     /* use MAX_MB messages buffers */ while(MCF_CAN_CANMCR&MCF_CAN_CANMCR_FRZACK);   /* wait for enter freeze mode */ MCF_CAN_CANCTRL = 0  | MCF_CAN_CANCTRL_PRESDIV(3)       /* S = 2Mhz => 16 * 125Khz bit rate */  | MCF_CAN_CANCTRL_RJW(0)        /* 1 times quanta resync */  | MCF_CAN_CANCTRL_PSEG1(5)        /* SEG1 = 6 time quanta */  | MCF_CAN_CANCTRL_PSEG2(6)        /* SEG2 = 7 time quanta */  | MCF_CAN_CANCTRL_BOFFMSK        /* enable Bus Off interrupt */  | MCF_CAN_CANCTRL_ERRMSK        /* enable Error interrupt */  | MCF_CAN_CANCTRL_SAMP         /* triple sample point */  | MCF_CAN_CANCTRL_TSYNC         /* resync enable */  | MCF_CAN_CANCTRL_LBUF         /* lowest buffer transmitted first */  | MCF_CAN_CANCTRL_PROPSEG(1);       /* 2 time quanta PROPSEG */ MCF_CAN_CANMCR &= ~MCF_CAN_CANMCR_HALT;    /* unfreeze FlexCAN */

to answer your question,  MCF_CAN_CANMCR is defined as vuint32 in mcf5213_can.h

ps: M5213 run @ 64Mhz
 
Emmanuel

0 Kudos
Reply