Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years ago.
how to use HAL commands??
I have CANBUS working under HAL drivers in uV5 but how can I add these three components ?
How to translate this:
-2- Configure the CAN Filter
#
#
#
#
#
#
#
#
#
sFilterConfig.FilterNumber = 0;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterIdHigh = 0x400 << 5; 11-bit ID in top bits
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x600 << 5; resolves as 0x01xx
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = 0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.BankNumber = 0;
if (HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK) { Filter configuration Error Error_Handler();
sprintf(console::string,"Can Filter configuration Error\n\r"); console::io.puts(console::string); }
and translate this:
HAL_CAN_ENABLE_IT (&hcan, CAN_IT_FMP1); HAL_CAN_ENABLE_IT (&hcan, CAN_IT_FMP0);
and this:
void CEC_CAN_IRQHandler(void) { /* USER CODE BEGIN CEC_CAN_IRQn 0 */ CAN_IRQFlag = true; checkCanRxFifos(); receive CAN messages before HAL sees them.
/* USER CODE END CEC_CAN_IRQn 0 */ HAL_CAN_IRQHandler(&hcan); /* USER CODE BEGIN CEC_CAN_IRQn 1 */
/* USER CODE END CEC_CAN_IRQn 1 */ }
1 Answer
7 years ago.
Hello Nick,
Have a look at the CANnucleo library. It has been implemented by calling HAL commands.
Hi, I used your code CANnucleo (you have a few renditions) successfully, but I had to add this to make the RX interrupt work.
void onMsgReceived() { msgAvailable = true; ++Counter; can.read(rxMsg); }
if (msgAvailable){ msgAvailable = false; setCursor(4,60); Usart1.printf("Can msgAvailable %d \r\n",Counter);
led = ON; turn the LED on setCursor(0,0); Usart1.printf("CAN message received\r\n"); printMsg(rxMsg);
Filtering performed by software: if(rxMsg.id == RX_ID) { rxMsg >> counter >> voltage; extract data from the received CAN message Usart1.printf(" counter = %d\r\n", counter); Usart1.printf(" voltage = %e V\r\n", voltage); timer.start(); transmission lag } }
thanks for the support. Now I will work on loading the RxTables under interrupt so we don't lose any frames. then the Tx...
posted by 10 Apr 2017