Using TTL for serial communication in rp2040 in arduino ide

Hi,

I have write a c code for rp2040 in arduino ide. But i have not give actual output.
Please find the below code.

#ifdef ARDUINO_ARCH_MBED_RP2040
// For the Arduino MBedOS Core, we must create Serial2
UART Serial2(8, 9, NC, NC);
#else
// For the Earl Philhower core ( earlephilhower (Earle F. Philhower, III) · GitHub )
// Serial2 is already defined.
#endif

void setup() {
Serial.begin(9600);
Serial1.begin(115200);
Serial2.begin(115200);
while (!Serial)
; // Serial is via USB; wait for enumeration
}

void loop() {
Serial.println("This is port "Serial"");
Serial1.println("1111111111111\r\nThis is port "Serial1"");
Serial2.println("2222222222222\r\nThis is port "Serial2"");

if (Serial1.read() > 0) { // read and discard data from UART0
Serial.println("Input detected on UART0");
}
if (Serial2.read() > 0) { // read and discard data from UART1
Serial.println("Input on UART1");
}
delay(2000);
}

I have sent data through the Serial Monitor, but I am not receiving it. According to the code, I should be receiving the character I sent through the Serial Monitor

This is port"Serial""
input on UART1.

This is port "Serial""
2222222222222
This is port "Serial2
Input on UART1

Isn't the Serial Monitor stuff just on Serial? There's no provision for if(Serial.read() > 0) in your sketch

But i am using aruino serial monitor. Please see my scratch code for your reference please help me.

I believe that I did.

When data is sent from Serial Monitor then that is on "Serial".

void setup() {
Serial.begin(9600);
Serial1.begin(115200);
Serial2.begin(115200);
while (!Serial)
; // Serial is via USB; wait for enumeration
}

void loop() {
  if (Serial.read() > 0)
  {
    Serial.println("you sent a char");
  }

}

Please let me know how to correct the statement. I am giving input on UART1.

if (Serial2.read() > 0) { // read and discard data from UART1
Serial.println("Input on UART1");
}

With a minimal circuit of UART0 Tx connected to UART1 Rx and UART0 Rx connected to UART1 Tx, the quick & dirty sketch below demonstrates TTL level communication between Serial1 and Serial2 and outputs the results to the Serial port.

#ifdef ARDUINO_ARCH_MBED_RP2040
// For the Arduino MBedOS Core, we must create Serial2
UART Serial2(8, 9, NC, NC);
#pragma message "MBED"
#else
// For the Earl Philhower core ( earlephilhower (Earle F. Philhower, III) · GitHub )
// Serial2 is already defined.
#endif

void setup() {
   Serial.begin(115200);
   delay(5000);
   Serial1.begin(115200);
   Serial2.begin(115200);
   while( !Serial ) {
      ;  // Serial is via USB; wait for enumeration
   }
   while( Serial1.available() ) {
      Serial1.read();
   }
   while( Serial2.available() ) {
      Serial2.read();
   }
   Serial.println("RP2040 Serial port test");
   Serial.println("-----------------------");
}

unsigned long serialSend = 0;

enum {
   SERIAL1_SENDING, 
   PAUSE1,
   SERIAL2_SENDING,
   PAUSE2
} serialState = SERIAL1_SENDING;

unsigned serialIndex = 0;

const char serial1text[] = "text from serial1\r\n";
const char serial2text[] = "TEXT FROM SERIAL2\r\n";

void loop() {
   switch( serialState ) {

      case SERIAL1_SENDING:
         if( millis() - serialSend > 50 ) {
            Serial1.write(serial1text[serialIndex]);
            if( ++serialIndex >= sizeof serial1text ) {
               serialIndex = 0;
               serialState = PAUSE1;
            }
            serialSend = millis();
         }
         break;
         
      case PAUSE1:
         if( millis() - serialSend > 1000 ) {
            serialState = SERIAL2_SENDING;
            serialSend = millis();
            serialIndex = 0;
         }
         break;
         
      case SERIAL2_SENDING:
         if( millis() - serialSend > 50 ) {
            Serial1.write(serial2text[serialIndex]);
            if( ++serialIndex >= sizeof serial2text ) {
               serialIndex = 0;
               serialState = PAUSE2;
            }
            serialSend = millis();
         }
         break;
         
      case PAUSE2:
         if( millis() - serialSend > 1000 ) {
            serialState = SERIAL1_SENDING;
            serialSend = millis();
            serialIndex = 0;
         }
         break;
   }
   
   if( Serial1.available() ) {
      Serial.write(Serial1.read());
   }
   
   if( Serial2.available() ) {
      Serial.write(Serial2.read());
   }
}

Please see the image i want to communicate through ttl.

You will find it exceedingly difficult to have Serial2 do anything useful with nothing connected to its pins (GPIO8 & 9). As to the rest, I have no idea what you have hooked up or why.

My connection is TXD on TTL Adapter to RX (GPIO1) on RP2040 and RXD on TTL Adapter to RX (GPIO0) on RP2040.

We want write a scratch for uart using interrupt.

The RP2040 dose not use TTL signals. It is a 3V3 device and only sends and receives 3V3 logic signals. TTL is a 5V signal.

Once you send anything to a serial monitor, that is it. In other words the signal goes nowhere else. So monitoring the signal on the serial port prevents any other use.

3.3v logic (aka low-voltage TTL - LVTTL) is also referred to as "TTL".

I can't help what ever some unknowable person refers to it it. But TTL stands for "Transistor Transistor Logic" which by definition is a 5V signal.

If you try and stuff a 5V signal into a RP2040, physics takes over the argument, and you will damage it.

An Arduino Uno, and a lot of other models, will generate 5V TTL signal. However some Arduinos have a 3V3 processor, and the signal from them can be passed safely into a RP2040.

I know plenty of highly knowledgeable engineers who will specify the signal levels as "3.3V TTL" or "5V TTL" when discussing logic circuits. Everyone understands what they're talking about, including component manufacturers.

So, your point is a pedantic one at best.

Thank you for your technical support. I have multiple time create a code for ttl to rp2040. finally i realise i have a some issue with hardware connection.
Again thank you so much for reply