Can define settings

This commit is contained in:
Вячеслав Штейбезандт 2024-11-20 14:22:35 +03:00
parent 7abcc6e7d3
commit 167de72ea4
3 changed files with 26 additions and 16 deletions

View File

@ -10,10 +10,20 @@
#define ONLINE 1; #define ONLINE 1;
#define OFFLINE 0; #define OFFLINE 0;
// TIM defines // TIM defines
#define TIM_REQUESTER_Prescaler 64000 #define TIM_REQUESTER_Prescaler 64000
//CAN Settings
#define _HCAN hcan
//CAN Speed
#define CAN_SPEED_PRSC_1000KB 2
#define CAN_SPEED_PRSC_500KB 4
#define CAN_SPEED_PRSC_250KB 8
#define CAN_SPEED_PRSC_125KB 16
#define CAN_SPEED_PRSC_50KB 40
#define CAN_CURRENT_SPEED CAN_SPEED_PRSC_250KB
//CAN Filter //CAN Filter
#define ID_MAIN_DEVICE 0x000 #define ID_MAIN_DEVICE 0x000
#define CURRENT_ID_DEVICE 0x002 #define CURRENT_ID_DEVICE 0x002

View File

@ -38,7 +38,7 @@ void MX_CAN_Init(void)
/* USER CODE END CAN_Init 1 */ /* USER CODE END CAN_Init 1 */
hcan.Instance = CAN1; hcan.Instance = CAN1;
hcan.Init.Prescaler = 2; hcan.Init.Prescaler = CAN_CURRENT_SPEED;
hcan.Init.Mode = CAN_MODE_NORMAL; hcan.Init.Mode = CAN_MODE_NORMAL;
hcan.Init.SyncJumpWidth = CAN_SJW_1TQ; hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan.Init.TimeSeg1 = CAN_BS1_13TQ; hcan.Init.TimeSeg1 = CAN_BS1_13TQ;

View File

