Send CAN Frame with an 16-bit MC9S12XF512MLM

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

Send CAN Frame with an 16-bit MC9S12XF512MLM

605 Views
Kartoon67
Contributor III

Hi everyone,

 

From begining, i'm sorry in advance about my english expression.

 

I have a little problem in programming an MCU 16-bit MC9S12XF512MLM. I have two developement tool card with the MC9S12XF512MLM that i connect with FLEXRAY and CAN module. The example give by freescale show that the two card are communicating correctly.

 

But when i try to send an CAN frame frome one NODE and receive the frame in the second NODE, i can't do it.

 

I'm using the folowing structure for sending a CAN FRAME :

 

 

UINT8 u8CAN_SendFrame(UINT32 u32ID, UINT8 u8Prio, UINT8 u8Length, UINT8 *u8TxData){       /* Transmission buffer */    UINT8 u8TxBuffer = {0};        /* Index to data within the transmission buffer */    UINT8 u8Index;        if (!CAN0TFLG)              /* Retrun if Transmit Buffer is full */        return ERR_BUFFER_FULL;    CAN0TBSEL = CAN0TFLG;       /* Select lowest empty buffer */    u8TxBuffer = CAN0TBSEL;        /* Backup selected buffer */            *((UINT32 *) ((UINT32)(&CAN0TXIDR0)))= u32ID;   /* Load Id to IDR Registers */                /* Load data to Data Segment Registers */        for (u8Index=0;u8Index<u8Length;u8Index++) {            *(&CAN0TXDSR0 + u8Index) = u8TxData[u8Index];          }    CAN0TXDLR = u8Length;   /* Set Data Length Code */    CAN0TXTBPR = u8Prio;    /* Set Priority */    CAN0TFLG = u8TxBuffer;  /* Start transmission */                        while ( (CAN0TFLG & u8TxBuffer) != u8TxBuffer)            ;  /* Wait for Transmission completion */                return NO_ERR; }

 And this one for receiving the frame :

 

void vfnCAN_ReceivedFrame(void){    /* Length of received frame */    UINT8 u8Length;        /* Index for extracting/storing received data */    UINT8 u8Index;        /* Reception array */    UINT8 u8RxData[8];    u8Length = (CAN0RXDLR & 0x0F);  /* Extract received frame data length */      /* Read and store each of the received data */     for (u8Index=0; u8Index<u8Length; u8Index++)           u8RxData[u8Index] = *(&CAN0RXDSR0 + u8Index);     CAN0RFLG_RXF = 1;   /* Clear reception flag */     }

 

 

If you have an idea about the problem, i will be greatful.

 

Thanks in advance,

 

Best Regards,

Labels (1)
0 Kudos
4 Replies

332 Views
kef
Specialist I

So make your favourite PC CAN tool connected to bus and see what's going on. Also try making acceptance filters open to all messages.

 

    *((UINT32 *) ((UINT32)(&CAN0TXIDR0)))= u32ID;   /* Load Id to IDR Registers */
 

^^ What is in u32ID? If it is plain CAN message ID, then your code is wrong. xxxIDR registers have two message ID's mapping, one for standard 11bit ID messages, and another one for 29bit ID messages. None of these mappings match CAN message ID, you need to shuffle ID bits a bit, set up RTR bit and IDE bit.

 

  

    CAN0RFLG_RXF = 1;   /* Clear reception flag */   

 

^^ comment is only partially correct. In fact this line of code clears not only reception flag (RXF), but also WUPIF, CSCIF and OVRIF flags. This is because RXF flag can not be written without writing other CAN0RFLG bits. All flags, that are set will be rewritten with ones and thus will be cleared.

 

0 Kudos

332 Views
Kartoon67
Contributor III

Hi and thank you for responding,

 

The code i have quote are becomming from the Example give by FREESCALE. That why i have some problem about this code because it may be right.

 

But when i use it, it don't work. I'm going to see what you answers and try to debug the program.

 

Regards,

0 Kudos

332 Views
Kartoon67
Contributor III

I would like to specify something about my questions.  The program i have quote in my last message are becoming from the Freescale example for using the MCU MC9S12XF512MLM.

 

Before that, there is a program to initializate the CAN module.

 

And i hope receiving a response about using this two fonctions and communication between my 2 Node by CAN module.

 

Thanks,

0 Kudos

332 Views
Kartoon67
Contributor III

Hi,

 

Anyone have an idea about my problem?

 

Regards,

0 Kudos