串口配置TMC2209电机驱动模块

串口配置TMC2209电机驱动模块

本文主要记录TMC2209调试过程,通过串口助手配置TMC2209的寄存器实现转速,方向,细分数等寄存器设置。
1.首先要实现uart配置TMC2209寄存器就要先知道串口发送数据的格式和接收数据的格式。
在这里插入图片描述
在这里插入图片描述
写数据和读数据格式按照上图格式配置即可。
CRC采用CRC_8校验,相关校验代码如下
在这里插入图片描述
TMC2209串口采用单线连接,串口连接方式如下
在这里插入图片描述
电机控制方向和细分模式选择(外部细分和内部细分)位都在通用寄存器中。
在这里插入图片描述
可见第三位是配置电机方向的,第七位是配置电机细分模式的,这里我们选择内部细分,因为内部细分比外部细分选择细分数更多。
在这里插入图片描述
只需发送上述指令就配置了电机方向与内部细分模式的打开,配置为0x89,0x81.(记得后面一定要加上CRC_8校验位)
在这里插入图片描述
1.为写入配置通用寄存器配置方向和内部细分模式。
2.为读取通用寄存器指令
3.为读取返回来的信息
(记得串口要关闭发送新行,否则会失败)
采用上述方法依次可以配置内部速度寄存器,细分个数,观测电流值等高级设置
在这里插入图片描述
内部速度寄存器
在这里插入图片描述
配置MERS细分个数寄存器,需要打开内部细分模式后配置。
更多详细的配置大家可以看数据手册。
在linux平台上写操作可以参考如下代码

//uart写操作
void UART_writeInt(unsigned char address, unsigned int value)
{
	char writeData[8];

	writeData[0] = 0x05;                         // Sync byte
	writeData[1] = 0x00;                        // Slave address
	writeData[2] = address | 0x80;      // Register address with write bit set
	writeData[3] = value >> 24;                  // Register Data
	writeData[4] = value >> 16;                  // Register Data
	writeData[5] = value >> 8;                   // Register Data
	writeData[6] = value & 0xFF;                 // Register Data
	writeData[7] = Calc_CRC8(writeData, 7);    // Cyclic redundancy check

	//printf("CRC=%x\n",writeData[7]);
	//serialFlush (fd);                  //清空缓冲区
	write(fd,writeData,8);
}
ATIONS Compatible Design Upgrade 3D Printers Printers, POS Office and home automation Textile, Sewing Machines CCTV, Security ATM, Cash recycler HVAC Battery Operated Equipment FEATURES AND BENEFITS 2-phase stepper motors up to 2.8A coil current (peak), 2A RMS STEP/DIR Interface with 4, 8, 16 or 32 microstep pin setting Smooth Running 256 microsteps by MicroPlyer™ interpolation StealthChop2™ silent motor operation SpreadCycle™ highly dynamic motor control chopper StallGuard4™ load and stall detection for StealthChop CoolStep™ current control for energy savings up to 75% Low RDSon, Low Heat-Up LS 170mΩ & HS 170mΩ (typ. at 25°C) Voltage Range 4.75… 28V DC Low Power Standby to fit EUP or for battery operation Internal Sense Resistor option (no sense resistors required) Passive Braking, Freewheeling, and automatic power down Single Wire UART & OTP for advanced configuration options Integrated Pulse Generator for standalone motion Full Protection & Diagnostics Choice of QFN and HTSSOP package for best fit DESCRIPTION The TMC2209 and TMC2226 are ultra-silent motor driver ICs for two phase stepper motors. TMC2209 pinning is compatible to a number of legacy drivers as well as to the TMC2208. TRINAMICs sophisticated StealthChop2 chopper ensures noiseless operation, maximum efficiency and best motor torque. Its fast current regulation and optional combination with SpreadCycle allow highly dynamic motion while adding. StallGuard for sensorless homing. The integrated power MOSFETs handle motor currents up to 2A RMS with protection and diagnostic features for robust and reliable operation. A simple to use UART interface opens up tuning and control options. Store application tuning to OTP memory. Industries’ most advanced STEP/DIR stepper motor driver family upgrades designs to noiseless and most precise operation for cost-effective and highly competitive solutions. Step/Dir Drivers for Two-Phase Bipolar Stepper Motors up to 2.8A peak – StealthChop™ for Quiet Movement – UART Interface Option – Sensorless Stall
### TMC2209 串口通信配置 #### GPIO 配置 为了使 STM32 能够与 TMC2209 步进电机驱动器进行有效的 UART 通信,需先设置相应的 GPIO 引脚。这涉及到指定哪些引脚负责发送数据 (TX) 和接收数据 (RX),以及其他必要的控制信号如片选 (CS)[^3]。 ```c // 初始化GPIO端口 void MX_GPIO_Init(void) { __HAL_RCC_GPIOA_CLK_ENABLE(); // 启用GPIOA时钟 GPIO_InitTypeDef GPIO_InitStruct = {0}; /* 配置PA9作为USART1_TX */ GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.Alternate = GPIO_AF7_USART1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* 配置PA10作为USART1_RX */ GPIO_InitStruct.Pin = GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); // 其他控制信号的初始化... } ``` #### USART 参数设定 接着要调整 USART 的参数来匹配 TMC2209 所期望的工作模式。通常情况下,默认波特率设为 115200 bps 或者按照具体应用需求而定;停止位一般采用一位;无奇偶校验;字符长度通常是八位[^2]。 ```c static void MX_USART1_UART_Init(void) { huart1.Instance = USART1; huart1.Init.BaudRate = 115200; huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; huart1.Init.Mode = UART_MODE_TX_RX; huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart1.Init.OverSampling = UART_OVERSAMPLING_16; if (HAL_UART_Init(&huart1) != HAL_OK) { Error_Handler(); } } ``` #### 数据传输注意事项 当向 TMC2209 发送指令或读取状态信息时需要注意的是,该设备内部有一个可读写的断电保存区域,其容量仅为三个字节(即二十四比特)。每次写入操作仅限于改变单一比特的状态,并建议等待至少十毫秒后再执行下一次访问以确保稳定性和准确性[^4]。 ---
评论 35
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值