UART1 and UART2 communication for RAK3172

Hi,

I am wondering if it’s possible to connect an ESP32 to a RAK3172 using I2C for data interchange.
Or should we go with UART1, cause UART2 we will use for the debugging & to burn the code.
One more thing if I use
if(Serial.available())
in the code, but all the data we type at UART that will consider as AT command.

so final thing I want is to communicate RAK3172 with ESP32

Hi @rushi_5029 ,

I2C data exchange should be possible but I am not sure if there is any available implementation you can use as reference. So I suggest to just use UART.

It is advisable to use UART1 so that UART2 is reserved for FW update and AT commands configuration.

If you plan to use UART2, you can use it in custom mode. It will not respond to AT commands (all disabled) except to AT+BOOT which will initiate bootloader mode.

OH thanks
but right now I am facing a problem and problem is I just used the custom mode as mentioned by you and I take the reference from your website, now whenever i am going to upload the new changed code to RAK3172 it just say
Device is not in boot mode
Detecting baudrate…
Detect baudrate fail, can not get the baudrate
and uploading fails!
why this?
what to do next?
if I connect BOOT0 pin to the VDD for the time of the uploading and then remove it will work?

Can you try to send AT+BOOT and see if it will go to bootloader mode? Have you double checked the UART baud rate?

not working, at the time of uploading the new code it is not going to the boot mode so uploading fails!

#include <Rak3172_Canopus.h>

// Use the default Serial1 instance for custom mode (RAK3172 UART1 is used for custom mode)
// On the RAK3172, by default, UART1 is assigned to custom mode and mapped to pins TX = 4 and RX = 5.

void setup() {
  // Initialize USB Serial (for debugging) in custom mode
  // Serial.begin(115200, RAK_CUSTOM_MODE);
  // Serial1.write("Rushikesh");
  // Initialize Serial1 (custom mode) at 9600 baud.
  // Note: The RAK Arduino core for STM32WLE supports the overload: begin(baud, config, RAK_SERIAL_MODE)
  Serial1.begin(9600, SERIAL_8N1, RAK_CUSTOM_MODE);
  
  while (!Serial1);
  Serial1.println("\nRAK3172 Transmitter - Custom Mode Enabled on UART1 ");
}

void loop() {
  String message = "Hello from RAK3172!";
  // Send the message over the custom UART (Serial1)
  Serial1.println(message);
  
  // Debug: Print what is being sent to the USB serial monitor.
  Serial1.print("RAK3172 sent: ");
  Serial1.println(message);
  Serial1.write(message);
  delay(5000); // wait 5 seconds before sending next message
}

i just wanted to communicate between esp32 from rak3172 sends data and esp32 will receives it!

Let me give you some pointers.

  1. Do not touch BOOT0. Unless you will use STM32CubeProgrammer, leave it floating.
  2. Make the UART work first on UART2. Do not involve ESP32 yet unless AT commands on UART is working. If UART2 is not working, what is the last code you uploaded before it stops working? The code you shared has commented Serial.begin so I do not think this is the code that made it stop working.
  3. Let’s remove the factor of hardware. Please ensure that USB-UART being used as well as the USB port and cable are ok.
  4. I can make UART1 working for AT command and disable AT command on UART2 using this code. UART2 will still allow AT+BOOT using this code so uploading code is still possible. I can also escape bootloader mode using AT+RUN. Baud rate is both 115200.
void setup()
{   
    // initialize serial communication at 115200 bits per second, and use custom mode so it will not respond to AT commands.
    Serial.begin(115200, RAK_CUSTOM_MODE);
    // initialize serial communication at 115200 bits per second, and use AT mode so it will be used as external modem to ESP32.
    Serial1.begin(115200, RAK_AT_MODE);
    delay(2000);
}

void loop()
{

}
  1. If nothing works on your RAK3172, you can always put it back on a fresh state. Use UART2 to fully erase the chip then uploading the hex FW using STM32Cubeprogrammer. At this point you need to pullup BOOT pin. Here’s the guide - How To Guide: STM32CubeProgrammer for RAK Modules | RAKwireless Documentation Center

I am testing only basic code

#include <Rak3172_Canopus.h>

void my_printing(char buf)
{
  Serial.printf("%c",buf);
}
void setup() 
{
  Serial.begin(9600, RAK_CUSTOM_MODE);
  Serial1.begin(9600, RAK_AT_MODE);
  while (!Serial);
  Serial.println("Custom Mode Echo Test on UART1");
  Serial.println("Connect TX and RX of UART1 (pins 4 and 5) for loopback.");
}

void loop() 
{
  while (Serial.available()) 
  {
    char buf = Serial.read();
    Serial.println();
    Serial.write(buf);
    my_printing(buf);
  }
  delay(10);
}

this code i am using for communicate between esp32 while i want less baud rate cause my esp32 is engaed already with other devies.
but for me if i tried something new and want to test then every time it says,

Device is not in boot mode
Detecting baudrate…
Detect baudrate fail, can not get the baudrate

but before i am using it fr lora p2p communication it works fine it goes into automatic boot mode while uploading and I tried,

AT+BOOT

cmd also but for that cmd response is,

12:54:36.931 → AT not support.

Every time for upload user code have to Erase & then uploading the new firmware of RAK3172 then it works for the instance but later again it won’t.

And i have question like for esp32 if we begin serial like
mySerial.begin(9600, SERIAL_8N1, RXD1, TXD1);
then ok
but for rak3172 begin is like
Serial1.begin(9600, RAK_AT_MODE);

then how to define the pin numbers for serial communication or by default it takes

@beegee @carlrowan

Can you please look into this matter?

Please upload a fresh FW again using STM32Cubeprogrammer. Don’t forget to erase.

Just so we have a fresh module.

Then to make the AT commands work for both UART1 and UART2, please upload this code (you can lessen the delay to whichever you need).

void setup()
{   
    // initialize serial communication at 9600 bits per second, and use AT mode so it will be used as external modem.
    Serial.begin(9600, RAK_AT_MODE);
    // initialize serial communication at 9600 bits per second, and use AT mode so it will be used as external modem.
    Serial1.begin(9600, RAK_AT_MODE);
    delay(2000);
}

void loop()
{

}

Once new baud rate is applied, you can upload a new firmware by sending AT+BOOT using the new baud rate you configured. Send AT+BOOT before uploading the FW in your Arduino IDE. Close the serial terminal as well before hitting upload.

For example, if you upload that code I shared above, you can only send AT+BOOT when the baud rate is 9600.