UART 4 bit numeric value communication
I am doing the project to control linear motor, For that I am using UART to send start and stop command to start and stop motor, as like this i sending different rpm value from 100 to 3000 randomly to change the ramp of the motor.
The problem that i am facing is for 3 digit number RPM i am getting output, but when is comes to 4 digit value i am not getting proper putput,
For example:
For 1000 RPM, I am getting 100 RPM as out put

- Baud Rate: 115200 bps
- Data Bits: 8
- Parity: None
- Stop Bits: 1
void
HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart)
{
int cmd_ok = 0;
rxbuffer[strlen(rxbuffer)] = '\0';
if (strncmp((const char*)rxbuffer, "start", 6) == 0)
{
rxbuffer[strlen(rxbuffer)] = '\0';
flag = 1;
cmd_ok = 1;
// MC_StartMotor1();
}
else if (strncmp((const char*)rxbuffer, "stop", 5) == 0)
{
rxbuffer[strlen(rxbuffer)] = '\0';
flag = 0;
cmd_ok = 1;
// MC_StopMotor1();
}
else
{
rxbuffer[strlen(rxbuffer)] = '\0';
char* endptr;
uint16_t rpmValue = strtol((char*)rxbuffer, &endptr, 10);
// rpmValue = atoi((char*)rxbuffer);
if (rxbuffer[0] != '\0' && *endptr == '\0' && rpmValue >= 100 && rpmValue <= 3000)
{
MC_ProgramSpeedRampMotor1(rpmValue, 30000);
// HAL_Delay(60000);
cmd_ok = 1;
}
}
if (cmd_ok == 1)
{
memset(rxbuffer, 0, sizeof(rxbuffer));
cmd_ok = 0;
rxindex = 0;
}
else
{
rxindex++;
}
HAL_UART_Receive_IT(&huart2, ((uint8_t*)rxbuffer) + strlen(rxbuffer), 1);
}