2024-02-19 11:03 AM
Hi I wanted to translate the following Arduino code with hal stm:
uint32_t TMC5160_SPI::readRegister(uint8_t address)
{
// request the read for the address
_beginTransaction();
_spi->transfer(address);
_spi->transfer(0x00);
_spi->transfer(0x00);
_spi->transfer(0x00);
_spi->transfer(0x00);
_endTransaction();
//Delay for the minimum CSN high time (2tclk + 10ns -> 176ns with the default 12MHz clock)
#ifdef TEENSYDUINO
delayNanoseconds(2 * 1000000000 / _fclk + 10);
#else
delayMicroseconds(1);
#endif
// read it in the second cycle
_beginTransaction();
_spi->transfer(address);
uint32_t value = 0;
value |= (uint32_t)_spi->transfer(0x00) << 24;
value |= (uint32_t)_spi->transfer(0x00) << 16;
value |= (uint32_t)_spi->transfer(0x00) << 8;
value |= (uint32_t)_spi->transfer(0x00);
_endTransaction();
_lastRegisterReadSuccess = true; // In SPI mode there is no way to know if the TMC5130 is plugged...
return value;
}
Thanks
2024-02-19 12:50 PM
Use this button to properly post source code:
2024-02-19 08:26 PM
Is there a question?
What chip? Should be examples in the CubeMX repository for how to interface with SPI.
2024-02-20 02:39 AM
You know that there's an Arduino Core available for STM32?
https://www.arduino.cc/reference/en/libraries/stm32duino-examples/
@SDall wrote:I wanted to translate the following Arduino code with hal stm
So what have you tried? Where are you stuck?