cancel
Showing results for 
Search instead for 
Did you mean: 

CAN transmit acknowledged even though no receiving node.

LHuss.1
Associate II

I want to set up error handling for my CAN messages, and I wanted to start with errors from sending messages to IDs not on the CAN bus net. However, every message I send is acknowledged. There is only stm32 chip set up on the net and the rest are currently TMC Pandrive motors. 
I am sending messages to individual motors with different IDs without issue - they're received and the motors react accordingly. 
So I am not sure how or why these messages to other CAN IDs are acknowledged. 
Below is the code I use in my CAN interface file. 

 

#include <CANInterface.h>

CAN_RxHeaderTypeDef rxHeader;
CAN_TxHeaderTypeDef txHeader;
std::vector<uint8_t> canRX(7, 0);
CAN_FilterTypeDef canfil;
uint32_t canMailbox;

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan1) {
	std::vector<char> sendBuf(60, 0);
	uint8_t bufLen = sprintf(sendBuf.data(), "response triggered\r\n");
	HAL_UART_Transmit(&huart5, (uint8_t *)sendBuf.data(), bufLen, 200);
	HAL_CAN_GetRxMessage(hcan1, CAN_RX_FIFO0, &rxHeader, canRX.data());
}

void sendCANMessage(uint8_t component, std::vector<uint8_t> canMessage) {
	txHeader.StdId = component;
	HAL_StatusTypeDef status = HAL_CAN_AddTxMessage(&hcan1, &txHeader, canMessage.data(), &canMailbox);
	std::vector<char> sendBuf(60, 0);
	uint8_t bufLen = sprintf(sendBuf.data(), "status: %d\r\n", status);
	HAL_UART_Transmit(&huart5, (uint8_t *)sendBuf.data(), bufLen, 200);
}

void CANSetup() {
	txHeader.DLC = 7;
	txHeader.StdId = 0x02;
	txHeader.IDE = CAN_ID_STD;
	txHeader.RTR = CAN_RTR_DATA;
	txHeader.TransmitGlobalTime = DISABLE;

	canfil.FilterFIFOAssignment = CAN_FILTER_FIFO0;
	canfil.FilterIdHigh = (1 << 5);
	canfil.FilterIdLow = 0;
	canfil.FilterMaskIdHigh = 0;
	canfil.FilterMaskIdLow = 0;
	canfil.FilterScale = CAN_FILTERSCALE_16BIT;
	canfil.FilterBank = 14;
	canfil.SlaveStartFilterBank = 0;
	canfil.FilterActivation = ENABLE;

	HAL_CAN_ConfigFilter(&hcan1, &canfil);
	HAL_CAN_Start(&hcan1);
	HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);
}

 

1 ACCEPTED SOLUTION

Accepted Solutions

You’re not supposed to worry about the structure of the frame. The peripheral is doing it. The frame acknowledgement is performed by any node receiving the frame no matter it’s the recipient or not. The acknowledgement has no relation with the ID but with the consistency of the frame structure and fields/errors etc... This is the CAN protocol defined by Bosch and it's not related to the STM32 product.

From the link: https://www.kvaser.com/can-protocol-tutorial/

SofLit_0-1710676127768.png

Hope I answered your question.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

3 REPLIES 3
SofLit
ST Employee

The frame is acknowledged by at least one node on the bus even it is not the frame recipient. The frame structure needs to be correct to be acknowledged.So what you are seeing is a normal behaviour 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I am not sure how to ensure the structure is correct? 

I know that the body of the message is correct since it makes the motors react, and when I provide the ID for a motor, it only uses that one motor, and the crc must also be correct in it. So what's going wrong when I change the ID to one not existent inside the net? 

Why would that be received by a node who is not the recipient? I was under the impression the node would just ignore it if the ID is not correct.

You’re not supposed to worry about the structure of the frame. The peripheral is doing it. The frame acknowledgement is performed by any node receiving the frame no matter it’s the recipient or not. The acknowledgement has no relation with the ID but with the consistency of the frame structure and fields/errors etc... This is the CAN protocol defined by Bosch and it's not related to the STM32 product.

From the link: https://www.kvaser.com/can-protocol-tutorial/

SofLit_0-1710676127768.png

Hope I answered your question.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.