This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to generate a CAN receive interrupt in simulator?

Hi,

I'm debugging an interrupt service routine. I simulate a CAN message and expect the simulator to generate a receive interrupt, but this doesn't happen. I also tried this on a Keil code example, but the result was the same, so I assume the problem isn't in my code. Here's what I did:

1) Load the project Keil\ARM\Boards\Keil\MCB2300\CAN\CAN.uvproj in the IDE.
2) Add the following code to CAN_Simulate.ini:

func void CAN_transmit(void) {

        CAN1ID = 0xC7;
        CAN1L = 7;
        CAN1B0 = 0x07;
        CAN1B1 = 0xD4;
        CAN1B2 = 0x0C;
        CAN1B3 = 0x1F;
        CAN1B4 = 0x0A;
        CAN1B5 = 0x01;
        CAN1B6 = 0x00;
        CAN1B7 = 0x00;
        CAN1IN = 1;
}

define button "Send CAN message", "CAN_transmit();"

3) Compile.
4) Set a breakpoint in CAN.c after the line:

if (CAN1->GSR & (1 << 0)) {                    /* CAN Controller #1 meassage is received */

5) Run.
6) Click on the "Send CAN message" button.
7) See a received message in the "CAN communication" window, but no receive interrupt is generated.

At the same time transmit interrupts do get generated. What am doing wrong?

Parents Reply Children
  • In KEIL's CanDemo.c

    It seems that only CAN-ID=33 will generate Rx Interrupt.

    /*----------------------------------------------------------------------------
      initialize CAN interface
     *----------------------------------------------------------------------------*/
    void can_Init (void) {
    
      CAN_setup (1);                                  /* setup CAN Controller #1 */
      CAN_setup (2);                                  /* setup CAN Controller #2 */
      CAN_wrFilter (1, 33, STANDARD_FORMAT);          /* Enable reception of messages */
    
      CAN_start (1);                                  /* start CAN Controller #2 */
      CAN_start (2);                                  /* start CAN Controller #2 */
    
      CAN_waitReady (1);                              /* wait til tx mbx is empty */
      CAN_waitReady (2);                              /* wait til tx mbx is empty */
    }
    
    
    int main (void)  {
      int i;
    
    #ifdef RT_AGENT
      RTA_Init();                                     /* Initialize Real-Time Agent  */
    #endif
      PINSEL10 = 0;                                   /* Disable ETM interface, enable LEDs  */
    
      adc_Init ();                                    /* initialise A/D converter */
      LED_init ();                                    /* Initialize the LEDs */
      can_Init ();                                    /* initialise CAN interface */
    
      lcd_init();                                     /* Initialize the LCD */
      lcd_clear();                                    /* Clear the LCD */
    
      lcd_print ("MCB2300 CAN Demo");                 /* Display string on LCD display */
      set_cursor (0, 1);                              /* Set cursor position on LCD display */
      lcd_print ("  http://www.keil.com  ");
      delay (0x10000);                                /* Wait wait a while */
    
      CAN_TxMsg[1].id = 33;                           /* initialise message to send */
      for (i = 0; i < 8; i++) CAN_TxMsg[0].data[i] = 0;
      CAN_TxMsg[1].len = 1;
      CAN_TxMsg[1].format = STANDARD_FORMAT;
      CAN_TxMsg[1].type = DATA_FRAME;
    
      while (1) {
        val_Tx = adc_Get ();                          /* TX value changes in any case */
        if (CAN_TxRdy[1]) {                           /* tx message on CAN Controller #2 */
          CAN_TxRdy[1] = 0;
    
          CAN_TxMsg[1].data[0] = val_Tx;             /* data[0] field = ADC value */
          CAN_wrMsg (2, &CAN_TxMsg[1]);               /* transmit message */
        }
    
        delay (10000);                                /* Wait a while to receive the message */
    
        if (CAN_RxRdy[0]) {                           /* rc message on CAN Controller #1 */
          CAN_RxRdy[0] = 0;
    
          val_Rx = CAN_RxMsg[0].data[0];
        }
    
        val_display ();                               /* display TX and RX values */
    
      }
    }