我想通过UART将十六进制值从PC接收并保存到STM32-uC。

收到的十六进制值如下所示:

FF00 4a85 04b5 08aa 6b7r 00FF

(FF00和00FF只是检查字节)

我想保存很多(不同)数据行,如下所示:
4a85 04b5 08aa 6b7r4a85 04b5 08aa 6b7r4a85 04b5 08aa 6b7r4a85 04b5 08aa 6b7r4a85 04b5 08aa 6b7r4a85 04b5 08aa 6b7r...................

稍后,我必须读取内存并从每2个字节中获取整数值:

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中做到这一点?

非常感谢你!

最佳答案

语法错误太多,使您无法尝试编写什么内容。例如,在第一个代码片段中,您有一个“ receive_done_flag == FALSE”,它是一个条件表达式,产生1(真)或0(假),但不使用条件的值。您是要写一份工作分配声明吗?还是if陈述?要么...?

在第二个片段中,您具有“ speed_hex_M1 >> 8 = motorspeed_hex [0]”。同样,在C语言中没有意义。左侧是分配给它的“变量(或存储单元)”。因此,您的意思是“ motorspeed_hx [0] = speed_hex_M1 >> 8”还是其他意思>

关于c - 接收十六进制值并将其保存到数组[STM32],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56188378/

10-12 19:15