@ -44,9 +44,9 @@ void REQUESTER_Init(void)
{ {
HAL_Init(); HAL_Init();
MX_CAN_Init(); MX_CAN_Init();
HAL_CAN_Start(&hcan); HAL_CAN_Start(&_HCAN);
REQUESTER_CAN_FILTERS(); REQUESTER_CAN_FILTERS();
HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING); HAL_CAN_ActivateNotification(&_HCAN, CAN_IT_RX_FIFO0_MSG_PENDING);
ControlFlags.IsPulse = 1; ControlFlags.IsPulse = 1;
MX_TIM7_Init(); MX_TIM7_Init();
MX_RTC_Init(); MX_RTC_Init();
@ -200,7 +200,7 @@ __weak HAL_StatusTypeDef CanRequestToAnalogUniversal(struct RXMsg _rxMsg)
data[3] = 'V'; data[3] = 'V';
data[4] = 'E'; data[4] = 'E';
data[5] = 'R'; data[5] = 'R';
return HAL_CAN_AddTxMessage(&hcan, &TxHeader, data, &TxMailBox); return HAL_CAN_AddTxMessage(&_HCAN, &TxHeader, data, &TxMailBox);
} }
__weak HAL_StatusTypeDef CanRequestToAnalogUSTAVKI(struct RXMsg _rxMsg) __weak HAL_StatusTypeDef CanRequestToAnalogUSTAVKI(struct RXMsg _rxMsg)
@ -223,7 +223,7 @@ __weak HAL_StatusTypeDef CanRequestToAnalogUSTAVKI(struct RXMsg _rxMsg)
data[4] = 'V'; data[4] = 'V';
data[5] = 'K'; data[5] = 'K';
data[6] = 'I'; data[6] = 'I';
return HAL_CAN_AddTxMessage(&hcan, &TxHeader, data, &TxMailBox); return HAL_CAN_AddTxMessage(&_HCAN, &TxHeader, data, &TxMailBox);
} }
__weak HAL_StatusTypeDef CanRequestToAnalogUSens(struct RXMsg _rxMsg) __weak HAL_StatusTypeDef CanRequestToAnalogUSens(struct RXMsg _rxMsg)
@ -245,7 +245,7 @@ __weak HAL_StatusTypeDef CanRequestToAnalogUSens(struct RXMsg _rxMsg)
data[3] = 'e'; data[3] = 'e';
data[4] = 'n'; data[4] = 'n';
data[5] = 's'; data[5] = 's';
return HAL_CAN_AddTxMessage(&hcan, &TxHeader, data, &TxMailBox); return HAL_CAN_AddTxMessage(&_HCAN, &TxHeader, data, &TxMailBox);
} }
__weak HAL_StatusTypeDef CanRequestToAnalogISens(struct RXMsg _rxMsg) __weak HAL_StatusTypeDef CanRequestToAnalogISens(struct RXMsg _rxMsg)
@ -267,7 +267,7 @@ __weak HAL_StatusTypeDef CanRequestToAnalogISens(struct RXMsg _rxMsg)
data[3] = 'e'; data[3] = 'e';
data[4] = 'n'; data[4] = 'n';
data[5] = 's'; data[5] = 's';
return HAL_CAN_AddTxMessage(&hcan, &TxHeader, data, &TxMailBox); return HAL_CAN_AddTxMessage(&_HCAN, &TxHeader, data, &TxMailBox);
} }
__weak HAL_StatusTypeDef CanRequestToAnalogTSens(struct RXMsg _rxMsg) __weak HAL_StatusTypeDef CanRequestToAnalogTSens(struct RXMsg _rxMsg)
@ -289,7 +289,7 @@ __weak HAL_StatusTypeDef CanRequestToAnalogTSens(struct RXMsg _rxMsg)
data[3] = 'e'; data[3] = 'e';
data[4] = 'n'; data[4] = 'n';
data[5] = 's'; data[5] = 's';
return HAL_CAN_AddTxMessage(&hcan, &TxHeader, data, &TxMailBox); return HAL_CAN_AddTxMessage(&_HCAN, &TxHeader, data, &TxMailBox);
} }
/** /**
@ -358,7 +358,7 @@ __weak HAL_StatusTypeDef CanRequestToBroadcastStatus(struct RXMsg _rxMsg)
data[5] = DateToUpdate.Date; data[5] = DateToUpdate.Date;
data[6] = DateToUpdate.WeekDay; data[6] = DateToUpdate.WeekDay;
return HAL_CAN_AddTxMessage(&hcan, &TxHeader, data, &TxMailBox); return HAL_CAN_AddTxMessage(&_HCAN, &TxHeader, data, &TxMailBox);
} }
__weak void CanRequestToBroadcastOnOff(struct RXMsg _rxMsg) __weak void CanRequestToBroadcastOnOff(struct RXMsg _rxMsg)
@ -713,7 +713,7 @@ void REQUESTER_Pulse_TIM_Handler()
PulseStage = 0; PulseStage = 0;
} }
data[0] = PulseStage++; data[0] = PulseStage++;
HAL_CAN_AddTxMessage(&hcan, &TxHeader, data, &TxMailBox); HAL_CAN_AddTxMessage(&_HCAN, &TxHeader, data, &TxMailBox);
} }
} }
@ -768,7 +768,7 @@ void REQUESTER_CAN_FILTERS()
canFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0; canFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
canFilterConfig.FilterActivation = ENABLE; canFilterConfig.FilterActivation = ENABLE;
canFilterConfig.SlaveStartFilterBank = 14; canFilterConfig.SlaveStartFilterBank = 14;
if(HAL_CAN_ConfigFilter(&hcan, &canFilterConfig) != HAL_OK) if(HAL_CAN_ConfigFilter(&_HCAN, &canFilterConfig) != HAL_OK)
{ {
Error_Handler(); Error_Handler();
} }
@ -782,7 +782,7 @@ void REQUESTER_CAN_FILTERS()
/*Маска 1.1111.1110.<...>. Нули - любые символы. Единицы - точное соответствие фильтру выше.*/ /*Маска 1.1111.1110.<...>. Нули - любые символы. Единицы - точное соответствие фильтру выше.*/
canFilterConfig.FilterMaskIdHigh = (uint16_t)(CAN_DEVICE_ID_FILTER>>13); canFilterConfig.FilterMaskIdHigh = (uint16_t)(CAN_DEVICE_ID_FILTER>>13);
canFilterConfig.FilterMaskIdLow = (uint16_t)(CAN_DEVICE_ID_FILTER<<3) | CAN_IDE_32; canFilterConfig.FilterMaskIdLow = (uint16_t)(CAN_DEVICE_ID_FILTER<<3) | CAN_IDE_32;
if(HAL_CAN_ConfigFilter(&hcan, &canFilterConfig) != HAL_OK) if(HAL_CAN_ConfigFilter(&_HCAN, &canFilterConfig) != HAL_OK)
{ {
Error_Handler(); Error_Handler();
} }
@ -793,7 +793,7 @@ void REQUESTER_CAN_FILTERS()
canFilterConfig.FilterIdLow = (uint16_t)(0x03000000<<5) | CAN_IDE_32; canFilterConfig.FilterIdLow = (uint16_t)(0x03000000<<5) | CAN_IDE_32;
canFilterConfig.FilterMaskIdHigh = (uint16_t)(CAN_DATA_TYPE_FILTER>>13); // we're checking only high 13 bits, that contained "key" canFilterConfig.FilterMaskIdHigh = (uint16_t)(CAN_DATA_TYPE_FILTER>>13); // we're checking only high 13 bits, that contained "key"
canFilterConfig.FilterMaskIdLow = (uint16_t)(CAN_DATA_TYPE_FILTER<<3) | CAN_IDE_32; // 1<<2 - set IDE bit canFilterConfig.FilterMaskIdLow = (uint16_t)(CAN_DATA_TYPE_FILTER<<3) | CAN_IDE_32; // 1<<2 - set IDE bit
if(HAL_CAN_ConfigFilter(&hcan, &canFilterConfig) != HAL_OK) if(HAL_CAN_ConfigFilter(&_HCAN, &canFilterConfig) != HAL_OK)
{ {
Error_Handler(); Error_Handler();
} }
@ -805,7 +805,7 @@ void REQUESTER_CAN_FILTERS()
canFilterConfig.FilterIdLow = (uint16_t)(HighIdFilter(DATA_TYPE_PULSE)<<5) | CAN_IDE_32; canFilterConfig.FilterIdLow = (uint16_t)(HighIdFilter(DATA_TYPE_PULSE)<<5) | CAN_IDE_32;
canFilterConfig.FilterMaskIdHigh = (uint16_t)(CAN_DATA_TYPE_FILTER>>13); // we're checking only high 13 bits, that contained "key" canFilterConfig.FilterMaskIdHigh = (uint16_t)(CAN_DATA_TYPE_FILTER>>13); // we're checking only high 13 bits, that contained "key"
canFilterConfig.FilterMaskIdLow = (uint16_t)(CAN_DATA_TYPE_FILTER<<3) | CAN_IDE_32; // 1<<2 - set IDE bit canFilterConfig.FilterMaskIdLow = (uint16_t)(CAN_DATA_TYPE_FILTER<<3) | CAN_IDE_32; // 1<<2 - set IDE bit
if(HAL_CAN_ConfigFilter(&hcan, &canFilterConfig) != HAL_OK) if(HAL_CAN_ConfigFilter(&_HCAN, &canFilterConfig) != HAL_OK)
{ {
Error_Handler(); Error_Handler();
} }
@ -816,7 +816,7 @@ void REQUESTER_CAN_FILTERS()
canFilterConfig.FilterIdLow = (uint16_t)(HighIdFilter(0)<<5) | CAN_IDE_32; canFilterConfig.FilterIdLow = (uint16_t)(HighIdFilter(0)<<5) | CAN_IDE_32;
canFilterConfig.FilterMaskIdHigh = (uint16_t)(0>>13); // we're checking only high 13 bits, that contained "key" canFilterConfig.FilterMaskIdHigh = (uint16_t)(0>>13); // we're checking only high 13 bits, that contained "key"
canFilterConfig.FilterMaskIdLow = (uint16_t)(0<<3) | CAN_IDE_32; // 1<<2 - set IDE bit canFilterConfig.FilterMaskIdLow = (uint16_t)(0<<3) | CAN_IDE_32; // 1<<2 - set IDE bit
if(HAL_CAN_ConfigFilter(&hcan, &canFilterConfig) != HAL_OK) if(HAL_CAN_ConfigFilter(&_HCAN, &canFilterConfig) != HAL_OK)
{ {
Error_Handler(); Error_Handler();
} }