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.

 

 

 

17 REPLIES 17
JKong.3
Associate III

In the software side, it works fine, but when I try to debug using oscilloscope, the waveform won't show.

In TSK_HighFrequencyTask()  (16 kHz), I downsampled to 8kHz, then stores alphabeta current and voltage (8 bytes per cycle) to a 64 byte buffer then sends a FDCAN signal storing that buffer. (so tx frequency is 1kHz)  

 

my code :

// in fdcan.c, 

/* FDCAN1 init function */
void MX_FDCAN1_Init(void)
{
 
  /* USER CODE BEGIN FDCAN1_Init 0 */
 
  /* USER CODE END FDCAN1_Init 0 */
 
  /* USER CODE BEGIN FDCAN1_Init 1 */
 
  /* USER CODE END FDCAN1_Init 1 */
  hfdcan1.Instance = FDCAN1;
  hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
  hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_NO_BRS;
  hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
  hfdcan1.Init.AutoRetransmission = DISABLE;
  hfdcan1.Init.TransmitPause = DISABLE;
  hfdcan1.Init.ProtocolException = DISABLE;
  hfdcan1.Init.NominalPrescaler = 1;
  hfdcan1.Init.NominalSyncJumpWidth = 1;
  hfdcan1.Init.NominalTimeSeg1 = 5;
  hfdcan1.Init.NominalTimeSeg2 = 2;
  hfdcan1.Init.DataPrescaler = 1;
  hfdcan1.Init.DataSyncJumpWidth = 1;
  hfdcan1.Init.DataTimeSeg1 = 1;
  hfdcan1.Init.DataTimeSeg2 = 1;
  hfdcan1.Init.StdFiltersNbr = 0;
  hfdcan1.Init.ExtFiltersNbr = 0;
  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
  if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN FDCAN1_Init 2 */
  /* configure reception filter to Rx buffer 0*/
 
  sFilterConfig.IdType = FDCAN_STANDARD_ID;
  sFilterConfig.FilterIndex = 0;
  sFilterConfig.FilterType = FDCAN_FILTER_MASK;
  sFilterConfig.FilterID1 = 0x11;
  sFilterConfig.FilterID2 = 0x11;
  sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
 
  if(HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig)!= HAL_OK)
  {
  Error_Handler();
  }
 
  /* configure Tx buffer message */
 
  // Configure Tx Header
  TxHeader.Identifier = 0x11;
  TxHeader.IdType = FDCAN_STANDARD_ID;
  TxHeader.TxFrameType = FDCAN_DATA_FRAME;
  TxHeader.DataLength = FDCAN_DLC_BYTES_64;
  TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
  TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
  TxHeader.FDFormat = FDCAN_FD_CAN;
  TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
  TxHeader.MessageMarker = 0;
 
  /* Start FDCAN module */
  if(HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
  {
  Error_Handler();
  }
  /* USER CODE END FDCAN1_Init 2 */
 
}

 

// in mc_tasks.c, TSK_HighFrequencyTask()

  /* USER CODE BEGIN HighFrequencyTask 1 */
(void)TSK_StoreToBuffer(TxData, buffer_index);
/* USER CODE END HighFrequencyTask 1 */

void TSK_StoreToBuffer(uint8_t * const buffer, uint8_t idx)
{
if (buffer_flag == BUFFER_READY)
{
// alphabeta_t data1, data2;
 
// data1 = FOCVars[M1].Ialphabeta;
// data2 = FOCVars[M1].Valphabeta;
//
// buffer[idx] = (uint8_t)(data1.alpha & 0xff);
// buffer[idx+1] = (uint8_t)((data1.alpha)>>8 & 0xff);
//
// buffer[idx + 16] = (uint8_t)(data1.beta & 0xff);
// buffer[idx + 17] = (uint8_t)((data1.beta)>>8 & 0xff);
//
// buffer[idx + 32] = (uint8_t)(data2.alpha & 0xff);
// buffer[idx + 33] = (uint8_t)((data2.alpha)>>8 & 0xff);
//
// buffer[idx + 48] = (uint8_t)(data2.beta & 0xff);
// buffer[idx + 49] = (uint8_t)((data2.beta)>>8 & 0xff);
 
buffer[idx] = (uint8_t)(0x31);
buffer[idx+1] = (uint8_t)(0x32);
 
buffer[idx + 16] = (uint8_t)(0x33);
buffer[idx + 17] = (uint8_t)(0x34);
 
buffer[idx + 32] = (uint8_t)(0x35);
buffer[idx + 33] = (uint8_t)(0x36);
 
buffer[idx + 48] = (uint8_t)(0x37);
buffer[idx + 49] = (uint8_t)(0x38);
 
 
 
idx += 2;
 
buffer_flag = BUFFER_BUSY;
}
else
{
if (idx == 16) // transmit message
{
//HAL_UART_Transmit_IT(&huart2, buffer, sizeof(buffer));
HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, buffer);
 
      idx = 0;
}
buffer_flag++; // BUFFER_READY = (uint8_t) 1, BUFFER_BUSY = (uint8_t) 0
}
}
 
I also set CAN_TERM pin to high
 
JKong3_1-1689565797262.png

Any thoughts on what am I missing?


 

 

 

 
JKong.3
Associate III

Sorry, it was a programming issue.

LCE
Principal

Okay...

Did the debouncing do the trick for the first basic problem?

JKong.3
Associate III

I couldn't due to my lack of programming skills. I will keep in mind when I start another project using UART.

So why the wrong answer was selected as a solution?

Sorry, got mixed up with my main goal (FDCAN + motorcontrol) with this topic (UART_DMA + GPIO interrupt(button))

I didn't mention that at first I sent FDCAN messages when button is pressed, then the FDCAN RX interrupt will send UART_DMA message. Which didn't work (also motorcontrol stopped operating), so I decided to send UART DMA message directly when button is pressed, which is the question stated here. 

So can you edit this topic as not solved?

Sounds like issues of interrupt safety, priorities, the ST's broken bloatware etc.

The menu on the right side of the particular solution post has an option "Not the Solution".

thanks