enabled can support and cleaned up the code for it
This commit is contained in:
parent
757165c9bf
commit
8983097b87
@ -19,13 +19,14 @@ once every 1s in states: INACTIVE, PRECHARGE, DISCHARGE, CHARGING, ERROR.
|
|||||||
once every 0.5s in states: READY, ACTIVE.
|
once every 0.5s in states: READY, ACTIVE.
|
||||||
with format of:
|
with format of:
|
||||||
CAN Messages:
|
CAN Messages:
|
||||||
- MVBMS Status (1B), Powerground Status 0-100% (1 bit)
|
MVBMS Status (1B), Powerground Status 0-100% (1B)
|
||||||
- Battery: SoC (1B), Pack Voltage (2B), Current (1B),
|
Battery: SoC (1B), Pack Voltage (2B), Current (1B),
|
||||||
Min/Max. Cell Temp (ID, Min Temp, ID, Max Temp)(4B),
|
|
||||||
Min/Max Cell Voltage (ID, Min Voltage, ID, Max Voltage)(4B)
|
Min/Max. Cell Temp (ID, Min Temp, ID, Max Temp)(3B),
|
||||||
|
Min/Max Cell Voltage (ID, Min Voltage, ID, Max Voltage)(3B)
|
||||||
|
|
||||||
bit 0-2: status
|
bit 0-2: status
|
||||||
bit 0-7:
|
bit 3-7:
|
||||||
bit 8-15: State of Charge from 0-100%
|
bit 8-15: State of Charge from 0-100%
|
||||||
bit 16-31: Battery voltage
|
bit 16-31: Battery voltage
|
||||||
bit 32-47: Current measurement
|
bit 32-47: Current measurement
|
||||||
@ -48,8 +49,11 @@ void can_handle_send_status() {
|
|||||||
int8_t id = -1;
|
int8_t id = -1;
|
||||||
int16_t temp = INT16_MIN;
|
int16_t temp = INT16_MIN;
|
||||||
sm_check_cell_temps(&id, &temp);
|
sm_check_cell_temps(&id, &temp);
|
||||||
data[6] = (id << 5) | (temp >> 4); // there are only 7 TMP1075
|
data[6] = (id << 4) | (temp >> 4); // there are only 7 TMP1075
|
||||||
ftcan_transmit(CAN_ID_OUT, data, sizeof(data));
|
ftcan_transmit(CAN_ID_OUT, data, sizeof(data));
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -59,9 +63,9 @@ to the sm_handle_ams_in() which handles the state machine transition.
|
|||||||
void can_handle_recieve_command(const uint8_t *data){
|
void can_handle_recieve_command(const uint8_t *data){
|
||||||
if (data[0] == 0x00 && data[1] == 0x00){
|
if (data[0] == 0x00 && data[1] == 0x00){
|
||||||
sm_handle_ams_in(data);
|
sm_handle_ams_in(data);
|
||||||
} else if (data[0] == 0b10000000 && data[1] == 0x00){
|
} else if (data[0] == 0x01 && data[1] == 0x00){
|
||||||
sm_handle_ams_in(data);
|
sm_handle_ams_in(data);
|
||||||
} else if (data[0] == 0b11000000 && data[1] <= 100) {
|
} else if (data[0] == 0x02 && data[1] <= 100) {
|
||||||
sm_handle_ams_in(data);
|
sm_handle_ams_in(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,9 +73,11 @@ void can_handle_recieve_command(const uint8_t *data){
|
|||||||
/*
|
/*
|
||||||
implements the _weak method ftcan_msg_recieved_cb() which throws an interrupt when a CAN message is recieved.
|
implements the _weak method ftcan_msg_recieved_cb() which throws an interrupt when a CAN message is recieved.
|
||||||
it only checks if the id is and datalen is correct thans hands data over to can_handle_recieve_command().
|
it only checks if the id is and datalen is correct thans hands data over to can_handle_recieve_command().
|
||||||
|
|
||||||
|
in MXCUBE under CAN NVIC settings "USB low priority or CAN_RX0 interrupts" has to be on
|
||||||
*/
|
*/
|
||||||
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data){
|
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data){
|
||||||
if (id == 0x501 && datalen == 16){
|
if (id == 0x501 && datalen == 2){
|
||||||
can_handle_recieve_command(data);
|
can_handle_recieve_command(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,11 @@ void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
|
|||||||
GPIO_InitStruct.Alternate = GPIO_AF9_CAN;
|
GPIO_InitStruct.Alternate = GPIO_AF9_CAN;
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* CAN interrupt Init */
|
||||||
|
HAL_NVIC_SetPriority(USB_LP_CAN_RX0_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(USB_LP_CAN_RX0_IRQn);
|
||||||
|
HAL_NVIC_SetPriority(CAN_RX1_IRQn, 0, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(CAN_RX1_IRQn);
|
||||||
/* USER CODE BEGIN CAN_MspInit 1 */
|
/* USER CODE BEGIN CAN_MspInit 1 */
|
||||||
|
|
||||||
/* USER CODE END CAN_MspInit 1 */
|
/* USER CODE END CAN_MspInit 1 */
|
||||||
@ -137,6 +142,9 @@ void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
|
|||||||
*/
|
*/
|
||||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
|
||||||
|
|
||||||
|
/* CAN interrupt DeInit */
|
||||||
|
HAL_NVIC_DisableIRQ(USB_LP_CAN_RX0_IRQn);
|
||||||
|
HAL_NVIC_DisableIRQ(CAN_RX1_IRQn);
|
||||||
/* USER CODE BEGIN CAN_MspDeInit 1 */
|
/* USER CODE BEGIN CAN_MspDeInit 1 */
|
||||||
|
|
||||||
/* USER CODE END CAN_MspDeInit 1 */
|
/* USER CODE END CAN_MspDeInit 1 */
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/* External variables --------------------------------------------------------*/
|
/* External variables --------------------------------------------------------*/
|
||||||
|
extern CAN_HandleTypeDef hcan;
|
||||||
/* USER CODE BEGIN EV */
|
/* USER CODE BEGIN EV */
|
||||||
|
|
||||||
/* USER CODE END EV */
|
/* USER CODE END EV */
|
||||||
@ -198,6 +198,34 @@ void SysTick_Handler(void)
|
|||||||
/* please refer to the startup file (startup_stm32f3xx.s). */
|
/* please refer to the startup file (startup_stm32f3xx.s). */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles USB low priority or CAN_RX0 interrupts.
|
||||||
|
*/
|
||||||
|
void USB_LP_CAN_RX0_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN USB_LP_CAN_RX0_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_LP_CAN_RX0_IRQn 0 */
|
||||||
|
HAL_CAN_IRQHandler(&hcan);
|
||||||
|
/* USER CODE BEGIN USB_LP_CAN_RX0_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END USB_LP_CAN_RX0_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles CAN RX1 interrupt.
|
||||||
|
*/
|
||||||
|
void CAN_RX1_IRQHandler(void)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN CAN_RX1_IRQn 0 */
|
||||||
|
|
||||||
|
/* USER CODE END CAN_RX1_IRQn 0 */
|
||||||
|
HAL_CAN_IRQHandler(&hcan);
|
||||||
|
/* USER CODE BEGIN CAN_RX1_IRQn 1 */
|
||||||
|
|
||||||
|
/* USER CODE END CAN_RX1_IRQn 1 */
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
|
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
|||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
# File automatically-generated by tool: [projectgenerator] version: [4.3.0-B58] date: [Thu May 30 20:42:23 EEST 2024]
|
# File automatically-generated by tool: [projectgenerator] version: [4.3.0-B58] date: [Mon Jun 03 16:11:34 EEST 2024]
|
||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
|
@ -63,6 +63,7 @@ Mcu.UserName=STM32F302CBTx
|
|||||||
MxCube.Version=6.11.1
|
MxCube.Version=6.11.1
|
||||||
MxDb.Version=DB.6.0.111
|
MxDb.Version=DB.6.0.111
|
||||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
|
NVIC.CAN_RX1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.ForceEnableDMAVector=true
|
NVIC.ForceEnableDMAVector=true
|
||||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
@ -72,6 +73,7 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
|||||||
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
||||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
||||||
|
NVIC.USB_LP_CAN_RX0_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||||
PA0.GPIOParameters=PinState,GPIO_Label
|
PA0.GPIOParameters=PinState,GPIO_Label
|
||||||
PA0.GPIO_Label=RELAY_EN
|
PA0.GPIO_Label=RELAY_EN
|
||||||
|
Loading…
x
Reference in New Issue
Block a user