cancel
Showing results for 
Search instead for 
Did you mean: 

sending signal (UART) while running MotorControl

JKong.3
Associate III

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];

void EXTI15_10_IRQHandler (void)
{
/* USER CODE BEGIN START_STOP_BTN */
  sprintf(mc_it_debug, "StartStop Button Pressed\r\n");
  HAL_UART_Transmit_DMA(&huart2, mc_it_debug, sizeof(mc_it_debug));
  if (  0U == LL_EXTI_ReadFlag_0_31(LL_EXTI_LINE_10) )
  {
    /* Nothing to do */
  }
  else
  {
    LL_EXTI_ClearFlag_0_31 (LL_EXTI_LINE_10);
    ( void )UI_HandleStartStopButton_cb ();
  }
 
}
 
in the main.c file, 

/* 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 

JKong3_0-1688626066429.png

Any advice will be helpful.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
LCE
Principal

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)

View solution in original post

17 REPLIES 17
JKong.3
Associate III

Update : HAL_UART_Transmit_IT() works

I'm guessing there's some conflict btw DMA and MotorControl

 

JKong.3
Associate III

Update : FDCAN also works, so anyone who tries to use FDCAN, 

my setting is (for 170MHz clock)

JKong3_0-1688641434230.png

I don't know what's wrong with DMA really.

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)

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
LCE
Principal

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.

Ok, will do

JKong.3
Associate III

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.

LCE
Principal

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)

JKong.3
Associate III

I will research more on that. Thanks for your help.

Trust me in some cases it could be 😉

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.