2024-03-13 07:04 PM
Please help how I can find this library.
STM32-H7A3ZI-Q with latest STM32CubeIDE
2024-03-13 07:13 PM
There is no such file.
There is stm32h7xx_hal_fdcan.h, which you can find here:
If you initialize an FDCAN peripheral within your IOC file and generate code, CubeMX will put this file in your project.
2024-03-15 07:55 PM
My friend sent me the code with #include "stm32h7xx_hal_can.h"
But no way I can find it.
2024-03-15 08:19 PM
Here ia the code sample
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_adc.h"
#include "stm32h7xx_hal_can.h"
ADC_HandleTypeDef hadc1;
CAN_HandleTypeDef hcan1;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_ADC1_Init(void);
static void MX_CAN1_Init(void);
int main(void) {
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_ADC1_Init();
MX_CAN1_Init();
uint16_t adc_value;
while (1) {
// Start ADC conversion
HAL_ADC_Start(&hadc1);
// Wait for conversion to complete
if (HAL_ADC_PollForConversion(&hadc1, 100) == HAL_OK) {
// Read ADC value
adc_value = HAL_ADC_GetValue(&hadc1);
// Process ADC value (filtering, amplification if needed)
// Send data through CAN bus
CAN_TxHeaderTypeDef TxHeader;
uint8_t TxData[8];
TxHeader.StdId = 0x321; // Example CAN ID
TxHeader.DLC = 8;
TxHeader.IDE = CAN_ID_STD;
TxHeader.RTR = CAN_RTR_DATA;
TxData[0] = (adc_value >> 😎 & 0xFF;
TxData[1] = adc_value & 0xFF;
HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, (uint32_t *)CAN_TX_MAILBOX0);
}
}
}
2024-03-15 08:48 PM
If I can't find CAN, can I use FDCAN as replacement. And below ts the code for CAN. Canyou help convert to FDCAN, please?
static void MX_CAN1_Init(void) {
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 1;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_13TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = ENABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK) {
Error_Handler();
}
}
int main(void) {
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_ADC1_Init();
MX_CAN1_Init();
uint16_t adc_value;
while (1) {
// Start ADC conversion
HAL_ADC_Start(&hadc1);
// Wait for conversion to complete
if (HAL_ADC_PollForConversion(&hadc1, 100) == HAL_OK) {
// Read ADC value
adc_value = HAL_ADC_GetValue(&hadc1);
// Process ADC value (filtering, amplification if needed)
// Send data through CAN bus
CAN_TxHeaderTypeDef TxHeader;
uint8_t TxData[8];
TxHeader.StdId = 0x321; // Example CAN ID
TxHeader.DLC = 8;
TxHeader.IDE = CAN_ID_STD;
TxHeader.RTR = CAN_RTR_DATA;
TxData[0] = (adc_value >> 😎 & 0xFF;
TxData[1] = adc_value & 0xFF;
HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, (uint32_t *)CAN_TX_MAILBOX0);
}
}
}
2024-03-15 11:38 PM - edited 2024-03-15 11:42 PM
Hello,
There is no stm32h7xx_hal_can.h in H7 cube HAL. You need to use FDCAN (stm32h7xx_hal_fdcan.h).
You need to use FDCAN peripheral in classic mode as a replacement of bxCAN.
Refer to this example: https://github.com/STMicroelectronics/STM32CubeH7/tree/b9d11df3020deef82310c88f3d8590d076b43ef7/Projects/STM32H743I-EVAL/Examples/FDCAN/FDCAN_Classic_Frame_Networking
2024-03-16 08:52 AM - edited 2024-03-16 08:53 AM
It doesn't exist, as I explained earlier, so you won't be finding it.
Perhaps ask your friend why he is including a file that doesn't exist.