Why does my code only work on STM32 L476RG and not G474RE
Hi,
I want to use the ETR to count pulses and set a second timer, so every ... seconds the value from the ETR counter is red and renewed like discribed in this Example
STM32 Frequency Counter – LAB10
https://deepbluembedded.com/stm32-counter-mode-example-frequency-counter-timer-in-counter-mode/
The code is
#include "main.h"
uint32_t gu32_CounterTicks = 0x00;
uint32_t gu32_Freq = 0x00;
uint8_t gu8_MSG[40] = {'\0'};
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim5;
UART_HandleTypeDef huart1;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM2_Init(void);
static void MX_TIM5_Init(void);
static void MX_USART1_UART_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_TIM2_Init();
MX_TIM5_Init();
MX_USART1_UART_Init();
HAL_TIM_Base_Start(&htim2);
HAL_TIM_Base_Start_IT(&htim5);
while (1)
{
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
{
if(htim->Instance == TIM5)
{
gu32_CounterTicks = TIM2->CNT;
gu32_Freq = gu32_CounterTicks * 20;
sprintf(gu8_MSG, "Frequency = %d Hz\n\r", gu32_Freq);
HAL_UART_Transmit(&huart1, gu8_MSG, sizeof(gu8_MSG), 100);
TIM5->CNT = 0;
TIM2->CNT = 0;
}
}while the example works fine on the L476RG I cant get it working on the G474RE.
Both have an ETR2 read mode at timer 2 and timer 5 is a normal timer that can be set to run a specific time.
I had a look on the datasheets of both Nucleo Devboards, but I couldnt find a difference that explains why the code only works on the L476RG and I need it to work on the G474RE too.
Thanks in advance