From 99ec12f69fc3265762fb9abdcd86fd5fe3378c04 Mon Sep 17 00:00:00 2001 From: Dylan Donahue Date: Sun, 7 Apr 2024 17:18:53 -0400 Subject: [PATCH] updated for 5v ref pin --- Core/Src/main.c | 86 ++++++++++++++++++++++++++++++++++++++++--------- shepherd2.ioc | 29 ++++++++--------- 2 files changed, 84 insertions(+), 31 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index e97bdc0..465636c 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -47,6 +47,8 @@ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ +ADC_HandleTypeDef hadc1; + CAN_HandleTypeDef hcan1; CAN_HandleTypeDef hcan2; @@ -82,6 +84,7 @@ static void MX_I2C1_Init(void); static void MX_TIM1_Init(void); static void MX_TIM2_Init(void); static void MX_TIM8_Init(void); +static void MX_ADC1_Init(void); /* USER CODE BEGIN PFP */ void watchdog_init(void); @@ -224,6 +227,7 @@ int main(void) MX_TIM1_Init(); MX_TIM2_Init(); MX_TIM8_Init(); + MX_ADC1_Init(); /* USER CODE BEGIN 2 */ for (int i = 0; i < 58; i++) { @@ -335,6 +339,58 @@ void SystemClock_Config(void) } } +/** + * @brief ADC1 Initialization Function + * @param None + * @retval None + */ +static void MX_ADC1_Init(void) +{ + + /* USER CODE BEGIN ADC1_Init 0 */ + + /* USER CODE END ADC1_Init 0 */ + + ADC_ChannelConfTypeDef sConfig = {0}; + + /* USER CODE BEGIN ADC1_Init 1 */ + + /* USER CODE END ADC1_Init 1 */ + + /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) + */ + hadc1.Instance = ADC1; + hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2; + hadc1.Init.Resolution = ADC_RESOLUTION_12B; + hadc1.Init.ScanConvMode = DISABLE; + hadc1.Init.ContinuousConvMode = DISABLE; + hadc1.Init.DiscontinuousConvMode = DISABLE; + hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; + hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; + hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc1.Init.NbrOfConversion = 1; + hadc1.Init.DMAContinuousRequests = DISABLE; + hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; + if (HAL_ADC_Init(&hadc1) != HAL_OK) + { + Error_Handler(); + } + + /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. + */ + sConfig.Channel = ADC_CHANNEL_15; + sConfig.Rank = 1; + sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; + if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN ADC1_Init 2 */ + + /* USER CODE END ADC1_Init 2 */ + +} + /** * @brief CAN1 Initialization Function * @param None @@ -855,8 +911,8 @@ static void MX_GPIO_Init(void) __HAL_RCC_GPIOD_CLK_ENABLE(); /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOC, FPGA_Reset_Pin|Communication_GPIO_Pin|Communication_GPIOC15_Pin|Communication_GPIOC0_Pin - |SPI_2_CS_Pin|Debug_LED_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOC, FPGA_Reset_Pin|Communication_GPIO_Pin|Communication_GPIOC0_Pin|SPI_2_CS_Pin + |Debug_LED_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOA, Fault_Output_Pin|SPI_1_CS_Pin|SPI_3_CS_Pin, GPIO_PIN_RESET); @@ -868,15 +924,21 @@ static void MX_GPIO_Init(void) /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(External_GPIO_GPIO_Port, External_GPIO_Pin, GPIO_PIN_RESET); - /*Configure GPIO pins : FPGA_Reset_Pin Communication_GPIO_Pin Communication_GPIOC15_Pin Communication_GPIOC0_Pin - SPI_2_CS_Pin Debug_LED_Pin */ - GPIO_InitStruct.Pin = FPGA_Reset_Pin|Communication_GPIO_Pin|Communication_GPIOC15_Pin|Communication_GPIOC0_Pin - |SPI_2_CS_Pin|Debug_LED_Pin; + /*Configure GPIO pins : FPGA_Reset_Pin Communication_GPIO_Pin Communication_GPIOC0_Pin SPI_2_CS_Pin + Debug_LED_Pin */ + GPIO_InitStruct.Pin = FPGA_Reset_Pin|Communication_GPIO_Pin|Communication_GPIOC0_Pin|SPI_2_CS_Pin + |Debug_LED_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + /*Configure GPIO pin : PC15 */ + GPIO_InitStruct.Pin = GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + /*Configure GPIO pin : Interlock_Read_Pin */ GPIO_InitStruct.Pin = Interlock_Read_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; @@ -890,17 +952,11 @@ static void MX_GPIO_Init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - /*Configure GPIO pin : I_Sense_Pin */ - GPIO_InitStruct.Pin = I_Sense_Pin; + /*Configure GPIO pin : I_SenseB2_Pin */ + GPIO_InitStruct.Pin = I_SenseB2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(I_Sense_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : I_SenseB0_Pin I_SenseB1_Pin I_SenseB2_Pin */ - GPIO_InitStruct.Pin = I_SenseB0_Pin|I_SenseB1_Pin|I_SenseB2_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + HAL_GPIO_Init(I_SenseB2_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : Debug_LEDB11_Pin Watchdog_Out_Pin External_GPIOB3_Pin External_GPIOB4_Pin External_GPIOB5_Pin */ diff --git a/shepherd2.ioc b/shepherd2.ioc index 7041364..61cc91d 100644 --- a/shepherd2.ioc +++ b/shepherd2.ioc @@ -179,11 +179,11 @@ PA9.Signal=USB_OTG_FS_VBUS PB0.GPIOParameters=GPIO_Label PB0.GPIO_Label=I Sense PB0.Locked=true -PB0.Signal=SharedAnalog_PB0 +PB0.Signal=ADCx_IN8 PB1.GPIOParameters=GPIO_Label PB1.GPIO_Label=I Sense PB1.Locked=true -PB1.Signal=SharedAnalog_PB1 +PB1.Signal=ADCx_IN9 PB10.Mode=Full_Duplex_Master PB10.Signal=SPI2_SCK PB11.GPIOParameters=GPIO_Label @@ -246,10 +246,8 @@ PC14-OSC32_IN.GPIOParameters=GPIO_Label PC14-OSC32_IN.GPIO_Label=Communication GPIO PC14-OSC32_IN.Locked=true PC14-OSC32_IN.Signal=GPIO_Output -PC15-OSC32_OUT.GPIOParameters=GPIO_Label -PC15-OSC32_OUT.GPIO_Label=Communication GPIO PC15-OSC32_OUT.Locked=true -PC15-OSC32_OUT.Signal=GPIO_Output +PC15-OSC32_OUT.Signal=GPXTI15 PC2.Mode=Full_Duplex_Master PC2.Signal=SPI2_MISO PC3.Mode=Full_Duplex_Master @@ -261,7 +259,7 @@ PC4.Signal=GPIO_Output PC5.GPIOParameters=GPIO_Label PC5.GPIO_Label=I Sense PC5.Locked=true -PC5.Signal=SharedAnalog_PC5 +PC5.Signal=ADCx_IN15 PC6.GPIOParameters=GPIO_Label PC6.GPIO_Label=Fan PWM PC6.Locked=true @@ -317,7 +315,7 @@ ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_CAN1_Init-CAN1-false-HAL-true,4-MX_CAN2_Init-CAN2-false-HAL-true,5-MX_SPI1_Init-SPI1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_UART4_Init-UART4-false-HAL-true,9-MX_USB_OTG_FS_PCD_Init-USB_OTG_FS-false-HAL-true,10-MX_I2C1_Init-I2C1-false-HAL-true,11-MX_TIM1_Init-TIM1-false-HAL-true,12-MX_TIM2_Init-TIM2-false-HAL-true,13-MX_TIM8_Init-TIM8-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_CAN1_Init-CAN1-false-HAL-true,4-MX_CAN2_Init-CAN2-false-HAL-true,5-MX_SPI1_Init-SPI1-false-HAL-true,6-MX_SPI2_Init-SPI2-false-HAL-true,7-MX_SPI3_Init-SPI3-false-HAL-true,8-MX_UART4_Init-UART4-false-HAL-true,9-MX_USB_OTG_FS_PCD_Init-USB_OTG_FS-false-HAL-true,10-MX_I2C1_Init-I2C1-false-HAL-true,11-MX_TIM1_Init-TIM1-false-HAL-true,12-MX_TIM2_Init-TIM2-false-HAL-true,13-MX_TIM8_Init-TIM8-false-HAL-true,14-MX_ADC1_Init-ADC1-false-HAL-true RCC.48MHZClocksFreq_Value=48000000 RCC.AHBFreq_Value=16000000 RCC.APB1Freq_Value=16000000 @@ -342,6 +340,14 @@ RCC.VCOI2SOutputFreq_Value=320000000 RCC.VCOInputFreq_Value=1666666.6666666667 RCC.VCOOutputFreq_Value=240000000 RCC.VcooutputI2S=160000000 +SH.ADCx_IN15.0=ADC1_IN15,IN15 +SH.ADCx_IN15.ConfNb=1 +SH.ADCx_IN8.0=ADC1_IN8,IN8 +SH.ADCx_IN8.ConfNb=1 +SH.ADCx_IN9.0=ADC1_IN9,IN9 +SH.ADCx_IN9.ConfNb=1 +SH.GPXTI15.0=ADC1_EXTI15,External-Trigger-for-Injected-conversion +SH.GPXTI15.ConfNb=1 SH.S_TIM1_CH1.0=TIM1_CH1,PWM Generation1 CH1 SH.S_TIM1_CH1.ConfNb=1 SH.S_TIM1_CH3.0=TIM1_CH3,PWM Generation3 CH3 @@ -354,15 +360,6 @@ SH.S_TIM8_CH3.0=TIM8_CH3,PWM Generation3 CH3 SH.S_TIM8_CH3.ConfNb=1 SH.S_TIM8_CH4.0=TIM8_CH4,PWM Generation4 CH4 SH.S_TIM8_CH4.ConfNb=1 -SH.SharedAnalog_PB0.0=GPIO_Analog -SH.SharedAnalog_PB0.1=ADC1_IN8,IN8 -SH.SharedAnalog_PB0.ConfNb=2 -SH.SharedAnalog_PB1.0=GPIO_Analog -SH.SharedAnalog_PB1.1=ADC1_IN9,IN9 -SH.SharedAnalog_PB1.ConfNb=2 -SH.SharedAnalog_PC5.0=GPIO_Analog -SH.SharedAnalog_PC5.1=ADC1_IN15,IN15 -SH.SharedAnalog_PC5.ConfNb=2 SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_16 SPI1.CLKPhase=SPI_PHASE_2EDGE SPI1.CLKPolarity=SPI_POLARITY_HIGH