【发布时间】:2019-10-04 21:38:56
【问题描述】:
我想通过 UART 从 PC 接收十六进制值并将其保存到 STM32-uC。
收到的 HEX 值如下所示:
FF00 4a85 04b5 08aa 6b7r 00FF
(FF00 和 00FF 只是检查字节)
我想保存很多(不同的)数据行,如下所示:
4a85 04b5 08aa 6b7r
4a85 04b5 08aa 6b7r
4a85 04b5 08aa 6b7r
4a85 04b5 08aa 6b7r
4a85 04b5 08aa 6b7r
4a85 04b5 08aa 6b7r
...................
稍后我必须读取内存并从每 2 个字节获取 int 值:
04D1 -> 1233
- 问题:
我创建多数组
volatile uint8_t testarrays[8][5000]; //data storage
并初始化:
uint8_t received_str[12] //4 Bytes: `FF 00 and 00 FF` checksum
uint32_t h=0;
while(h<5000){
if (receive_done_flag == TRUE) { //UART receive data
testarrays[0][h]=received_str[2];
testarrays[1][h]=received_str[3];
testarrays[2][h]=received_str[4];
testarrays[3][h]=received_str[5];
testarrays[4][h]=received_str[6];
testarrays[5][h]=received_str[7];
testarrays[6][h]=received_str[8];
testarrays[7][h]=received_str[9];
}
receive_done_flag == FALSE
h++;
}
我的想法对吗?
- 问题:
我以后如何从存储中读取数据? uint16_t x=0; uint16_t y=0; uint8_t motorspeed_hex[8];
uint16_t speed_hex_M1;
uint16_t speed_hex_M2;
uint16_t speed_hex_M3;
uint16_t speed_hex_M4;
while(y<vert_length){
x=0;
while(x<hor_length){
motorspeed_hex[x] = testarrays[x][y];
x++;
}
uint16_t speed_hex_M1 >> 8 = motorspeed_hex[0]
uint16_t speed_hex_M1 = motorspeed_hex[1]
uint16_t speed_hex_M2 >> 8 = motorspeed_hex[2]
uint16_t speed_hex_M2 = motorspeed_hex[3]
uint16_t speed_hex_M3 >> 8 = motorspeed_hex[4]
uint16_t speed_hex_M3 = motorspeed_hex[5]
uint16_t speed_hex_M4 >> 8 = motorspeed_hex[6]
uint16_t speed_hex_M4 = motorspeed_hex[7]
y++;
}
现在,我必须将 speed_hex_M1.. 转换为 int 值,我该如何在 c 中做到这一点?
非常感谢!
【问题讨论】:
-
怕你不懂基本的东西。你需要从 c 书开始,学习语言和数据类型,然后开始编程微控制器。现在对你来说太早了
-
谢谢,但我尝试通过做来学习它)数据类型有什么问题?
标签: c hex qbytearray