首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >STM32F103C8T6 (Blue pill)与Arduino nano的串行通信

STM32F103C8T6 (Blue pill)与Arduino nano的串行通信
EN

Stack Overflow用户
提问于 2020-02-26 19:57:21
回答 1查看 984关注 0票数 0

我的Arduino nano里有一个下一个代码:

代码语言:javascript
复制
#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 (蓝色药丸):

代码语言:javascript
复制
#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呢?

EN

回答 1

Stack Overflow用户

发布于 2020-02-26 20:16:11

尝试为Blue Pill上的Nano设置波特率-它看起来您从未在脚本中设置过波特率。您可能还需要包括软件序列,就像您在Nano上所做的那样- Blue Pill可能没有以其他方式进行通信所需的库。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60413403

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档