0

I've been struggling for ages, finally caved and asking for help now. There are very little resources on STM32 for this driver that I have seen.

I can use the device with the STEP/DIR interface but I want to be able to do the more advanced things now with only the single UART line and not the STEP/DIR lines.

I am trying to control a TMC2209 in the most basic form to understand how it all works, without libraries and such. I want to get basic controls working so I can understand it and build up my own code from there, right now the goal is to just talk to the thing and get it to spin.

I am using a STM32F103, I have setup the USART3 line (PC10) in signal wire half duplex mode and using the following code to try read from the CHOPCONF register.

       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);

I expect the following : ( according to the Datasheet that is,,, )

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

But I am getting this :

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

I am not sure if I am transmitting these in the correct order or maybe the HAL function should not be used for this at all ?

Any help or pointers in the right direction would be greatly appreciated.

Spider999
  • 135
  • 1
  • 8
  • 17

0 Answers0