Author Topic: how to use interrupt getting CAN-BUS data!  (Read 9041 times)

Offline tr111

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
how to use interrupt getting CAN-BUS data!
« on: November 23, 2007, 06:35:38 AM »
   I have know the work in loopback mode,this is FlexCAN performs an internal loop
back that can be used for self test operation.
   But how can I get the data from I send!
   I don't know that
    Receiving CAN data messages
When a CAN data message is received it is placed in a free receive buffer and the owner task is notified of the fact via an interrupt event. It can then pick up the data by calling the generic fnRead(). It is not necessary to specify the read length since data should be read as a block from a single buffer, however there are a number of options available.
......   case INTERRUPT_EVENT:     // on an interrupt event
            switch (ucInputMessage[MSG_INTERRUPT_EVENT]) {
            case CAN_RX_MSG::      // A CAN rx. message is waiting
                Length = fnRead(CAN_interface_ID, ucInputMessage,
                         (0 | GET_CAN_RX_TIME_STAMP | GET_CAN_RX_ID));
                          // collect the message along with some details
                break; ......
Can that more detail, tell me how to do in utasker?????????
the freecale give me some code:
this the interrupt

 MCF_GPIO_PASPAR=MCF_GPIO_PASPAR_SYNCA_CANRX|MCF_GPIO_PASPAR_SYNCB_CANTX;
                         
                         
   
   /* FlexCAN Soft Reset */
   MCF_FlexCAN_CANMCR = MCF_FlexCAN_CANMCR_SOFTRST;
   while ((MCF_FlexCAN_CANMCR & MCF_FlexCAN_CANMCR_SOFTRST) != 0x0) {}
   
   /* initialize FlexCANs */         
   init_flexcan();
   
   /* initialize FlexCAN interrupts */
   init_flexcan_interrupts();
   
   /* zero message in receive buffer 1 */
   * (vuint32 *) (FLEXCAN_BUFFERS + 0x18) = 0x00000000;
   * (vuint32 *) (FLEXCAN_BUFFERS + 0x1C) = 0x00000000;
   
   printf("DONE\n\r");
   
      printf("Received buffer before sending: 0x%08x 0x%08x\n\r", * (vuint32 *) (FLEXCAN_BUFFERS + 0x18), * (vuint32 *) (FLEXCAN_BUFFERS + 0x1C));   
   
   
   /* transmit a message from transmit buffer 0 */   
   * (vuint32 *) (FLEXCAN_BUFFERS + 0x8) = 0xABCD0022;
   * (vuint32 *) (FLEXCAN_BUFFERS + 0xC) = 0xBABA1234;      
   
   MCF_FlexCAN_CANMCR &= ~(MCF_FlexCAN_CANMCR_HALT); //leave HALT
   
   /* await for synchronisation */
   for (i=1;i<255;i++) {}   
   
   //from some reason, this didn't work in loopback mode   
   //while (MCF_CAN_CANMCR0 & MCF_CAN_CANMCR_NOTRDY == MCF_CAN_CANMCR_NOTRDY) {}
      
   * (vuint16 *) FLEXCAN_BUFFERS = 0x0C08; //write CODE for transmission of 8 bytes   

/*********************************************************************************************/
__declspec(interrupt)
void Rx_Buffer1(void)
{
   /* display received data */
   printf("Received data after sending: 0x%08x 0x%08x\n\r", * (vuint32 *) (FLEXCAN_BUFFERS + 0x18), * (vuint32 *) (FLEXCAN_BUFFERS + 0x1C));   
   
   MCF_FlexCAN_IFLAG|=  MCF_FlexCAN_IFLAG_BUF1I;
}


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: how to use interrupt getting CAN-BUS data!
« Reply #1 on: November 28, 2007, 08:38:59 PM »
Hi

I am having difficulty finding the time to check this out on the hardware - hopefully I can verify some time soon.

In the meantime, check that all jumpers are correct on the evaluation board that you are using - the interface is often shared with serial ports and the correct ones can be determined from the markings on the board and/or the EVB description.

Also take a look at the debug routine fnDumpCAN() in M5223X.c. You can call this from any code and it will dump all important CAN releated information to either the serial interface (if opened) or to TELNET (if connected). I found this very useful when developing the drivers since it shows exactly the state of the various CAN buffers and often the reason for unexpected events is immediately visible.

Good luck

Regards

Mark