friday code dump
This commit is contained in:
@ -267,7 +267,21 @@ uint8 writeCMD(uint16 command, uint8* args, uint8 arglen) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define ITER_COUNT 50
|
||||
static uint8_t count = 0;
|
||||
static bool isOn = false;
|
||||
|
||||
uint8 readCMD(uint16 command, uint8* buffer, uint8 buflen) {
|
||||
if (count == ITER_COUNT) {
|
||||
HAL_GPIO_WritePin(STATUS_LED_B_GPIO_Port, STATUS_LED_B_Pin, isOn ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
|
||||
count = 0;
|
||||
isOn = !isOn;
|
||||
} else {
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
uint8 txbuffer[6 + buflen] = {};
|
||||
uint8 rxbuffer[6 + buflen] = {};
|
||||
|
||||
@ -314,11 +328,11 @@ uint8 pollCMD(uint16 command) {
|
||||
}
|
||||
|
||||
void mcuAdbmsCSLow() {
|
||||
//HAL_GPIO_WritePin(CSB_GPIO_Port, CSB_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(CSB_GPIO_Port, CSB_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
void mcuAdbmsCSHigh() {
|
||||
//HAL_GPIO_WritePin(CSB_GPIO_Port, CSB_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(CSB_GPIO_Port, CSB_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
uint8 mcuSPITransmit(uint8* buffer, uint8 buffersize) {
|
||||
|
||||
@ -38,7 +38,6 @@ static bool isOn = false;
|
||||
void ams_can_send_status() {
|
||||
if (count == ITER_COUNT) {
|
||||
HAL_GPIO_WritePin(STATUS_LED_G_GPIO_Port, STATUS_LED_G_Pin, isOn ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(STATUS_LED_B_GPIO_Port, STATUS_LED_B_Pin, isOn ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
|
||||
count = 0;
|
||||
isOn = !isOn;
|
||||
|
||||
@ -35,7 +35,7 @@ uint16_t amsov = 0;
|
||||
uint8_t amserrorcode = 0;
|
||||
uint8_t amswarningcode = 0;
|
||||
|
||||
uint8_t numberofCells = 16;
|
||||
uint8_t numberofCells = 14;
|
||||
uint8_t numberofAux = 0;
|
||||
|
||||
uint8_t packetChecksumFails = 0;
|
||||
@ -52,7 +52,7 @@ struct pollingTimes {
|
||||
uint32_t TMP1075;
|
||||
};
|
||||
|
||||
struct pollingTimes pollingTimes = {0, 0, 0, 0};
|
||||
struct pollingTimes pollingTimes = {0, 0};
|
||||
|
||||
void AMS_Init(SPI_HandleTypeDef* hspi) {
|
||||
if (eepromconfigured == 1) {
|
||||
@ -124,8 +124,8 @@ void AMS_Loop() {
|
||||
|
||||
uint8_t AMS_Idle_Loop() {
|
||||
if (!amsWakeUp()) {
|
||||
error_data.data_kind = SEK_INTERNAL_BMS_TIMEOUT;
|
||||
set_error_source(ERROR_SOURCE_INTERNAL);
|
||||
//error_data.data_kind = SEK_INTERNAL_BMS_TIMEOUT;
|
||||
//set_error_source(ERROR_SOURCE_INTERNAL);
|
||||
}
|
||||
|
||||
packetChecksumFails += amsAuxAndStatusMeasurement(&module);
|
||||
@ -197,34 +197,6 @@ uint8_t AMS_Idle_Loop() {
|
||||
}
|
||||
|
||||
mcuDelay(10);
|
||||
|
||||
// static uint32_t channelstobalance = 1;
|
||||
|
||||
// channelstobalance = 0x1FFFF;
|
||||
/* if(channelstobalance & 0x20000){
|
||||
channelstobalance = 1;
|
||||
}*/
|
||||
|
||||
// amsConfigBalancing(channelstobalance);
|
||||
// amsStartBalancing(100);
|
||||
|
||||
if ((module.overVoltage | module.underVoltage)) {
|
||||
// amsSendWarning();
|
||||
// currentAMSState = AMSWARNING;
|
||||
}
|
||||
|
||||
// AMS_Balancing_Loop();
|
||||
|
||||
/* if(BalancingActive)
|
||||
{
|
||||
amsStartBalancing(100);
|
||||
}
|
||||
else
|
||||
{
|
||||
amsStopBalancing();
|
||||
}*/
|
||||
// amsConfigBalancing(balancedCells);
|
||||
// volatile amscheck = amscheckOpenCellWire(&module);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#include "eeprom.h"
|
||||
#include "errors.h"
|
||||
#include "stm32f3xx_hal.h"
|
||||
#include "stm32f3xx_hal_gpio.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@ -118,6 +119,12 @@ int main(void)
|
||||
/* USER CODE BEGIN 2 */
|
||||
tmp1075_init(&hi2c1);
|
||||
AMS_Init(&hspi1);
|
||||
ams_can_init(&hcan);
|
||||
|
||||
bool relay_actual = false;
|
||||
bool relay_target = true;
|
||||
|
||||
uint32_t target_time = HAL_GetTick() + 10000;
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
@ -135,6 +142,13 @@ int main(void)
|
||||
ams_can_send_error();
|
||||
}
|
||||
ams_can_send_log();
|
||||
|
||||
if (HAL_GetTick() >= target_time) {
|
||||
HAL_GPIO_WritePin(RELAY_EN_GPIO_Port, RELAY_EN_Pin, relay_target ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(STATUS_LED_R_GPIO_Port, STATUS_LED_R_Pin, relay_target ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
||||
target_time = HAL_GetTick() + 10000;
|
||||
relay_target = !relay_target;
|
||||
}
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
@ -294,7 +308,7 @@ static void MX_SPI1_Init(void)
|
||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
|
||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
|
||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
@ -505,7 +519,10 @@ static void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, RELAY_EN_Pin|_60V_EN_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, RELAY_EN_Pin|_60V_EN_Pin|CSB_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, STATUS_LED_R_Pin|STATUS_LED_B_Pin|STATUS_LED_G_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, PRECHARGE_EN_Pin|AUX_IN_Pin, GPIO_PIN_RESET);
|
||||
@ -516,17 +533,20 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : RELAY_EN_Pin _60V_EN_Pin */
|
||||
GPIO_InitStruct.Pin = RELAY_EN_Pin|_60V_EN_Pin;
|
||||
/*Configure GPIO pins : RELAY_EN_Pin _60V_EN_Pin CSB_Pin */
|
||||
GPIO_InitStruct.Pin = RELAY_EN_Pin|_60V_EN_Pin|CSB_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : STATUS_LED_R_Pin STATUS_LED_B_Pin STATUS_LED_G_Pin AUX_OUT_Pin */
|
||||
GPIO_InitStruct.Pin = STATUS_LED_R_Pin|STATUS_LED_B_Pin|STATUS_LED_G_Pin|AUX_OUT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
/*Configure GPIO pins : STATUS_LED_R_Pin STATUS_LED_B_Pin STATUS_LED_G_Pin PRECHARGE_EN_Pin
|
||||
AUX_IN_Pin */
|
||||
GPIO_InitStruct.Pin = STATUS_LED_R_Pin|STATUS_LED_B_Pin|STATUS_LED_G_Pin|PRECHARGE_EN_Pin
|
||||
|AUX_IN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PB10 PB12 PB4 PB5
|
||||
@ -537,12 +557,11 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PRECHARGE_EN_Pin AUX_IN_Pin */
|
||||
GPIO_InitStruct.Pin = PRECHARGE_EN_Pin|AUX_IN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
/*Configure GPIO pin : AUX_OUT_Pin */
|
||||
GPIO_InitStruct.Pin = AUX_OUT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(AUX_OUT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : RELAY_BATT_SIDE_ON_Pin RELAY_ESC_SIDE_ON_Pin CURRENT_SENSOR_ON_Pin */
|
||||
GPIO_InitStruct.Pin = RELAY_BATT_SIDE_ON_Pin|RELAY_ESC_SIDE_ON_Pin|CURRENT_SENSOR_ON_Pin;
|
||||
|
||||
@ -238,12 +238,11 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**SPI1 GPIO Configuration
|
||||
PA4 ------> SPI1_NSS
|
||||
PA5 ------> SPI1_SCK
|
||||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
@ -274,12 +273,11 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
|
||||
__HAL_RCC_SPI1_CLK_DISABLE();
|
||||
|
||||
/**SPI1 GPIO Configuration
|
||||
PA4 ------> SPI1_NSS
|
||||
PA5 ------> SPI1_SCK
|
||||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
|
||||
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 1 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user