2023-07-05 11:50 PM
Hi,
I'm currently working on sending signals through FDCAN or UART of B-G431B-ESC1 while driving a motor.
I have written a debug code which sends UART data when a button is pressed.
However, the function is called once and never called again, nor the motor won't start.
"stm32g4xx_mc_it"
uint8_t mc_it_debug[64];
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_ADC2_Init();
MX_COMP1_Init();
MX_COMP2_Init();
MX_COMP4_Init();
MX_CORDIC_Init();
MX_DAC3_Init();
MX_OPAMP1_Init();
MX_OPAMP2_Init();
MX_OPAMP3_Init();
MX_TIM1_Init();
MX_MotorControl_Init();
MX_FDCAN1_Init();
MX_USART2_UART_Init();
/* Initialize interrupts */
MX_NVIC_Init();
I am assuming it is a priority issue, which is set as
Any advice will be helpful.
Solved! Go to Solution.
2023-07-06 10:14 PM
Search the web for basics about switches and debouncing.
And not only debouncing:
If you only check the level of the switch GPIO, think about the time it is actually pressed vs. the few micro-/ milliseconds it actually takes the MCU to perform stuff.
So before you release the switch, everything might be triggered several times, which might create several problems.
I would do the following:
- reduce the ISR to just set a flag and save the time (SysTick or some other timer)
- block or ignore the button interrupt for some time (check flag and SysTick)
2023-07-06 01:18 AM
Update : HAL_UART_Transmit_IT() works
I'm guessing there's some conflict btw DMA and MotorControl
2023-07-06 04:04 AM
Update : FDCAN also works, so anyone who tries to use FDCAN,
my setting is (for 170MHz clock)
I don't know what's wrong with DMA really.
2023-07-06 04:29 AM - edited 2023-07-06 04:30 AM
Hello,
Regarding your FDCAN bitrate config, I see 999999bit/s. So please try to find another values for NSEG1 and NSEG2 to have exactly 1000000bit/s (1Mb/s)
2023-07-06 05:17 AM
I cannot imagine that 1ppm deviation of the FDCAN bitrate is the problem here...
Do you do any analog debouncing of the button ? If not, do it in the source code, so suppress any button action for some time after each button action.
2023-07-06 05:56 PM
Ok, will do
2023-07-06 06:06 PM
Can you tell me the meaning of debouncing? I'm assuming what you're saying is create another callback for rising-edge interrupt of a button
UART_Transmit_IT and CANFD works fine, it's just that when I want to check if FDCAN is working by sending UART signals in FDCAN_TxBufferCompleteCallback by
sprintf(debug_main, "FDCAN_TxCallback Called\r\n");
HAL_UART_Transmit_DMA(&huart2, debug_main, sizeof(debug_main));
DMA doesn't work(meaning it does not send data and the motor doesn't run), but when I change it to HAL_UART_Transmit_IT, it works fine.
2023-07-06 10:14 PM
Search the web for basics about switches and debouncing.
And not only debouncing:
If you only check the level of the switch GPIO, think about the time it is actually pressed vs. the few micro-/ milliseconds it actually takes the MCU to perform stuff.
So before you release the switch, everything might be triggered several times, which might create several problems.
I would do the following:
- reduce the ISR to just set a flag and save the time (SysTick or some other timer)
- block or ignore the button interrupt for some time (check flag and SysTick)
2023-07-06 10:27 PM
I will research more on that. Thanks for your help.
2023-07-07 02:28 AM
Trust me in some cases it could be ;)