I've made a custom board with STM32L051 IC and i'm using Arduino_Core_STM32. I created a variant based on L051C(6-8)(T-U) example and changed Serial to UART1 (PA9,PA10 pins).
My variant_mydevice.h looks like:
Code: Select all
// UART Definitions
#ifndef SERIAL_UART_INSTANCE
#define SERIAL_UART_INSTANCE 0
#endif
// Default pin used for generic 'Serial' instance
// Mandatory for Firmata
#ifndef PIN_SERIAL_RX
#define PIN_SERIAL_RX PA10
#endif
#ifndef PIN_SERIAL_TX
#define PIN_SERIAL_TX PA9
#endif
Code: Select all
//*** UART ***
#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_TX[] = {
{PA_2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART2)},
{PA_9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART1)},
{PA_14, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART2)},
{PB_6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)},
{PB_10, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_LPUART1)},
{NC, NP, 0}
};
#endif
#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_RX[] = {
{PA_3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART2)},
{PA_10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART1)},
{PA_15, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART2)},
{PB_7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_USART1)},
{PB_11, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_LPUART1)},
{NC, NP, 0}
};
#endif
I have a GSM modem attached to USART2 (PA3, PA2 pins) and i'm trying to send AT commands with code/serial monitor, but it does not work.
Here is my code:
Code: Select all
HardwareSerial Serial2(PA2, PA3); // (RX,TX)
void setup() {
Serial.begin(9600);
Serial.println("### AT TEST ###");
delay(500);
Serial.flush();
Serial2.begin(9600);
delay(5000);
Serial2.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
}
void loop()
{
updateSerial();
}
void updateSerial()
{
delay(500);
while (Serial.available()) {
Serial2.write(Serial.read());
}
while(Serial2.available()) {
Serial.write(Serial2.read());
}
}
If i type any AT command, serial monitor always shows the same.
I already tried swapping HardwareSerial Serial2(PA3, PA2), but that shows a blank serial monitor.
If i use softwareSerial, replacing Serial2 by mySerial
Code: Select all
#include <SoftwareSerial.h>
SoftwareSerial mySerial(PA2, PA3); // (RX,TX)
it works as expected, i see AT response "OK" and if i enter AT commands i see the response at the serial monitor.
Can you please help?
Thanks