stm32 到 arduino 的串行通信

huangapple go评论64阅读模式
英文:

stm32 to arduino serial communication

问题

I am sending my adc values to an arduino board via UART.

sprintf(data," ADC1= %d ADC2= %d \n", adcData[0], adcData[1]);//working
HAL_UART_Transmit(&huart2, (uint8_t*)data, strlen(data), 1000); //working
HAL_Delay(500);

and my outputs as like this in Tera Term screen;

stm32 到 arduino 的串行通信

my arduino while loop as follows;

incomingByte = Serial.read(); // read the incoming byte:
String myString = String(incomingByte);
Serial.print(" I received:");
Serial.println(myString);

And the outputs do not match my adc values stm32 到 arduino 的串行通信

stm32 到 arduino 的串行通信

What should I do to see my values as I sent.

英文:

I am sending my adc values to an arduino board via UART.

sprintf(data,"\f ADC1= %d ADC2= %d \r\n",adcData[0],adcData[1]);//calisiyor
HAL_UART_Transmit(&huart2,(uint8_t*)data,strlen(data),1000); //calisiyor
HAL_Delay(500);

and my outputs as like this in Tera Term screen;

stm32 到 arduino 的串行通信

my arduino while loop as follow;

incomingByte = Serial.read(); // read the incoming byte:
String myString = String(incomingByte);
Serial.print(" I received:");
Serial.println(myString);

And the outputs does not like my adc values stm32 到 arduino 的串行通信

stm32 到 arduino 的串行通信

What should ı do to see my values as ı sent.

答案1

得分: 1

要查看您发送的值,您应该将数据中继如其发送。

int incomingByte = Serial.read(); // 读取传入的字节:
if (incomingByte >= 0) { // 如果有输入
  Serial.write(incomingByte); // 打印接收到的内容
}
英文:

To see your values you sent, you should relay the data as it is sent.

int incomingByte = Serial.read(); // read the incoming byte:
if (incomingByte >= 0) { // if there is some input
  Serial.write(incomingByte); // print what is received
}

huangapple
  • 本文由 发表于 2023年3月12日 07:34:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75710222.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定