0
votes

I have a next code in in my 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);
}

If i connect the D2 and D3 to my TTL, i can read the message at 9600 baud, but if i connect the Tx->Rx and Rx->Tx to my STM32F103C8T6 (Blue pill) with a next code:

#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);
    }
}

On the PA_2, PA_3 is an USB TTL, that send some encrypted data to one PC. The PA_9 and PA10 are connected to Arduino Nano, and i wish to read the data from Nano on the BluePill with this UART, but i always receive that a Nano in unreadable. Have try to change the Tx-Rx wires, but nothing. Why will not work a simultanous use of two serbials?

1
the AVR SoftwareSerial has in constructor RX,TX, the mbed has TX, RX in Serial constructor. did you wire D2 to PA9 and D3 to PA10?Juraj
@Juraj Yes, the D2->PA_9 and D3->PA_10 On the ARV side is all OK, i think, because if a connect to D2 D3 an TTL USB, and i look with minicom, i can read the data from Nano at 9600 baud. The problem is on STM32 side, because it seems not to see the Nano.Peter Boldt
did you try the STM32 Serial 1 with an USB to TTL adapter?Juraj
@Juraj Unfortunately not, because i have just one USB TTL here, and have no two devices. Is strange that is no possible to find good examples of using two Serbial interfaces at same time on BluePill.Peter Boldt
you only need one for a test with echo sketchJuraj

1 Answers

0
votes

Try setting a baud rate for the Nano on the Blue Pill-it doesn't look like you ever set one in your script. You may also need to include Software Serial like you do on your Nano-the Blue Pill may not have the library it needs otherwise to communicate.

Note, I haven't worked with a Blue Pill before so I'm not sure of how similar or different it is from the Nano.