cancel
Showing results for 
Search instead for 
Did you mean: 

New version of STM32F1 CAN configuration error on some pins

User.23
Associate II

STM32F103C8T6 

V1.7.0 

TRUESTUDIO

FREERTOS

UBUNTU16.04

Figure 1 configure CAN to send to die

Figure 2 configure CAN no problem

Haven't tried CAN acceptance yet

1 REPLY 1
User.23
Associate II

My code:

​#include "sys_include.h"

void CAN_Init(void){

CAN_Filter_Init();

HAL_CAN_Start(&hcan);

HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING);

HAL_CAN_ActivateNotification(&hcan,CAN_IT_TX_MAILBOX_EMPTY);

}

void CAN_Filter_Init(void){

CAN_FilterTypeDef sFilterConfig;

sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

sFilterConfig.FilterIdHigh = 0x0000;

sFilterConfig.FilterIdLow = 0x0000;

sFilterConfig.FilterMaskIdHigh = 0x0000;

sFilterConfig.FilterMaskIdLow = 0x0000;

sFilterConfig.FilterFIFOAssignment = 0;

sFilterConfig.FilterActivation = ENABLE;

sFilterConfig.FilterBank = 14;

HAL_CAN_ConfigFilter(&hcan, &sFilterConfig);

}

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *can)

{

CAN_Message rxdata;

CAN_RxHeaderTypeDef rx_message;

if(can->Instance == hcan.Instance)

{

HAL_CAN_GetRxMessage(can,CAN_RX_FIFO0,&rx_message,rxdata.data);

if(rx_message.StdId == 0x201){

// can_test.backposition = rxdata.data[0] << 24 | rxdata.data[1] << 16 | rxdata.data[2] << 8 | rxdata.data[3];

// can_test.backposition = rxdata.data[4] << 8 | rxdata.data[5];

}

}

HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING);

}

void Send_Message(int32_t distance,int16_t speed,int16_t pwm3){

CAN_Message txdata;

CAN_TxHeaderTypeDef tx_message;

tx_message.StdId = 0x201;

tx_message.IDE = CAN_ID_STD;

tx_message.RTR = CAN_RTR_DATA;

tx_message.DLC = 0x08;

txdata.data[0] = 0;

txdata.data[1] = 0;

txdata.data[2] = 0;

txdata.data[3] = 0;

txdata.data[4] = 0;

txdata.data[5] = 0;

txdata.data[6] = 0;

txdata.data[7] = 0;

// txdata.data[0] = (unsigned char)(distance >> 24);

// txdata.data[1] = (unsigned char)(distance >> 16);

// txdata.data[2] = (unsigned char)(distance >> 8);

// txdata.data[3] = (unsigned char)distance;

// txdata.data[4] = (unsigned char)(speed >> 8);

// txdata.data[5] = (unsigned char)speed;

// txdata.data[6] = (unsigned char)(pwm3 >> 8);

// txdata.data[7] = (unsigned char)pwm3;

HAL_CAN_AddTxMessage(&hcan,&tx_message,txdata.data,(uint32_t*)CAN_TX_MAILBOX0);

}