2017-03-16 07:07 PM
Hello, I m a new guy in ST MCU
I use CubeMX as start point and create a project for CAN1 and CAN2 Communication, and test a simple code below
result is 'HAL_CAN_Transmit(&hcan1, 50); ' always return Time out error;
can any one have idea about it?
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();/* Configure the system clock */
SystemClock_Config();/* Initialize all configured peripherals */
MX_CAN1_Init(); MX_CAN2_Init();hcan1.pTxMsg = &TxM;
hcan1.pRxMsg = &RxM; sFilterConfig.FilterNumber = 0; sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST; sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT; sFilterConfig.FilterIdHigh = 0x0; sFilterConfig.FilterIdLow = 0; sFilterConfig.FilterMaskIdHigh = 0; sFilterConfig.FilterMaskIdLow = 0; sFilterConfig.FilterFIFOAssignment = 0; sFilterConfig.FilterActivation = ENABLE; sFilterConfig.BankNumber = 14; HAL_CAN_ConfigFilter (&hcan1, &sFilterConfig); hcan1.pTxMsg ->StdId = 0x11; hcan1.pTxMsg ->RTR = CAN_RTR_DATA; hcan1.pTxMsg ->IDE = CAN_ID_STD; hcan1.pTxMsg ->DLC = 2; HAL_CAN_Receive_IT (&hcan1, CAN_FIFO0 );while (1)
{ HAL_Delay (1000); hcan1.pTxMsg ->Data [0] = 0x5a; hcan1.pTxMsg ->Data [1] = 0x6d; HAL_CAN_Transmit(&hcan1, 50); }2017-03-21 03:07 AM
Looks like you are requesting data from ID 0x
Your line:
hcan1.pTxMsg ->RTR = CAN_RTR_DATA;
�?
Says request for remote data. If the device at 0x11 doesn't respond with 2 bytes (because your DLC of 2 means that the remote must response with 2 as well) or isn't setup for response to RTR frames.... you won't get anything but silence.
Not completely sure but if you don't have anything else on the bus to awk the transmission, you'd probably timeout as well.2017-03-30 09:04 AM
What should the value of
hcan1.pTxMsg ->RTR be then?