如何使用DisplayStringAtLine函数在STM32上正确显示uint32变量

问题描述

我正在尝试在连接到STM32F407评估板的LCD显示器(Waveshare 3.2英寸TFT)上显示uint32_t值。 Waveshare提供的库包含一个函数BSP_LCD_displayStringAtLine。我的字符串输出可以正常工作,但是当我尝试向它发送uint32_t值时,它只会在LCD上应该显示该值的行上显示损坏的数据。

我尝试使用

BSP_LCD_displayStringAtLine (3,(uint8_t*) Difference);

还有

BSP_LCD_displayStringAtLine (3,(uint8_t*) &Difference);

但是会产生废话。我想我可能没有正确地将变量传递给函数,但是制造商提供的文档并不全面,我在Google上找不到太多帮助。

解决方法

您需要先将uint32_t转换为字符串。

伪代码:

uint32_t value = 7;
uint8_t buf[16]; // pick a large enough size
u32_to_u8str(value,buf); // assuming this null terminates the string
BSP_LCD_DisplayStringAtLine(3,&buf);

This question可能会有有用的答案。