Question
Weird problem with UART
I work with STM32L475.
First I configure UART
int main(void)
{
/* Configure the system clock to 80 MHz */
SystemClock_Config();
GPIO_Setup();
USART_Setup(UART4, 115200);
USART_SendInt(UART4, 1234, 1);
USART_SendInt(UART4, 0, 1);
while (1)
{
if (uart4_rx_ready)
{
uart4_rx_ready = 0;
PARSER_ParseCommand(uart4_rx_buf);
}
}
}And my print functions
void USART_SendString(USART_TypeDef *USARTx, const char *string)
{
uint32_t timeout;
while (*string)
{
timeout = USART_TIMEOUT;
while ( (USARTx->ISR & USART_ISR_TXE) == 0) { if(!timeout--) break; }
USARTx->TDR = *string++;
}
}
void USART_SendInt(USART_TypeDef *USARTx, int num, int cr)
{
uint32_t timeout;
char str[10];
int i = 0;
uint32_t sign = 0;
if (num<0)
{
num *= -1;
sign = 1;
}
do str[i++] = num % 10 + '0'; while ((num /= 10) > 0);
if (sign)
USART_SendString(USARTx,"-");
for (i--; i >= 0; i--)
{
timeout = USART_TIMEOUT;
while( !(USARTx->ISR & USART_ISR_TXE) ) { if(!timeout--) break; }
USARTx->TDR = str[i];
}
if (cr)
USART_SendString(USARTx, "\r");
}USART_SendString always works good. USART_SendInt - works only at startup
USART_SendInt(SYS_USART, 1234, 1);
USART_SendInt(SYS_USART, 0, 1);
prints me
1234
0
Then in run time if I invoke USART_SendInt - it doesn't print.
With other chips, like STM32F3xx USART_SendInt works without problem.
