我的Arduino nano里有一个下一个代码:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
void setup()
{
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Native USB only
}
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() // run over and over
{
mySerial.write("Software serial from Arduino Nano\n");
delay(500);
}如果我将D2和D3连接到我的TTL,我可以以9600波特率读取消息,但是如果我用下一个代码将Tx->Rx和Rx->Tx连接到我的STM32F103C8T6 (蓝色药丸):
#include "stm32f103c8t6.h"
#include "mbed.h"
#include "USBSerial.h"
#include "Crypto.h"
int main() {
Serial pc(PA_2, PA_3);
Serial nano(PA_9, PA_10);
while(1)
{
//AES data here
if(nano.readable())
{
printf("Nano is here!\n");
char c[128];
nano.gets(c, 4);
printf("I got c line: %s \n", c);
}
else
{
printf("Nano is unreadable\n");
}
wait_ms(1000);
}
}在PA_2上,PA_3是USB,它将一些加密的数据发送到一台PC。PA_9和PA10连接到Arduino Nano,我希望用这个UART从BluePill上的Nano读取数据,但我总是收到一个无法读取的Nano。我试着更换Tx-Rx线,但没有结果。为什么不能同时使用两个serbial呢?
发布于 2020-02-26 20:16:11
尝试为Blue Pill上的Nano设置波特率-它看起来您从未在脚本中设置过波特率。您可能还需要包括软件序列,就像您在Nano上所做的那样- Blue Pill可能没有以其他方式进行通信所需的库。
请注意,我以前没有使用过Blue Pill,所以我不确定它与Nano有多相似或不同。
https://stackoverflow.com/questions/60413403
复制相似问题