cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G030C8Tx can not communicate with BTT TMC2209

Moonless
Associate

I have STM32G030C8Tx C project that I am trying communicate with BigTreeTech TMC2209 module with the UART half duplex interface. I have attempt to write the code from scratch, kicked that around for a few weeks, gave up and tried to port over some ardiuno projects. I have finally a working project on github, https://github.com/veysiadn/tmc_2209. Still haven't had any luck. I have two drivers boards that I am working with. One I have soldered the bridge pads on the bottom, the other has no modifications. Drivers have tested on BTT SKR 1.4 turbo board with marlin configured to use UART, both worked.   Both boards have the pot adjusted to give the boards enough current at 12 volts.   Both power supplies are running for testing the firmware.


I thinking it may be a wiring issue, maybe?

Screenshot 2025-01-09 133933.pngScreenshot 2025-01-09 135856.png

 

The code...

USART initialization

 

 

static void MX_USART2_UART_Init(void) { 
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_HalfDuplex_Init(&huart2) != HAL_OK) 
    Error_Handler(); 
}

 

 

 
 
Initialize code / Pre loop

 

 

  /* USER CODE BEGIN 2 */
  UART_InitPoll(&uartData, &huart1);
  UART_Printf(&uartData, TERMINAL_CLEAR_SCREEN);
  UART_CursorPut(&uartData, 0, 0);
  UART_Printf(&uartData, "TMC2209 C\n\r");

  tmc2209_setup(&stepper_driver, 115200, SERIAL_ADDRESS_0);
  tmc2209_set_hardware_enable_pin(&stepper_driver, MOTOR0_ENABLE_Pin);
  enable_cool_step(&stepper_driver, 1, 0);
  tmc2209_enable(&stepper_driver);
  set_micro_steps_per_step(&stepper_driver, MICROSTEPS_PER_STEP);
  set_pwm_frequency(&stepper_driver, INTERNAL_PWM_FREQUENCY_46KHZ);
  set_stand_still_mode(&stepper_driver, TMC_NORMAL);
  set_all_current_percent_values(&stepper_driver, RUN_CURRENT_PERCENT, 0, 0);
  enable_automatic_current_scaling(&stepper_driver);
  enable_stealth_chop(&stepper_driver);

  set_stealth_chop_duration_threshold(&stepper_driver, 9999999);
  /* USER CODE END 2 */

 

 

  
the main loop

 

 

  /* USER CODE BEGIN WHILE */
  uint32_t mstep_counter = 0;
  uint32_t current_velocity = 0;
  while (1) {
  if (!HAL_GPIO_ReadPin(MOVE_RIGHT_GPIO_Port, MOVE_RIGHT_Pin)) {
  UART_Printf(&uartData, "Move right\n\r");
    tmc2209_enable(&stepper_driver);
    enable_inverse_motor_direction(&stepper_driver);

    current_velocity = tx_movement_ramp_up(MAX_TARGET_VELOCITY, ACCELERATION);
    while (!HAL_GPIO_ReadPin(MOVE_RIGHT_GPIO_Port, MOVE_RIGHT_Pin)) {
      move_at_velocity(&stepper_driver, current_velocity);
      mstep_counter = get_microstep_counter(&stepper_driver);
      if (mstep_counter)  { }

      UART_Printf(&uartData, "\tMoving right\n\r");
    }
  }  else if (!HAL_GPIO_ReadPin(MOVE_LEFT_GPIO_Port, MOVE_LEFT_Pin))  {

    UART_Printf(&uartData, "Move Left\n\r");
    tmc2209_enable(&stepper_driver);
    disable_inverse_motor_direction(&stepper_driver);

    current_velocity = tx_movement_ramp_up(MAX_TARGET_VELOCITY, ACCELERATION);
    while (!HAL_GPIO_ReadPin(MOVE_LEFT_GPIO_Port, MOVE_LEFT_Pin))    {
      move_at_velocity(&stepper_driver, current_velocity);
    }
    UART_Printf(&uartData, "\tMoving left\n\r");
  }  else  {
    if (current_velocity > 0)    {
      tx_movement_ramp_down(0, ACCELERATION);
      current_velocity = 0;
    }    else    {
      move_at_velocity(&stepper_driver, STOP_VELOCITY);
    }
    tmc2209_disable(&stepper_driver);
    HAL_Delay(1);

//UART_Printf(&uartData, "Stop Movement\n\r");
  }
  /* USER CODE END WHILE */

 

 

 

Any body have any thoughts.   Happy to post more code if need.    

Thank you for taking the time to look over this for me, it is very appreciated.

1 REPLY 1
Moonless
Associate

Solved my problem,  with this post.    I was not transmitting MSB first, I had it disabled.   Now I an communicate with the module is listening now.    I don't know about receiving data back yet, but this is a starting point.