AnsweredAssumed Answered

STM32 & CAN bus - problem with communication

Question asked by rafal.anna on Mar 24, 2014
Latest reply on Aug 14, 2014 by Clive One
I have STM32F429-Disco board and I'm trying to connect two CAN interfaces, which this board has. 

My parts of the code are:

                                   
                                                                                                                                                                                                           
/* CAN1 init function */
            void MX_CAN1_Init(void)
            {
           
           
              hcan1.Instance = CAN1;                                                                       
              hcan1.Init.Prescaler = 8;                                                                 // Specifies the length of a time quantum.
              hcan1.Init.Mode = CAN_MODE_NORMAL;                                             // Specifies the CAN operating mode.
              hcan1.Init.SJW = CAN_SJW_1TQ;                                                       // Specifies the maximum number of time quanta the CAN hardware is allowed to lengthen or shorten a bit to perform resynchronization.
              hcan1.Init.BS1 = CAN_BS1_10TQ;                                                       // Specifies the number of time quanta in Bit Segment 1. 
              hcan1.Init.BS2 = CAN_BS2_7TQ;                                                       // Specifies the number of time quanta in Bit Segment 2.
              hcan1.Init.TTCM = DISABLE;                                                            // Enable or disable the time triggered communication mode.
              hcan1.Init.ABOM = DISABLE;                                                            // Enable or disable the automatic bus-off management.
              hcan1.Init.AWUM = DISABLE;                                                            // Enable or disable the automatic wake-up mode.
              hcan1.Init.NART = DISABLE;                                                            // Enable or disable the non-automatic retransmission mode.
              hcan1.Init.RFLM = DISABLE;                                                            // Enable or disable the receive FIFO Locked mode.
              hcan1.Init.TXFP = DISABLE;                                                            // Enable or disable the transmit FIFO priority.
                 hcan1.pTxMsg = &hcan1Transmit;
                 hcan1.pRxMsg = &hcan1Receive;
              HAL_CAN_Init(&hcan1);
                 
                 hcan1Filter.FilterNumber = 0;                                                        // Specifies the filter which will be initialized
                 hcan1Filter.FilterMode = CAN_FILTERMODE_IDMASK;                         // Specifies the filter mode to be initialized.
                 hcan1Filter.FilterScale = CAN_FILTERSCALE_32BIT;                         // Specifies the filter scale.
                 hcan1Filter.FilterIdHigh = 0x00;                                                       // Specifies the filter identification number (MSBs for a 32-bit configuration, first one for a 16-bit configuration).
                 hcan1Filter.FilterIdLow = 0x00;                                                       // Specifies the filter identification number (LSBs for a 32-bit configuration, second one for a 16-bit configuration).
                 hcan1Filter.FilterMaskIdHigh = 0x00;                                                  // Specifies the filter mask number or identification number, according to the mode (MSBs for a 32-bit configuration, first one for a 16-bit configuration).
                 hcan1Filter.FilterMaskIdLow = 0x00;                                                  // Specifies the filter mask number or identification number, according to the mode (LSBs for a 32-bit configuration, second one for a 16-bit configuration).
                 hcan1Filter.FilterFIFOAssignment = 0;                                             // Specifies the FIFO (0 or 1) which will be assigned to the filter.
                 hcan1Filter.FilterActivation = ENABLE;                                             // Enable or disable the filter.
                 hcan1Filter.BankNumber = 0;                                                       // Select the start slave bank filter
                 HAL_CAN_ConfigFilter(&hcan1, &hcan1Filter);
                 
           
           
            } 
 void MX_CAN2_Init(void)
            {
           
           
              hcan2.Instance = CAN2;
              hcan2.Init.Prescaler = 8;
              hcan2.Init.Mode = CAN_MODE_NORMAL;
              hcan2.Init.SJW = CAN_SJW_1TQ;
              hcan2.Init.BS1 = CAN_BS1_10TQ;
              hcan2.Init.BS2 = CAN_BS2_7TQ;
              hcan2.Init.TTCM = DISABLE;
              hcan2.Init.ABOM = DISABLE;
              hcan2.Init.AWUM = DISABLE;
              hcan2.Init.NART = DISABLE;
              hcan2.Init.RFLM = DISABLE;
              hcan2.Init.TXFP = DISABLE;
                 hcan2.pTxMsg = &hcan2Transmit;
                 hcan2.pRxMsg = &hcan2Receive;
              HAL_CAN_Init(&hcan2);
                 
                 hcan2Filter.FilterNumber = 0;                                                        // Specifies the filter which will be initialized
                 hcan2Filter.FilterMode = CAN_FILTERMODE_IDMASK;                         // Specifies the filter mode to be initialized.
                 hcan2Filter.FilterScale = CAN_FILTERSCALE_32BIT;                         // Specifies the filter scale.
                 hcan2Filter.FilterIdHigh = 0x00;                                                       // Specifies the filter identification number (MSBs for a 32-bit configuration, first one for a 16-bit configuration).
                 hcan2Filter.FilterIdLow = 0x00;                                                       // Specifies the filter identification number (LSBs for a 32-bit configuration, second one for a 16-bit configuration).
                 hcan2Filter.FilterMaskIdHigh = 0x00;                                                  // Specifies the filter mask number or identification number, according to the mode (MSBs for a 32-bit configuration, first one for a 16-bit configuration).
                 hcan2Filter.FilterMaskIdLow = 0x00;                                                  // Specifies the filter mask number or identification number, according to the mode (LSBs for a 32-bit configuration, second one for a 16-bit configuration).
                 hcan2Filter.FilterFIFOAssignment = 0;                                             // Specifies the FIFO (0 or 1) which will be assigned to the filter.
                 hcan2Filter.FilterActivation = ENABLE;                                             // Enable or disable the filter.
                 hcan2Filter.BankNumber = 0;                                                       // Select the start slave bank filter
                 HAL_CAN_ConfigFilter(&hcan2, &hcan2Filter);
           
           
            }
 /* Transmit Structure preparation CAN1 */
                                hcan1Transmit.StdId = 0x321;                                        // Specifies the standard identifier.
                                hcan1Transmit.ExtId = 0x02;                                             // Specifies the extended identifier.
                                hcan1Transmit.RTR = CAN_RTR_DATA;                         // Specifies the type of frame for the message that will be transmitted. < Data frame */
                                hcan1Transmit.DLC = 1;                                                  // Specifies the length of the frame that will be transmitted.
                                hcan1Transmit.IDE = CAN_ID_STD;                                   // Specifies the type of identifier for the message that will be transmitted. < Standard Id */
                                hcan1Transmit.Data[0] = 0;
                                Init_RxMessage(&hcan1Receive);
                      /* Enable CAN1 interrupt request */
                                __HAL_CAN_ENABLE_IT(&hcan1, CAN_IT_FMP0);
                                
                      /* Transmit Structure preparation CAN2 */
                                hcan2Transmit.StdId = 0x320;                                        // Specifies the standard identifier.
                                hcan2Transmit.ExtId = 0x01;                                             // Specifies the extended identifier.
                                hcan2Transmit.RTR = CAN_RTR_DATA;                         // Specifies the type of frame for the message that will be transmitted. < Data frame */
                                hcan2Transmit.DLC = 1;                                                  // Specifies the length of the frame that will be transmitted.
                                hcan2Transmit.IDE = CAN_ID_STD;                                   // Specifies the type of identifier for the message that will be transmitted. < Standard Id */
                                hcan2Transmit.Data[0] = 0;
                                Init_RxMessage(&hcan2Receive);
                      /* Enable CAN2 interrupt request */
                                __HAL_CAN_ENABLE_IT(&hcan2, CAN_IT_FMP0);
 
                                                                                                                                                                                        
I'm connecting these two CAN interfaces through MCP2551 transceiver. 
 If I change CAN mode to LOOPBACK and test, everything works ok, but when it is in NORMAL mode, it seems there's a problem. I cannot transmit anything through the bus. 
           
 
 Where am I wrong?
                                   

Outcomes