我正在使用以下 C 库文件尝试通过 UART 发送 9 个浮点值: https://github.com/microbuilder/LPC1343CodeBase/blob/master/core/uart/uart.c
按照评论中的示例,我想出了以下代码:
#define UARTBUFFERSIZE 36
float testVals[9] = {0.1, 0.2, 0.3, 0.5, 0.6, 0.7, 0.8, 0.9}; //global, just for testing
在我的主要代码中,我有以下行来尝试发送 testVals:
uartSend((float *)testVals, UARTBUFFERSIZE);
main.c:94:4: warning: passing argument 1 of 'uartSend' from incompatible pointer type
core/uart/uart.h:67:6: note: expected 'uint8_t *' but argument is of type 'float *'
我是否必须使用“uint8_t”类型,这样我才能发送浮点值吗?
最佳答案
只需将其转换为uint8_t*
,它是安全的。您的 float 设置正确 9 个 float -> 9 x 4 字节。
关于C编程UART函数不兼容指针类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23569048/