ESP8866 D1 mini, can only receive serial on pin 13 (D7), not pin 3 (RX)

Im sending serial data from a SIM5320E to the ESP. If using pin 3 the ESP receives nothing. If using Serial.swap() and pin 13 everything is as expected.
I am using this code:

char receivedChar;




void setup() {
  Serial.begin(115200);
  Serial1.begin(115200);
 // Only used with pin 13
  Serial.swap();
}

void loop() {
  
  while (Serial.available() > 0)
{
      receivedChar = Serial.read();
      Serial1.print(receivedChar);
}
}

I also have a USB-TTL interface that I have connected to pin 2 (Serial1) for debug purpose. If I connect pin 3 (RX) to the USB-TTL and send data to the esp, it receives data. So pin 3 is clearly working, the SIM5320E is clearly working (confirmed with both pin 13 (D7) and the USB-TTL) but the combination pin 3 and SIM5320E does not work for some reason. I probably rather want to use pin 13 in the end but would really like to understand why this is not working :slight_smile:

Pinout:

which D1 is it? R1, R2, mini? all have pins marked Dn where n is not the number of the esp8266 pin so you should use Dn in the sketch

sorry for being vague, it's the mini, just updated the question. Thanks for the tip with the Dn reference, didn't know that.

maybe the on-board USB chip interferes

Here's a guide to using Serial & Serial1 on esp8266. It refers to the GPIO pin numbers, not the physical pin numbers or the Dn pin numbers marked on wemos D1 mini.

http://arduino.esp8266.com/Arduino/versions/2.1.0-rc2/doc/reference.html#serial

@PaulRB do you see something wrong how Serials is used in OP's sketch? because I don't. I already checked the doc as I guess OP did too, because that is the only source for knowledge about swap

No, I can't see anything wrong in the sketch. Need to see the schematic.

Well there is uart.c & uart.cpp, but the OP doesn't have any issue when the pins are swapped, right ?
you comment out

  Serial.swap();

when you want to receive on GPIO3 (marked RX on the PCB)
So i don't think it has anything to do with that, but rather that the logic-level might not be sufficient. I have experienced on nodeMUC's repeatedly that a 5v logic level through a (2/3) voltage divider doesn't work for reception on the RX pin, where it does on GPIO13 (using swap() )
Now i am guessing that the SIM is powered with something in the order of 4v, which would mean you normally speaking should reduce the logic level a bit, have you done that ?
Personally i would consider to run it though a 74HC04 (though 2 gates) powered at 3.3v to make sure you should have nearly 3.3v logic levels.
When i encountered it with communication between an UNO & nodeMCU i just connected the RX straight to the UNO's TX, and that worked.

Thank you for the guide :slight_smile:

No the issue only occur without using swap, using pin 3.
The sim-module is powered over usb (tried both a powerbank and usb in the computer).
Will try to power it over the pins instead.
Are you saying that there is a built in voltage divider on the RX pin but not on pin 13?

You're suggesting the 74HC04 as to get a higher (3.3V) logic level? The inverting of the signal is only a byproduct that does not matter?

well yes the inverting needs to be corrected, so you run the signal through 2 gates and it will be what it was before.

Ah the sim has USB ?

I suspect there is something, and there is at least a 470R resistor between the CH340 TX & ESP RX (pin 3) considering that the CH340 probably sets the TX LOW when it is not in use, there is (some) influence.
(if it would set it HIGH there would also be influence)
The 470R resistor would already explain why a 5v logic through a (1K-1K-1k) voltage divider won't work on the RX pin, If the output from a the sim would be an open collector with a pullup, that would interfere significantly.
The schematic of the SIM should clarify things, but a 3.3v powered 74HC04 where you pass the signal through 2 gates, should fix the issue. The logic level may already be correct, but the 470R resistor can cause issues if combined with other pullups or pull-downs or dividers.

Yes, the sim has usb.
Thanks for clarifying things. A 74HC04 seem to be the way to go.

Oh eh, i would check on the logic levels of the SIM though... You may need to reduce it. As the ESP may well deal fairly gracefully with voltages above it's 3.3v Vcc, I am pretty sure that 74HC04 doesn't, and it does respond to much lower levels. You will only be able to check them using an oscilloscope though since you can't just set the Sim's TX pin HIGH as you can on on the ESP.

Ok, thank you, will keep that in mind.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.