Receiving speed with UART
I have to receive a desired speed that is sent from the TX code, and receive it into the RX code of another different STM32 board that is connected to a Maxon 251601 motor, for it to work.
If i write for example MC_ProgramSpeedRampMotor1(1500,2000) directly in the board that it is connected to the motor it works good.
The problem that I have is that I try to send this from the transmiter board:
char tx_buff[32];
int velocidad = 1500;
while (1)
{
int len = sprintf(tx_buff, "SPD%d\n", velocidad);
HAL_UART_Transmit(&huart2, (uint8_t*)tx_buff, len, HAL_MAX_DELAY);
HAL_Delay(1000);
}
And the receiver has this in the main:
char rx_buff[32];
int duration = 5000;
while (1)
{
HAL_UART_Receive(&huart2, (uint8_t*)rx_buff, 8, HAL_MAX_DELAY);
char *ptr = strstr(rx_buff, "SPD");
if (ptr != NULL)
{
int velocidad = atoi(ptr + 3);
MC_StartMotor1();
MC_ProgramSpeedRampMotor1(velocidad, duration);
}
I was trying for it to receive "SPD1500\n" inside the rx_buff, to make the motor move. The strange thing is that while I was trying to receive it, it actually worked once, but the motor didn't move, so when I tried it again it didn't receive anything, even with the same code. I have heard that it could have been only luck that the transmiter and receiver were sincronized at the same moment, but I could not do it again.
Do you think that I should change something in the code to receive the speed and make the motor move using the MC_ProgramSpeedRampMotor(speed,time), or does this issue come from somewhere else?
