qazplm3218 发表于 2020-2-11 22:52:29

串口接收字符串类型数据?

串口通讯,中断接收串口助手发过来的字符串类型的数据比如:ABCD1234,中断接收里用组来保存接收的字符串类型数据,uint8_t   TEMP;
A存入TEMP,B存入TEMP,C存入TEMP依次存入,直到4存入TEMP,
问题是:如何将数组的的字符重新连接起来保存?如何定义新的变量str?使str="ABCD1234"?

radio2radio 发表于 2020-2-11 23:30:15

TEMP[] 与 str = “ABCD1234” 的要相等,就是 TEMP 必须是“0x00”:

TEMP = 0;
memcpy(str, TEMP, 9);

mylovemcu 发表于 2020-2-12 08:34:38

定义一个uint8_t   str;

str = temp;



qazplm3218 发表于 2020-2-12 21:20:51

radio2radio 发表于 2020-2-11 23:30
TEMP[] 与 str = “ABCD1234” 的要相等,就是 TEMP 必须是“0x00”:

TEMP = 0;


uint8_t TEMP;
uint8_t*str=0;
memcpy(str,TEMP,3);编译成功,但是程序执行到memcpy(str,TEMP,3);系统直接死机?不知道是什么原因,是数据类型定义错误??


uint8_t TEMP;
uint8_tstr=0;
memcpy(str,TEMP,3);
编译失败,错误信息如下:

main.c(81): error:#167: argument of type "uint8_t" is incompatible with parameter of type "void *restrict"
      memcpy(str,RxBuffer1,3);

radio2radio 发表于 2020-2-12 22:07:48

初始化uint8_t str = "1234567890";

如果要收3个字节,TEMP=0;   memcpy(str, TEMP, 4);

qazplm3218 发表于 2020-2-12 22:30:11

radio2radio 发表于 2020-2-12 22:07
初始化uint8_t str = "1234567890";

如果要收3个字节,TEMP=0;   memcpy(str, TEMP, 4);

初始化uint8_t str = "1234567890";uint8_t TEMP;

接收2个字节,TEMP=0;   memcpy(str, TEMP, 3);
编译错误
main.c(38): error:#144: a value of type "char *" cannot be used to initialize an entity of type "uint8_t"
uint8_tstr="1234567890";
main.c(81): error:#167: argument of type "uint8_t" is incompatible with parameter of type "void *restrict"
      memcpy(str,TEMP,3);

radio2radio 发表于 2020-2-12 22:48:06

改呀,str的 uint8_t 改为char类型,我错。
页: [1]
查看完整版本: 串口接收字符串类型数据?