2025-06-17 1:59 PM
I'm using an STM32L452RE MCU to communicate with the L6470 stepper motor driver via SPI, and I'm currently having trouble reading data from the driver.
I’m able to transmit data (e.g., RUN, MOVE, SOFT_STOP commands).
The motor runs and responds correctly, so SPI transmit appears functional.
Problem:
I'm trying to read registers like ABS_POS, ACC, etc. using the GET_PARAM command.
I always receive 0 in response, regardless of the register.
Setup:
MCU: STM32 (HAL SPI)
SPI Mode: CPOL = 1, CPHA = 1 (Mode 3)
Driver: L6470
Motor: Connected and moving
MISO, MOSI, SCK, CS connections confirmed
uint32_t L6470_ReadABS_POS(void) {
uint8_t cmd = 0x25; // GET_PARAM | ACC (0x05)
static uint8_t TramsmitData[2];
TramsmitData[0] = cmd;
TramsmitData[1] = 0x00;
static uint8_t receivedData[2] = {0};
for (int index = 0; index < 1; index++)
{
L6470_CS_Low();
HAL_SPI_Transmit(&hspi2,&TramsmitData[index], sizeof(TramsmitData[index]), HAL_MAX_DELAY);
HAL_SPI_Receive(&hspi2, &receivedData[index],sizeof(receivedData[index]), HAL_MAX_DELAY);
L6470_CS_High();
}
printf("receivedData[0] %d \r\n",receivedData[0]);
printf("receivedData[1] %d \r\n",receivedData[1]);
// printf("ABS_POS = %ld\n", value);
}
void L6470_Init()
{
L6470_SetABS_Pos(1000);
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_SPI2_Init();
/* USER CODE BEGIN 2 */
L6470_Init();
L6470_Run(0, 0x6312); // RUN forward at max speed
L6470_ReadABS_POS();
}
2025-06-17 2:14 PM
Welcome to the forum
Please see How to write your question to maximize your chances to find a solution for best results - in particular, How to insert source code
What board(s) are you using?
Please show schematic(s)
Have you looked at the SPI lines with an oscilloscope and/or analyser to see what's going on?