Skip to main content
iboxe
Associate
January 6, 2020
Question

Hello! I can not send 5 identifiers (IDs).Please tell me where the error is.

  • January 6, 2020
  • 10 replies
  • 2028 views

CAN_FilterTypeDef sFilterConfig;

CAN_TxHeaderTypeDef TxHeader;

CAN_RxHeaderTypeDef RxHeader;

uint8_t TxData[8];

uint8_t RxData[8];

uint32_t TxMailbox;

/* USER CODE END PV */

/* Private function prototypes ----------Ча�?тные функции прототипов-------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_CAN_Init(void);

static void MX_WWDG_Init(void);

/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_CAN_Init();

 MX_WWDG_Init();

 /* USER CODE BEGIN 2 */

 sFilterConfig.FilterBank=0;

 sFilterConfig.FilterMode=CAN_FILTERMODE_IDMASK;

 sFilterConfig.FilterScale=CAN_FILTERSCALE_32BIT;

 sFilterConfig.FilterIdHigh=0x0000;

 sFilterConfig.FilterIdLow=0x0000;

 sFilterConfig.FilterMaskIdHigh=0x0000;

 sFilterConfig.FilterMaskIdLow=0x0000;

 sFilterConfig.FilterFIFOAssignment=CAN_RX_FIFO0;

 sFilterConfig.FilterActivation=ENABLE;

 sFilterConfig.SlaveStartFilterBank=14;

 if(HAL_CAN_ConfigFilter(&hcan,&sFilterConfig)!=HAL_OK){

   /* Filter configuration Error */

   Error_Handler();

 }

 if(HAL_CAN_Start(&hcan)!=HAL_OK){

   /* Start Error */

   Error_Handler();

 }

/*активируем обработчик прерывани�?*/

 if (HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING) !=HAL_OK) { Error_Handler(); }

 if (HAL_CAN_ActivateNotification(&hcan, CAN_IT_ERROR) !=HAL_OK) { Error_Handler(); }

   /* Notification Error */

 TxOffHeader.StdId=0x3B3; 0x43E; 0x171; 0x22A; 0x017;

 TxOffHeader.ExtId=0x00;

 TxOffHeader.RTR=CAN_RTR_DATA;

 TxOffHeader.IDE=CAN_ID_STD;

 TxOffHeader.DLC=8;

 TxOffHeader.TransmitGlobalTime=DISABLE;

 TxData[0]=0x10, 0x00, 0x10, 0x10, 0x10, 0x10;

 TxData[1]=0x80, 0x9D, 0x80, 0x80, 0x80, 0x80;

 TxData[2]=0x74, 0x10, 0x74, 0x74, 0x74, 0x74;

 TxData[3]=0x07, 0x80, 0x07, 0x07, 0X07, 0x07;

 TxData[4]=0x0F, 0x00, 0x0F, 0x0F; 0x0F, 0x0F;

 TxData[5]=0xFF, 0x00, 0xFF, 0xFF; 0xFF, 0xFF;

 TxData[6]=0x00, 0x00, 0x00, 0x00; 0x00, 0x00;

 TxData[7]=0x00, 0x00, 0x00, 0x00; 0x00, 0x00;

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

   if(TicksMs == 0){

     TicksMs = PERIOD;

     HAL_CAN_AddTxMessage(&hcan,&TxOffHeader,TxData,&TxMailbox);

     HAL_GPIO_WritePin(Led2_GPIO_Port, Led2_Pin, GPIO_PIN_SET);  //вкл �?ветодиод

   }

  /* USER CODE END WHILE */

/* USER CODE BEGIN 4 */

void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef* hcan){

  //HAL_GPIO_TogglePin(Led1_GPIO_Port, Led1_Pin);

}

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef* hcan){

  HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &RxHeader,RxData);

  //HAL_GPIO_TogglePin(Led2_GPIO_Port, Led2_Pin);

}

/* USER CODE END 4 */

This topic has been closed for replies.

10 replies

Tesla DeLorean
Guru
January 6, 2020

Hard to guess at your implementation details.

For the transmit to succeed you'd need a receiving node on the network with equivalent bit rate setting to respond with an acknowledgement.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Bob S
Super User
January 6, 2020

I haven't looked at the rest of the code, but what do you expect these lines to actually do?

TxOffHeader.StdId=0x3B3; 0x43E; 0x171; 0x22A; 0x017;

and

TxData[0]=0x10, 0x00, 0x10, 0x10, 0x10, 0x10;
TxData[1]=0x80, 0x9D, 0x80, 0x80, 0x80, 0x80;
TxData[2]=0x74, 0x10, 0x74, 0x74, 0x74, 0x74;
TxData[3]=0x07, 0x80, 0x07, 0x07, 0X07, 0x07;
TxData[4]=0x0F, 0x00, 0x0F, 0x0F; 0x0F, 0x0F;
TxData[5]=0xFF, 0x00, 0xFF, 0xFF; 0xFF, 0xFF;
TxData[6]=0x00, 0x00, 0x00, 0x00; 0x00, 0x00;
TxData[7]=0x00, 0x00, 0x00, 0x00; 0x00, 0x00;

Tesla DeLorean
Guru
January 6, 2020

It isn't C, I think it just shows the 5 sets of data being sent.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
iboxe
iboxeAuthor
Associate
January 6, 2020

And how it should be right? I’m studying the can-bus of a car and while it’s hard for me

iboxe
iboxeAuthor
Associate
January 6, 2020

I sent one identifier and one date.

TxOffHeader.StdId=0x3B3;

 TxOffHeader.ExtId=0x00;

 TxOffHeader.RTR=CAN_RTR_DATA;

 TxOffHeader.IDE=CAN_ID_STD;

 TxOffHeader.DLC=8;

 TxOffHeader.TransmitGlobalTime=DISABLE;

 TxData[0]=0x10;

 TxData[1]=0x80;

 TxData[2]=0x74;

 TxData[3]=0x07;

 TxData[4]=0x0F;

 TxData[5]=0xFF;

 TxData[6]=0x00;

 TxData[7]=0x00;

I managed. But I tried sending some identifiers. And it was not successful.

Jack Peacock_2
Associate II
January 7, 2020

If the other node is a car it's using the J1939 CAN protocol, which requires the full 29-bit extended address. What specific SAE PGN are you trying to access?

If your RTR request isn't properly formatted for J1939 I would not expect to see a reply. J1939 is sensitive to PGN objects, make sure you have the right one and it's supported on your car. Not every PGN is supported by a vendor. The packet will be ignored since it doesn't follow the protocol, or if your object doesn't exist.

Have you tried examining the CAN error registers to see if some bus type error is being reported? If you're being disconnected due to a bus timeout your request isn't being sent.

Jack Peacock

iboxe
iboxeAuthor
Associate
January 7, 2020

No no no, the protocol has nothing to do with it.I’m sending one message.I do not know how to write code for five messages.

iboxe
iboxeAuthor
Associate
January 7, 2020

https://youtu.be/_SZnZeglpGM

An example of the work of the can explorer. Five messages sends.