cancel
Showing results for 
Search instead for 
Did you mean: 

CAN TX ERRORS ??? please help

JHERI
Senior

Hello

following the CAN lectures I have a real strange problem transmitting can message

I have two can nodes 1) nucleo 446re board and node 2) is my Can Bus Analyser

I even get the same TX errors in loop back mode & Can normal mode ????

why ?? what is wrong with these tx mail boxes

I have set my CAN code to use interrupt mode and every 100ms I transmit the same message over and over again,

but I only ever get two successful transmissions and then generate an error in the  HAL_CAN_AddTxMessage

Why is this???? are the TX mail boxes not getting cleared? ready for the next tx message

Why would I get an error with the .. this makes no sense at all ???

// ************************************************************************                             // ***** CAN 1 INIT
// ********** HIGH LEVEL CAN1 PHERIPHERAL INITIALISATION SETUP ************                             // HIGH LEVEL CAN1 PERIPHERAL CONFIGURATION
// ************************************************************************                             // HEADER FILE stm32f4xx_hal_can.c has info 
 
    CAN_HandleTypeDef   hcan1;                                                                          // assign handle to CAN1 Peripheral
 
 
void MX_CAN1_Init(void)
{
 
    hcan1.Instance                  = CAN1;                                                             // working with CAN1 Peripheral
                                                                                                        // Master Clock @ 50Mhz = APB1 Freq = 25Mhz
                                                                                                        // Duration of 1 time quanta (1TQ) = PCLK1 / CAN Prescaler                   
                                                                                                        
                                                                                                          
    hcan1.Init.Mode                 = CAN_MODE_NORMAL;//LOOPBACK;                                                // CAN1 OPERATING MODE
                                                                                                        // @ 25mhz
                                                                                                        // Set CAN1 to 500Mbits Per Second from website calculator (www.bittiming.can-wiki.info)
 // important can1 timing setup                                                                         // 
    hcan1.Init.Prescaler            = 5;                                                                // Set Prescaler to 5 for 500Mbits
    
    hcan1.Init.SyncJumpWidth        = CAN_SJW_1TQ;                                                      // 1 Time Quantum
    hcan1.Init.TimeSeg1             = CAN_BS1_8TQ;                                                      // SELECT TimeSeg1 = 8TQ (1TQ - 16TQ)
    hcan1.Init.TimeSeg2             = CAN_BS2_1TQ;                                                      // SELECT TimeSeg2 = 1TQ
    
    hcan1.Init.TimeTriggeredMode    = DISABLE;                                                          // Transmit Mode Disabled
    hcan1.Init.AutoBusOff           = DISABLE;                                                           // Auto Bus Off Disabled
    hcan1.Init.AutoWakeUp           = DISABLE;                                                          // Auto Wake Up Disabled
    hcan1.Init.AutoRetransmission   = DISABLE;                                                           // Auto Re-Transmit CAN Message On Error
    hcan1.Init.ReceiveFifoLocked    = DISABLE;                                                          // Disabled = new message will Overwrite the 3 messages in the Fifo if messages not read
    hcan1.Init.TransmitFifoPriority = DISABLE;                                                          // Transmit Fifo Priority
      
    if (HAL_CAN_Init(&hcan1) != HAL_OK)
      {
      _Error_Handler(__FILE__, __LINE__);
      }
 
}
 

// ************************************************************************                             // ***** LOW LEVEL CAN INIT
// ********** LOW LEVEL CAN PERIPHERAL INITIALISATION SETUP **************                              // LOW LEVEL CAN PERIPHERAL CONFIGURATION
// ************************************************************************                             // HEADER FILE stm32f4xx_hal_can.c has info 
 
 
void HAL_CAN_MspInit(CAN_HandleTypeDef* canHandle)
{
 
    GPIO_InitTypeDef    GPIO_InitStruct;
    
    if ( canHandle-> Instance == CAN1)                                                                  // if CAN instance = CAN1 then configure GPIO for CAN 1 Peripherals
        {
 
        /* CAN1 clock enable */
        __HAL_RCC_CAN1_CLK_ENABLE();                                                                    // ENABLE CAN1 CLOCK
  
        /**CAN1 GPIO Configuration    
        PA11     ------> CAN1_RX
        PA12     ------> CAN1_TX 
        */
    
        GPIO_InitStruct.Pin         = GPIO_PIN_11|GPIO_PIN_12;                                          // Configure GPIO for CAN1 PA11= CAN RX / PA12= CAN TX
        GPIO_InitStruct.Mode        = GPIO_MODE_AF_PP;                                                  // ALTERNATE PUSH PULL MODE
        GPIO_InitStruct.Pull        = GPIO_NOPULL;                                                      // NO PULL UPS
        GPIO_InitStruct.Speed       = GPIO_SPEED_FREQ_VERY_HIGH;                                        // VERY HIGH FREQ
        GPIO_InitStruct.Alternate   = GPIO_AF9_CAN1;                                                    // ALTERNATE GPIO AF9 CAN1
      
        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);                                                         // Init GPIO 
 
        HAL_NVIC_SetPriority( CAN1_TX_IRQn,  10 ,0 );
        HAL_NVIC_SetPriority( CAN1_RX0_IRQn, 10 ,0 );
        HAL_NVIC_SetPriority( CAN1_RX1_IRQn, 10 ,0 );
        HAL_NVIC_SetPriority( CAN1_SCE_IRQn, 10 ,0 );
 
        HAL_NVIC_EnableIRQ( CAN1_TX_IRQn );
        HAL_NVIC_EnableIRQ( CAN1_RX0_IRQn);
        HAL_NVIC_EnableIRQ( CAN1_RX1_IRQn);
        HAL_NVIC_EnableIRQ( CAN1_SCE_IRQn);
        
        }
 
}
 

here you can see successful messages sent on the can bus but only 2/3 before the error in the HAL_CAN_AddTxMessage() code ??

0690X000006CTNWQA4.jpg

here we can see two / three messages getting sent before the error at the HAL_CAN_AddTxMessage code

0690X000006CTNMQA4.jpg

0690X000006CTNHQA4.jpg

 This is on the CAN RX pin of the Nucleo Board

0690X000006CTOPQA4.jpg

This is on the CAN TX Pin Of The Nucleo Board

0690X000006CTOKQA4.jpg

Both in my logic anylyser and CAN Bus Analyser I can see the successful transmission of the two messages

WHY WHY WHY is the ARM triggering an error ???? after only sending 2 messages

It should send the messages for the next year! or until I hit the stop button in my debugger

any help will be appreciated

Thanks in advance, oh this is now getting to me, it should be fun, but its now becoming a pain for the amount of time I am wasting

Oh I also get a CAN ERR interrupt generation and error code of 0x1000

CAN ERROR 0x1000 is

(0x00010000U) /*!< TxMailbox 1 transmit failure due to tranmit error  

why does this only transmit 2 messages and then error ???

ON FURTHER TESTING .?????? ... WHAT IS GOING ON, the returned error is HAL_CAN_ERROR_NOT_INITIALIZED

it's already sent two/three messages and now it is saying it's not initialized

are these HAL APIs buggy or flawed ??

0690X000006CTOFQA4.jpg

  

this error is both in loopback and normal mode, is it because it is in interrupt mode ?

0 REPLIES 0