tommag / TMC5160_Arduino

Arduino library for Trinamic TMC5160 stepper motor driver
MIT License
69 stars 24 forks source link

Delay for the minimum CSN time after SPI transfer #21

Closed DeanIsMe closed 1 year ago

DeanIsMe commented 1 year ago

The minimum chip select high time is 2*tCLK + 10 ns. This solution waits for this amount of time after each SPI transaction. It accounts for the clock speed of the arduino using F_CPU, and the clock speed of the TMC5160 with TMC5160::fclk. This delay is only necessary when performing consecutive SPI transactions. But, it's so short (~200 ns) that there's no real cost to adding the delay after every SPI transaction.

This was noted in issue #15

tommag commented 1 year ago

In the end I took an easier path of using the builtin delayNanoseconds() on Teensy and delayMicroseconds(1) on other platforms. When you have a slower processor, 1us doesn't matter that much :) Thanks very much for taking time to submit !