Trinamic TMC2209 STM32 UART 无法从设备读取

问题描述 投票:0回答:1

我已经挣扎了很长时间,现在终于屈服并寻求帮助。 我见过的关于这个驱动的STM32资源很少。

我可以使用带有 STEP/DIR 接口的设备,但我希望现在能够仅使用单条 UART 线而不是 STEP/DIR 线来执行更高级的操作。

我试图以最基本的形式控制 TMC2209,以了解它是如何工作的,而不需要库等。 我想让基本控件正常工作,这样我就可以理解它并从那里构建我自己的代码,现在的目标是与该东西交谈并让它旋转。

我使用的是STM32F103,我已将USART3线(PC10)设置为信号线半双工模式,并使用以下代码尝试从CHOPCONF寄存器读取。

       Sync = 0x05; // sync byte to start the Tx
       Address = 0x00; // MS1 and MS2 are pulled low so the device address is 0
       RegAddress = 0x6C; // Trying for a basic read from the CHOPCONF Reg
       motor_CRC = 0xCA;  // CRC that has been worked out

       HAL_UART_Transmit(&huart3,&Sync,sizeof(Sync),20);
       HAL_UART_Transmit(&huart3,&Address,sizeof(Address),20);
       HAL_UART_Transmit(&huart3,&RegAddress,sizeof(RegAddress),20);
       HAL_UART_Transmit(&huart3,&motor_CRC,sizeof(motor_CRC),20);

// Receive the data from the TMC2209

       HAL_UART_Receive(&huart3, &ReplySync, sizeof(ReplySync), 200);
       HAL_UART_Receive(&huart3, &ReplyMasterAddr, sizeof(ReplyMaster), 20);
       HAL_UART_Receive(&huart3, &ReplyAddr, sizeof(ReplyAddr), 20);
       HAL_UART_Receive(&huart3, &Reply1, sizeof(Reply1), 20);
       HAL_UART_Receive(&huart3, &Reply2, sizeof(Reply2), 20);
       HAL_UART_Receive(&huart3, &Reply3, sizeof(Reply3), 20);
       HAL_UART_Receive(&huart3, &Reply4, sizeof(Reply4), 20);
       HAL_UART_Receive(&huart3, &ReplyCRC, sizeof(ReplyCRC), 20);

       HAL_Delay(1000);

我期望以下内容:(根据数据表,,,,)

ReplySync      >>> 0x05
ReplyMasterAddr>>> 0xFF
ReplyAddr      >>> 0xCA
Reply1         >>> 0x53
Reply2         >>> 0x00
Reply3         >>> 0x00
Reply4         >>> 0x10
ReplyCRC       >>> I dont know this one yet,,,,

但是我明白了:

ReplySync      >>> 0x05
ReplyMasterAddr>>> 0x00
ReplyAddr      >>> 0x5D
Reply1         >>> 0x09
Reply2         >>> 0x08
Reply3         >>> 0x00
Reply4         >>> 0x02
ReplyCRC       >>> 0x09

我不确定我是否以正确的顺序传输这些内容,或者 HAL 函数根本不应该用于此目的?

任何正确方向的帮助或指示将不胜感激。

stm32 uart stepper usart stm32f1
1个回答
0
投票

已经有一段时间了,但我确实设法让它工作了一段时间。 我会尽力提供尽可能多的信息来说明我是如何完成这项工作的。

我的 UART 通讯最终是这样的;

// THIS SETUP DOES NOT MATTER IF YOU DONT CARE ABOUT STALL DETECTION AND OTHER FETURES, MAYBE JUST DO THE FIRST ONE FOR UART COMMS
      uint8_t FullSetup[]={0x05 ,0x00 ,0x80 ,0x00 ,0x00 ,0x01 ,0xe1 ,0x63,// This address will need to be changed if directed at anything but the hood motor
                           0x05 ,0x00 ,0xec ,0x12 ,0x00 ,0x00 ,0x53 ,0x07,
                           0x05 ,0x00 ,0xF0 ,0x24 ,0x00 ,0x70 ,0x2C ,0xD7, // setting the PWM Conf Reg for Stealth Chop
                           0x05 ,0x00 ,0x94 ,0x00 ,0x00 ,0x0f ,0xa0 ,0x3b, // stall guard detection, make sure this is the lowest value used (4000 now)
                           0x05 ,0x00 ,0xc2 ,0x00 ,0x00 ,0x00 ,0x00 ,0x45,
                           0x05 ,0x00 ,0xa2 ,0x00 ,0x00 ,0x00 ,0x00 ,0x0E};  // last thing is set the speed to Zero

我使用了示例中给出的相同 CRC 检查器并通过以下内容发送:

HAL_UART_Transmit(AUX_MOTOR_UART_CH, FullSetup, sizeof(FullSetup),100);  // sets the main operating details needed. DOES NOT SET direction, speed or stall value

对于那些需要它的人,我通过这样做设置了摊位值:

uint8_t StallV[] = {0x05 ,0x00 ,0xc0 ,0x00 ,0x00 ,0x00 ,0x00 ,0x8D}; // Set the motor stall value

                StallV[6]= hoodMotorBuffer.Stall;//Stall[HoodTracker]+(hoodMotorBuffer.Stall);
                TMC2209_calcCRC(StallV, sizeof(StallV));
                HAL_UART_Transmit(AUX_MOTOR_UART_CH, StallV, sizeof(StallV),1); // send Stall value.

希望这对某人有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.