AnsweredAssumed Answered

Flexcan K70 with CAN0 and CAN1 with Mqx driver

Question asked by gianfranco camoirano on May 21, 2015
Latest reply on Jun 12, 2015 by soledad

Hi to all

I'm try to use in the K70 the CAN0 and CAN1 connected to two different Can Bus.

If I configure only 1 of this, it's work good but if I configure this, the result of second "flexcan_init" is error 1040.

it's not important which CAN is configured like second....it's doesn't work.

this is my code :

 

uint32_t u32_error = 0;

uint32_t u32_bitrate_get = 0;

uint32_t rx_fifo_id[8];

 

      /* Set CAN1 device parameters */

     instance = CAN_1;                       

     flexcan1_data.num_mb = 16;

     flexcan1_data.max_num_mb = 16;

     flexcan1_data.num_id_filters = kFlexCanRxFifoIDFilters_8;

     flexcan1_data.is_rx_fifo_needed = FALSE;

     flexcan1_data.is_rx_mb_needed = TRUE;

    

     /* Set rx code status params  */

     rx_cs1.code = kFlexCanRX_Ranswer;

     rx_cs1.msg_id_type = kFlexCanMbId_Std;

     rx_cs1.data_length = 1;

     rx_cs1.substitute_remote = 0;

     rx_cs1.remote_transmission = 0;

     rx_cs1.local_priority_enable = 0;

     rx_cs1.local_priority_val = 0;

    

     id_table.is_extended_mb = 0;

     id_table.is_remote_mb = 0;

     id_table.id_filter = rx_fifo_id;

 

    

     /* Init CAN device */

      u32_error = flexcan_init(instance, &flexcan1_data, FALSE);

      if (u32_error){

          return u32_error;

      }

     

      /* Set CAN bitrate */

      u32_error = flexcan_set_bitrate(instance, 1000000);

     if (u32_error){

         return u32_error;

     }

 

     /* Get CAN bitrate */

     u32_error = flexcan_get_bitrate(instance, &u32_bitrate_get);

     if (u32_error){

         return u32_error;

     }

    

     /* Set mask type */

     u32_error = flexcan_set_mask_type(instance, kFlexCanRxMask_Global);

     if (u32_error){

         return u32_error;

     }

 

     /* Set CAN rx fifo and mailbox mask */    

     if (flexcan1_data.is_rx_fifo_needed) {

         u32_error = flexcan_set_rx_fifo_global_mask(instance, kFlexCanMbId_Std, 0x7FF);

         if (u32_error){

             return u32_error;

         }

     }

 

     if (flexcan1_data.is_rx_mb_needed) {

         u32_error = flexcan_set_rx_mb_global_mask(instance, kFlexCanMbId_Std, u32_MyAddressCan);       

         if (u32_error){

             return u32_error;

         }

     }

    

     /* Configure CAN rx resources for selected instance  */

     if (flexcan1_data.is_rx_fifo_needed){

         u32_error = flexcan_rx_fifo_config(instance, &flexcan1_data, kFlexCanRxFifoIdElementFormat_A, &id_table);

         if (u32_error){

             return u32_error;

         }

     }

    

      /* Set CAN0 device parameters */

     instance = CAN_0;                       

     flexcan0_data.num_mb = 16;

     flexcan0_data.max_num_mb = 16;

     flexcan0_data.num_id_filters = kFlexCanRxFifoIDFilters_8;

     flexcan0_data.is_rx_fifo_needed = FALSE;

     flexcan0_data.is_rx_mb_needed = TRUE;

    

     /* Set rx code status params  */

     rx_cs0.code = kFlexCanRX_Ranswer;

     rx_cs0.msg_id_type = kFlexCanMbId_Std;

     rx_cs0.data_length = 1;

     rx_cs0.substitute_remote = 0;

     rx_cs0.remote_transmission = 0;

     rx_cs0.local_priority_enable = 0;

     rx_cs0.local_priority_val = 0;

    

     id_table.is_extended_mb = 0;

     id_table.is_remote_mb = 0;

     id_table.id_filter = rx_fifo_id;

 

    

     /* Init CAN device */

      u32_error = flexcan_init(instance, &flexcan0_data, FALSE);                         // <----- ERROR -----    u32_error exit with value 1040

      if (u32_error){

          return u32_error;

      }

     

      /* Set CAN bitrate */

      u32_error = flexcan_set_bitrate(instance, 1000000);

     if (u32_error){

         return u32_error;

     }

 

     /* Get CAN bitrate */

     u32_error = flexcan_get_bitrate(instance, &u32_bitrate_get);

     if (u32_error){

         return u32_error;

     }

    

     /* Set mask type */

     u32_error = flexcan_set_mask_type(instance, kFlexCanRxMask_Global);

     if (u32_error){

         return u32_error;

     }

 

     /* Set CAN rx fifo and mailbox mask */    

     if (flexcan0_data.is_rx_fifo_needed) {

         u32_error = flexcan_set_rx_fifo_global_mask(instance, kFlexCanMbId_Std, 0x7FF);

         if (u32_error){

             return u32_error;

         }

     }

 

     if (flexcan0_data.is_rx_mb_needed) {

         u32_error = flexcan_set_rx_mb_global_mask(instance, kFlexCanMbId_Std, u32_MyAddressCan);       

         if (u32_error){

             return u32_error;

         }

     }

    

     /* Configure CAN rx resources for selected instance  */

     if (flexcan0_data.is_rx_fifo_needed){

         u32_error = flexcan_rx_fifo_config(instance, &flexcan0_data, kFlexCanRxFifoIdElementFormat_A, &id_table);

         if (u32_error){

             return u32_error;

         }

     }

 

I'm using MQX 3.9

thanks.

 

gianfranco

Outcomes