Increase UART speed
8 years 2 months ago #29530359
by tako
Increase UART speed was created by tako
Hi,
I am connecting my STM32F4 board with our Roboteq SDC2130. I want to get some data from Roboteq during run-time.
For example the acceleration in the below code:
int Get_Acc(void)
{
uint8_t acc=0;
uint8_t tx_motor[7]; // data transmit to motor controller
uint8_t rx_motor[10]={0};
tx_motor[0]='~';
tx_motor[1]='M';
tx_motor[2]='A';
tx_motor[3]='C';
tx_motor[4]=' ';
tx_motor[5]='1';
tx_motor[6]='\r';
roboteq_acc_tick[a]=HAL_GetTick();
HAL_UART_Transmit(&roboteq_huart, tx_motor,7, 20);
roboteq_acc_tick[a]= HAL_GetTick()-roboteq_acc_tick[a];
HAL_UART_Receive(&roboteq_huart, rx_motor,10, 20) // Receive MAC=?????\r
a++;
if (a==200) a=0;
if(rx_motor[8]!='\r')
return ((rx_motor[4]-48)*1000+(rx_motor[5]-48)*100+(rx_motor[6]-48)*10+(rx_motor[7]-48));
else
return ((rx_motor[4]-48)*100+(rx_motor[5]-48)*10+(rx_motor[6]-48));
}
I use roboteq_acc_tick to get the execution time for everytime this function was called. However, sometimes the execution time is 1ms, sometimes it is 0ms(this function is just an example, there are quite a number of functions which also send commands to Roboteq in the program). However, if I use this function alone with a test program, its execution time is always 0ms. Is there anything wrong in my code? Let's say if I want the execution time is strictly less than 1ms, is there any way to do it?
Thank you.
I am connecting my STM32F4 board with our Roboteq SDC2130. I want to get some data from Roboteq during run-time.
For example the acceleration in the below code:
int Get_Acc(void)
{
uint8_t acc=0;
uint8_t tx_motor[7]; // data transmit to motor controller
uint8_t rx_motor[10]={0};
tx_motor[0]='~';
tx_motor[1]='M';
tx_motor[2]='A';
tx_motor[3]='C';
tx_motor[4]=' ';
tx_motor[5]='1';
tx_motor[6]='\r';
roboteq_acc_tick[a]=HAL_GetTick();
HAL_UART_Transmit(&roboteq_huart, tx_motor,7, 20);
roboteq_acc_tick[a]= HAL_GetTick()-roboteq_acc_tick[a];
HAL_UART_Receive(&roboteq_huart, rx_motor,10, 20) // Receive MAC=?????\r
a++;
if (a==200) a=0;
if(rx_motor[8]!='\r')
return ((rx_motor[4]-48)*1000+(rx_motor[5]-48)*100+(rx_motor[6]-48)*10+(rx_motor[7]-48));
else
return ((rx_motor[4]-48)*100+(rx_motor[5]-48)*10+(rx_motor[6]-48));
}
I use roboteq_acc_tick to get the execution time for everytime this function was called. However, sometimes the execution time is 1ms, sometimes it is 0ms(this function is just an example, there are quite a number of functions which also send commands to Roboteq in the program). However, if I use this function alone with a test program, its execution time is always 0ms. Is there anything wrong in my code? Let's say if I want the execution time is strictly less than 1ms, is there any way to do it?
Thank you.
Please Log in or Create an account to join the conversation.
Moderators: tonysantoni
Time to create page: 0.047 seconds