AnsweredAssumed Answered

stm32f042 can problem

Question asked by turkman.serhat on Aug 27, 2015
Latest reply on Aug 27, 2015 by turkman.serhat
01.void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
02.{
03. 
04.  GPIO_InitTypeDef GPIO_InitStruct;
05.  if(hcan->Instance==CAN)
06.  {
07.  /* USER CODE BEGIN CAN_MspInit 0 */
08. 
09.  /* USER CODE END CAN_MspInit 0 */
10.    /* Peripheral clock enable */
11.    __CAN_CLK_ENABLE();
12.    /**CAN GPIO Configuration   
13.    PB8     ------> CAN_RX
14.    PB9     ------> CAN_TX
15.    */
16.    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
17.    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
18.    GPIO_InitStruct.Pull = GPIO_NOPULL;
19.    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
20.         
21.    GPIO_InitStruct.Alternate = GPIO_AF4_CAN;
22.         
23.    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
24. 
25.  /* USER CODE BEGIN CAN_MspInit 1 */
26. 
27.  /* USER CODE END CAN_MspInit 1 */
28.  }
29. 
30.}
31. 
32./* CAN init function */
33.void MX_CAN_Init(void)
34.{
35. 
36.  hcan.Instance = CAN;
37.     
38.  hcan.pTxMsg = &TxMessage; // Pointer initialization
39.  hcan.pRxMsg = &RxMessage;
40.  hcan.Init.Prescaler = 3;
41.  hcan.Init.Mode = CAN_MODE_NORMAL;
42.  hcan.Init.SJW = CAN_SJW_1TQ;
43.  hcan.Init.BS1 = CAN_BS1_13TQ;
44.  hcan.Init.BS2 = CAN_BS2_2TQ; 
45.  hcan.Init.TTCM = DISABLE;
46.  hcan.Init.ABOM = DISABLE;
47.  hcan.Init.AWUM = DISABLE;
48.  hcan.Init.NART = DISABLE;
49.  hcan.Init.RFLM = DISABLE;
50.  hcan.Init.TXFP = DISABLE;
51.  HAL_CAN_Init(&hcan);
52. 
53.}
54. 
55. 
56. 
57. 
58.while(1) //main while
59.{
60.        while(hcan.State == HAL_CAN_STATE_BUSY);
61. 
62.        TxMessage.IDE = CAN_ID_STD;
63.        TxMessage.StdId = 0x001;
64.        TxMessage.ExtId = 0x001;
65.        TxMessage.RTR = CAN_RTR_DATA; //For Remote Request CAN_RTR_REMOTE
66.        TxMessage.DLC = 8;
67.        TxMessage.Data[0] = 0x01;
68.        TxMessage.Data[1] = 0x02;
69.        TxMessage.Data[2] = 0x03;
70.        TxMessage.Data[3] = 0x04;
71.        TxMessage.Data[4] = 0x05;
72.        TxMessage.Data[5] = 0x06;
73.        TxMessage.Data[6] = 0x07;
74.        TxMessage.Data[7] = 0x08;
75.      HAL_CAN_Transmit(&hcan,100);
76. 
77.        while(hcan.State == HAL_CAN_STATE_BUSY);
78.        HAL_Delay(10);
79.        HAL_CAN_Receive(&hcan,CAN_FIFO0,100);
80. 
81. 
82. 
83.        while(hcan.State == HAL_CAN_STATE_BUSY);
84.        HAL_Delay(10);
85.        HAL_CAN_Receive(&hcan,CAN_FIFO1,100);
86.}

I'm running the same code in two boards.  

I can see the CAN signals with oscilloscope. But the hcan.pRxMsg is always empty. 

I use latest CubeMx.

Am i missing sth?


Outcomes