halo from indonesia

beryindo
Posts: 11
Joined: Wed Oct 18, 2017 10:43 am

halo from indonesia

Post by beryindo » Wed Oct 18, 2017 10:57 am

halo I am from indonesia.
i new use stm32. i want to ask about the pin.
Serial1 in mega, can i use pin in stm32?
pin 50 and 51 in mega, can i use pin in stm32?
does my scetch code need to be changed ?
if my scetch code needs to be changed there?
does my scetch code need to be added ?

Code: Select all

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
#define gpsPort Serial1
#include <SoftwareSerial.h>
#define PIN_TX    50
#define PIN_RX    51
thank you

User avatar
zoomx
Posts: 523
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: halo from indonesia

Post by zoomx » Wed Oct 18, 2017 2:27 pm

Yes it need to be changed but you don't need software serial since you more than one hardware serial. MEGA has more than one hardware serial too!

In this forum there are also example sketch for PCD8544 LCD (or nokia 5110).
PCD8544 (Nokia 5110 Display)
viewtopic.php?f=13&t=7

beryindo
Posts: 11
Joined: Wed Oct 18, 2017 10:43 am

Re: halo from indonesia

Post by beryindo » Thu Oct 19, 2017 12:28 am

can give mae example for changer Serial1 in Mega, what in stm32 ?

User avatar
zoomx
Posts: 523
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: halo from indonesia

Post by zoomx » Thu Oct 19, 2017 6:09 am

From Arduino reference
https://www.arduino.cc/en/Reference/Serial
The Arduino Mega has three additional serial ports: Serial1 on pins 19 (RX) and 18 (TX), Serial2 on pins 17 (RX) and 16 (TX), Serial3 on pins 15 (RX) and 14 (TX). To use these pins to communicate with your personal computer, you will need an additional USB-to-serial adaptor, as they are not connected to the Mega's USB-to-serial adaptor. To use them to communicate with an external TTL serial device, connect the TX pin to your device's RX pin, the RX to your device's TX pin, and the ground of your Mega to your device's ground.
From STM32 reference
http://wiki.stm32duino.com/index.php?title=API
Serial & USB Serial
Serial USB is enabled for all F103 boards when uploading using the bootloader, it is also available when uploading by ST-Link (SWD) In these cases:

Serial.print("Hello world"); will print via Serial USB (CDC).
Serial1 prints to hardware USART 1
Serial2 prints to hardware USART 2
etc
When uploading via "Serial" (external USB to Serial adaptor connected to PA9 and PA10 (USART1) on the STM32):

Serial.print("Hello world"); will print to hardware USART1 (the one the code was uploaded using)
Serial1 prints to hardware USART 2
etc
Note. Some boards, e.g. Nucleo F103RB have special serial mapping, because these boards need to have hardware modification to make Serial usable.

The Serial <-> USART mapping is defined in file "variants/<board_name>/board.cpp".

beryindo
Posts: 11
Joined: Wed Oct 18, 2017 10:43 am

Re: halo from indonesia

Post by beryindo » Thu Oct 19, 2017 9:19 am

thank you for replying. I use STM32F103C8T6, upload it using USB to serial PL2303HX by using pin A9 and pin A10. how can i see serial monitor like arduino mega?

Image

User avatar
zoomx
Posts: 523
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: halo from indonesia

Post by zoomx » Thu Oct 19, 2017 9:53 am

You have a board that is known as Blue Pill, from STM32Wiki
http://wiki.stm32duino.com/index.php?title=Blue_Pill
Image

TX1 PA9 USART1
RX1 PA10

TX2 PA2 USART2
RX2 PA3

TX3 PB10 USART3
RX3 PB11

After uploading you can use the same serial port (and pins) for serial monitor like on a Mega.
Since you're uploading code using serial
Serial.print("Hello world"); will print to hardware USART1 (the one the code was uploaded using), that is the same serial port that I can see in photo.

beryindo
Posts: 11
Joined: Wed Oct 18, 2017 10:43 am

Re: halo from indonesia

Post by beryindo » Thu Oct 19, 2017 1:16 pm

I try with this code, but I can't show on serial monitor

Code: Select all

void setup() {
    Serial.begin(115200);
    Serial.print("test print donk");
}

void loop() {

}

stevestrong
Posts: 1735
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: halo from indonesia

Post by stevestrong » Thu Oct 19, 2017 1:41 pm

For output on PA9/PA10, you have to use Serial1.

Code: Select all

void setup() {
    Serial1.begin(115200);
    Serial1.print("test print donk");
}
uint32_t counter;
void loop() {
  Serial1.println(counter++);
  delay(1000);
}

User avatar
zoomx
Posts: 523
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: halo from indonesia

Post by zoomx » Thu Oct 19, 2017 2:15 pm

Since he is using serial upload Serial.print should output on the same port.

I use this simple sketch to identify ports used.

Code: Select all

/*
  STM32_serial_test
*/

void setup() {
  Serial.begin(115200);
  Serial1.begin(115200);
  Serial2.begin(115200);

  Serial.println("Hello world this is Serial");
  Serial1.println("Hello world this is Serial1");
  Serial2.println("Hello world this is Serial2");

 delay(500);
}

void loop() {
  Serial.println("It Works on serial");
  Serial1.println("It Works on serial1");
  Serial2.println("It Works on serial2");
  delay(500);
}

beryindo
Posts: 11
Joined: Wed Oct 18, 2017 10:43 am

Re: halo from indonesia

Post by beryindo » Sat Oct 21, 2017 5:17 am

zoomx wrote:
Thu Oct 19, 2017 2:15 pm
Since he is using serial upload Serial.print should output on the same port.

I use this simple sketch to identify ports used.

Code: Select all

/*
  STM32_serial_test
*/

void setup() {
  Serial.begin(115200);
  Serial1.begin(115200);
  Serial2.begin(115200);

  Serial.println("Hello world this is Serial");
  Serial1.println("Hello world this is Serial1");
  Serial2.println("Hello world this is Serial2");

 delay(500);
}

void loop() {
  Serial.println("It Works on serial");
  Serial1.println("It Works on serial1");
  Serial2.println("It Works on serial2");
  delay(500);
}
thank you, its work, why respon USSD can't show ?
Image

Code: Select all

#define Sim800LSerial Serial1 //A2,A3

void setup(){
  Sim800LSerial.begin(9600);
   Serial.begin(9600);
}

void loop(){
  if(Sim800LSerial.available()){
    Serial.write(Sim800LSerial.read());
  }
  if(Serial.available()){     
    Sim800LSerial.write(Serial.read()); 
  }
}

Post Reply