I have a simple test project that interfaces with an UART device through the hardware serial port 2 of my STM32 Nucleo32 development kit (STM32L432).
Here is my platformio.ini:
[env:nucleo_l432kc]
platform = ststm32
board = nucleo_l432kc
framework = arduino
build_flags =
-D SERIAL_UART_INSTANCE=2
And here is my code:
void setup() {
pinMode(PA3, INPUT_PULLUP);
Serial2.begin(9600);
}
void loop() {
Serial2.print("AT\r");
delay(500);
while (Serial2.available()) {
char c = Serial2.read();
Serial.print(c); // Print received character
}
delay(5000);
}
However, I’ve run into some inconsistencies with Serial.available()
between the STM32 Nucleo32 platform and Arduino AVR platforms.
I’ve hooked up my UART to ports: PA2 and PA3 on my nucleo board, alongside a logic analyzer.
The logic analyzer shows a correct response (OK\r
) from the peripheral device connected to my development board. However, unlike on Arduino platforms, the incoming serial response doesn’t seem to affect the Serial2.available()
return value in any way. The return value always remains 0, and so the code never reaches the loop where it’s supposed to print out the response from the serial buffer.
This same code works fine on Arduino AVR platforms.
What difference is there with this call between these two platforms?