cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32F4 CANbus Acknowledgment error problem

Sergen
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Sergen
Associate III

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.

View solution in original post

12 REPLIES 12
LCE
Principal

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

Then maybe remove one of the 120R resistors.

Sergen
Associate III

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

Sergen
Associate III

unfortunately it didn't work

Sergen
Associate III

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

Karl Yamashita
Lead II

Post some code

If you find my answers useful, click the accept button so that way others can see the solution.

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 */

}

Sergen
Associate III

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 */

}

LCE
Principal

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?

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

UseCode Snippet.png

If you find my answers useful, click the accept button so that way others can see the solution.