Hello everyone, for a couple of weeks I've been interested in the Arduino world using a STM32F103C8T6 prototyping board purchased from China (Ali.....ss), I'm a total beginner, so I can't tell you if it's original or a clone. In fact, by grabbing here and there from the internet, I managed to write a little program in C that finally works as I want. However, I got to the correct functioning thanks to the printing on the Arduino monitor of all the inputs, outputs, bits, counters and timers used. The problem is that now, the Serial.print function, from one day to the next, no longer works and I can't understand why. I can easily upload the program to the STM32 but when I ask to print the variables, nothing appears on the monitor and I don't even see the LEDs of the USB adapter (FTDI) flashing (so, I assume that it's the STM32 that isn't sending anything). I tried on another computer with the same results, I changed the STM32 board with a new one and even then I don't see anything appear on the monitor. It doesn't even print on PICSimLab anymore. I completely uninstalled (using revo uninstaller, so also all the registry entries), both Arduino 2.3.4 and STMCubePrg 2.18 and reinstalled already 3 times and always with the same result. I don't know what to do to get the Arduino monitor working again. If I figure out how, I'll attach the test program.
Could someone help me?
Thank you very much.
Please post your sketch, using code tags when you do
Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
I tried to attach the code but I'm a new member, I'm not allowed to attach anything. In addition, I'm Italian and I have to look for help in the translator to try to understand well.
thanks for your interest
Follow the instructions that I posted and you don't need to attach anything
Would you like me to move your topic to the Italian language section of the forum ?
#include <Arduino.h>
// pins Definition
#define I1_PIN PA0 // selection button
#define AI1_PIN PA1 // analog input vcc
#define I2_PIN PA2 // force print button
#define Q1_PIN PA4 // output led
#define Q2_PIN PA5 // output motor enable
#define Q0_PIN PB12 // temporary led out for monitor
// Definizione dei bit di memoria
bool V_Ok = false; // Bit supply ok
bool M_Cont = false; // Bit continuous
bool M_Interm = false; // Bit intermittent
bool M_Reset = false; // Bit reset
bool Led_On = false; // Bit led enable
bool Q2_On = false; // Bit motor enable
bool M_Start = false; // Bit 1st button press
bool buttonState = LOW;
bool lastButtonState = LOW;
// Definizione dei temporizzatori e contatori
unsigned long T_Max_Pul = 0; // max time mode select
unsigned long Osc_On_Off = 0; // motor intermittence
unsigned int Cont_Puls = 0; // button press counter
unsigned long T_Reset = 0; // time button press for reset
unsigned long Osc_Led = 0; // led intermittence
unsigned NC_Reset = 0; // number of reset cycles
unsigned T_On_Led = 0; // time Led On
void setup() {
// Configura pin I/O
HardwareSerial Serial(PA9, PA10);
Serial.begin(9600); // inizializza seriale
while (!Serial)
;
pinMode(I1_PIN, INPUT);
pinMode(AI1_PIN, INPUT_ANALOG);
pinMode(I2_PIN, INPUT);
pinMode(Q1_PIN, OUTPUT);
pinMode(Q2_PIN, OUTPUT);
pinMode(Q0_PIN, OUTPUT); // test
// Inizializza LED e Pompa
digitalWrite(Q1_PIN, LOW);
digitalWrite(Q2_PIN, LOW);
}
void loop() {
unsigned int adc_value = analogRead(AI1_PIN); // Legge il valore dell'ADC
// Controlla AI1 per la tensione corretta
if ((adc_value > 0x307) && (adc_value < 0x3a2)) {
V_Ok = true; // valore alimentazione nei limiti
} else {
V_Ok = false; // valore alimentazione nei limiti
}
// invia i dati a Seriale
if (digitalRead(I2_PIN) == HIGH) {
digitalWrite(Q0_PIN, HIGH);
Serial.print("I1_PIN = ");
Serial.println(I1_PIN);
Serial.print("adc_value = ");
Serial.println(adc_value);
Serial.print("V_Ok = ");
Serial.println(V_Ok);
Serial.print("I2_PIN = ");
Serial.println(I2_PIN);
Serial.print("Q1_PIN = ");
Serial.println(Q1_PIN);
Serial.print("Q2_PIN = ");
Serial.println(Q2_PIN);
Serial.print("M_Cont = ");
Serial.println(M_Cont);
Serial.print("M_Interm = ");
Serial.println(M_Interm);
Serial.print("Led_On = ");
Serial.println(Led_On);
Serial.print("Q2_On = ");
Serial.println(Q2_On);
Serial.print("T_Max_Pul = ");
Serial.println(T_Max_Pul);
Serial.print("Osc_On_Off = ");
Serial.println(Osc_On_Off);
Serial.print("Cont_Puls = ");
Serial.println(Cont_Puls);
Serial.print("T_Reset = ");
Serial.println(T_Reset);
Serial.print("Osc_Led = ");
Serial.println(Osc_Led);
Serial.print("M_Reset = ");
Serial.println(M_Reset);
Serial.print("M_Start = ");
Serial.println(M_Start);
Serial.print("NC_Reset = ");
Serial.println(NC_Reset);
} else {
digitalWrite(Q0_PIN, LOW);
}
// Aggiornamento time
delay(1);
}
This is just a test to check if the monitor is working and even then, it doesn't work for me.
Is there some menu entry related to CDC in the tools menu for the board that you selected? If yes you might have to enable it.
I'm not familiar with your board and the possible menu entries.
it's already set up like this, it worked fine for a few days, then it stopped and I don't know why.
no, I want to keep the current forum, I need it to learn.
here I am again, I continued to test and I can say that at the beginning, Serial.print() worked for a few days, then when it stopped working I first added a delay(50) after Serial.begin and since it didn't work anyway, I replaced delay with while(!Serial) and the prog never ran, then I added HardwareSerial Serial(PA10,PA9), before Serial.begin and so it runs but still doesn't send anything to the monitor. I also confirm that even by loading the .bin on PICSimLab, printing to the monitor doesn't work for me.
I trust a lot in your skills and experience, I have already exhausted my limited knowledge.
thanks to everyone.
Maybe @ptillisch has an idea what might be wrong. If he doesn't reply here he probably does not know.
Hi @aliex_59.
This is a bug. You are defining the Serial
object local to the scope of the setup
function. The object is only defined inside that scope. The Serial
object you use in the loop
function is a completely different one, which is defined globally by the core:
This is called "variable shadowing", and is the cause of many a confusing bug.
I'm also suspicious about the arguments. The parameters of the HardwareSerial
constructor are:
You are trying to configure PA9 as the RX pin of the board and PA10 as the TX pin of the board. But we can see that the default pins are opposite of that:
I have almost zero experience working with 3rd party STM32 boards so I don't know whether it is possible to configure any arbitrary pins as hardware serial, especially when those pins are already configured as serial by the core, except with the opposite assignments. It doesn't make any sense to do that, so it isn't worth investigating anyway.
It is unnecessarily complex for a test. You need to refine your troubleshooting techniques.
Please try with a simple sketch:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("hello");
delay(1000);
}
Connect pin A9 on the STM32F103C8T6 prototyping board to the RX pin on the FTDI adapter. You should now see "hello" printed in Serial Monitor at 0.5 Hz.
I tested this personally with my STM32F103C8 "Blue Pill" board and it works as expected.
I was not able to get serial output from your sketch, even after fixing the variable shadowing bug. However, once I switched it to use pin A9 as the TX pin instead of A10, it did work as expected.
The TX LED on the common FTDI adapters only blink when the serial port of the adapter is open.
Hi @ptillisch. Thank you for the help you offered. For the definitions of the PA9, PA10 pins, I also tried to invert them but without success. When I say that I don't see the LED flashing on the FTDI adapter, I mean the RX LED, that is, my STM32 module is not transmitting anything. However, after several tests I have come to a conclusion, I am a beginner (but stubborn). I have verified that using the board manager of the link "https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json" which should be "official", Serial.print does not work, nothing is transmitted from the module. I also noticed that, if there is no instruction "HardwareSerial Serial(PA10, PA9)" before "Serial.begin(9600)", "while (!Serial)" blocks the program execution.
If instead I use/install the manager from the link "http://dan.drown.org/stm32duino/package_STM32duino_index.json", everything works perfectly, there is only one very small inconvenience, if I try to load the program on the STM with the IDE monitor open, it gives me a port error and I don't understand why, at that moment the STM is reset and therefore does not transmit anything on the port, so much so that the port is set (in my case) to 9600 and the loading occurs at 115000. My desire would be to use the first link because from what I see it is the official one but unfortunately it does not work for me. Can anyone help me understand the difference between the two managers or tell me what to add to the configuration to make the official manager work completely? Thanks everyone.
And I verified that it works just fine after fixing the bugs in your sketch code.
Did you try the test I provided in post #12?
Then remove the pointless while (!Serial)
from your code! That construct is only useful when you are using the native USB capabilities of a board to produce a CDC serial port via a direct USB connection to the computer. It is not at all useful when you are using the UART on the board to connect to the computer via a USB to serial bridge adapter.
That platform has not been under active development for years. I'm sure it is a very nice platform, but the "STM32 MCU based boards" platform is also nice and also actively maintained.
Try the test I provided in post #12.
I did as you suggested (I think),
//
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
Serial.println("hello");
delay(1000);
}
but with "https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json", it doesn't print anything. Am I missing some library?
The screenshot was helpful. From looking at it, I think the problem is the way you have configured the board. Please try this:
- Select Tools > USB support (if available) > None from the Arduino IDE menus.
- Select Tools > U(S)ART support > Enabled (generic 'Serial') from the Arduino IDE menus.
- Upload the minimal "hello" test sketch to the board.
- Connect pin A9 on the STM32F103C8T6 prototyping board to the RX pin on the FTDI adapter.
- Select the port of the FTDI adapter from Arduino IDE's Tools > Port menu.
- Open Serial Monitor.
- Select "9600" from the baud rate menu in Serial Monitor.
Do you now see "hello" printed in Serial Monitor at 0.5 Hz?
GREAT, it works now!!! Thank you so much for your help. I'm just sorry I bothered you with something like that. So, just to clarify, in Tools, "USB Support" means the USB port (mini or C) soldered onto the board and "U(S)ART Support" means the various serials referred to the board pins? Thanks again everyone.
You are welcome. I'm glad it is working now.
That is correct. This is a direct connection to the USB data pins on the STM32 chip, using the microcontroller's native USB capabilities to communicate with the computer via a USB CDC serial port, or HID.
That is correct. In this case, the communication interface is plain serial and communication with the computer requires the use of a USB to serial bridge like your FTDI module.