繁体   English   中英

STM32F103C8T6(蓝丸)与Arduino nano串口通信

[英]STM32F103C8T6 (Blue pill) and Arduino nano serial communication

我的 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 TTL,将一些加密数据发送到一台 PC。 PA_9 和 PA10 连接到 Arduino Nano,我希望使用此 UART 从 BluePill 上的 Nano 读取数据,但我总是收到无法读取的 Nano。 尝试更改 Tx-Rx 线,但没有。 为什么不能同时使用两个塞尔维亚语?

尝试为 Blue Pill 上的 Nano 设置波特率 - 它看起来不像您曾经在脚本中设置过。 您可能还需要像在 Nano-the Blue Pill 上所做的那样包含 Software Serial,否则它可能没有通信所需的库。

请注意,我之前没有使用过 Blue Pill,所以我不确定它与 Nano 的相似或不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM