Skip to main content
Associate III
Nov 13, 2023 11:40 AM UTC
Solved

Stm32F4 CANbus Acknowledgment error problem

Hello everyone. The last time I opened a form related to bit timing, I realized that the problem was in the Canbus transceiver. I added 1-2 revisions and replaced it with the MCP2551 transceiver. Even though there is a device on the other side, I get an acknowledgment error and the logic analyzer is as follows.

This topic has been closed for replies.
SergenBest answer
Associate III
Nov 22, 2023 9:04 AM UTC

Solution: First, I changed the CAN2 mode to loopback and tried to receive data, but I could not receive it. Then I edited the time segment 1 and 2 values ​​and after receiving the data in loopback mode, I tried normal mode and my system worked.

12 replies

LCE
Principal III
Nov 13, 2023 2:56 PM UTC

On the CAN bus, connect CANH with CANH, and CANL with CANL.

Then maybe remove one of the 120R resistors.

SergenAuthor
Associate III
Nov 13, 2023 4:42 PM UTC

Thanks for your support, I will give you feedback when I try it

SergenAuthor
Associate III
Nov 14, 2023 5:47 AM UTC

I found the problem. The message is going to the other party's RX line incorrectly. How can I fix this

Karl Yamashita
Principal
Nov 14, 2023 9:57 PM UTC

Post some code

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
SergenAuthor
Associate III
Nov 15, 2023 12:34 PM UTC

Transmit

int main(void)

{

/* USER CODE BEGIN 1 */

 

/* USER CODE END 1 */

 

/* MCU Configuration--------------------------------------------------------*/

 

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

 

/* USER CODE BEGIN Init */

 

/* USER CODE END Init */

 

/* Configure the system clock */

SystemClock_Config();

 

/* USER CODE BEGIN SysInit */

 

/* USER CODE END SysInit */

 

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_CAN2_Init();

/* USER CODE BEGIN 2 */

 

HAL_CAN_Start(&hcan2);

TxHeader.DLC = 1;

TxHeader.IDE = CAN_ID_STD;

TxHeader.RTR = CAN_RTR_DATA;

TxHeader.StdId = 0x407;

TxData[0] = 0xFA;

HAL_CAN_ActivateNotification(&hcan2,CAN_IT_RX_FIFO0_MSG_PENDING);

/* USER CODE END 2 */

 

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

// int state = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0);

// if(state){

HAL_CAN_AddTxMessage(&hcan2,&TxHeader,TxData,&TxMailbox);

// HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13,GPIO_PIN_SET);

// }

// else{

// HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13,GPIO_PIN_RESET);

// }

HAL_Delay(200);

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}

SergenAuthor
Associate III
Nov 15, 2023 12:35 PM UTC

Receiver

/* USER CODE BEGIN Includes */

CAN_RxHeaderTypeDef RxHeader;

uint8_t RxData[2];

/* USER CODE END Includes */

 

/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */

 

/* USER CODE END PTD */

 

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

 

/* USER CODE END PD */

 

/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */

 

/* USER CODE END PM */

 

/* Private variables ---------------------------------------------------------*/

CAN_HandleTypeDef hcan;

 

/* USER CODE BEGIN PV */

 

/* USER CODE END PV */

 

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_CAN_Init(void);

/* USER CODE BEGIN PFP */

void HAL_CAN_RxFifo0FullCallback(CAN_HandleTypeDef *hcan){

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

}

/* USER CODE END PFP */

 

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

 

/* USER CODE END 0 */

 

/**

* @brief The application entry point.

* @retval int

*/

int main(void)

{

/* USER CODE BEGIN 1 */

 

/* USER CODE END 1 */

 

/* MCU Configuration--------------------------------------------------------*/

 

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

 

/* USER CODE BEGIN Init */

 

/* USER CODE END Init */

 

/* Configure the system clock */

SystemClock_Config();

 

/* USER CODE BEGIN SysInit */

 

/* USER CODE END SysInit */

 

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_CAN_Init();

/* USER CODE BEGIN 2 */

HAL_CAN_Start(&hcan);

HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING);

/* USER CODE END 2 */

 

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}

Karl Yamashita
Principal
Nov 16, 2023 4:09 PM UTC

Edit your post and use Code Sample so it formats your code which makes it easier to read your code

UseCode Snippet.png

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
SergenAuthor
Associate III
Nov 17, 2023 3:21 PM UTC

thanks

LCE
Principal III
Nov 16, 2023 10:05 AM UTC

> I found the problem. The message is going to the other party's RX line incorrectly. 

What do you exactly mean? Some hardware wiring problem?

SergenAuthor
Associate III
Nov 17, 2023 3:20 PM UTC

I did but let me do it again

SergenAuthorBest answer
Associate III
Nov 22, 2023 9:04 AM UTC

Solution: First, I changed the CAN2 mode to loopback and tried to receive data, but I could not receive it. Then I edited the time segment 1 and 2 values ​​and after receiving the data in loopback mode, I tried normal mode and my system worked.