Photon connected via Uart to 5V sensor

Hey,
so I want to use a photon to talk via UART (using Serial1 on the photon) with my sensor, which is on a 5V level logic.
After reading that the photon is mostly on all pins 5V tolerant I just went for direct connecting the sensor -> without any luck. I am analysing tx and rx line with a logic analyser. The sensor is not replying as hoped. The logic analyser says it has frame errors on the tx line. I guess that the sensor is cmos technology and therefore the high logic level threshold is somewhere at 3.5V.
I then decide to go with a logic converter (logic-converter .
Unfortunatly I still have the same problem.
This is my testing code:

String sendData;

// setup() runs once, when the device is first turned on.
void setup() {
  Serial.begin();
  Serial1.begin(9600);
}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
  get_info();
  delay(10000);
}

void get_info(){
  byte out[5];
  out[0]=0x72; //STX
  out[1]=0x05; //Length
  out[2]=0xEE; //Sensor ID
  out[3]=0x03; //Request Type
  //out[4]=0x00; //Request Data
  out[4]=0x68; //Checksum
  Serial1.write(out, 5);
  Serial1.flush();
}

I tested my code with an old arduino uno which is 5V logic level and it worked right away. Are there maybe some pullups or anything else on the uart pins of the photon.
Any suggestions?

Thanks
Greetings

Just to clarify the obvious: You do have RX and TX crossed between the Photon and the sensor and also have shared GND between both, right?

I usually don’t have issues with direct UART communications between a Photon and 5V devices but when having two devices each living at the far and opposite ends of the tolerance bands it surely can fail.

1 Like

Hey,
yes I have them crossed, (i also tried changing them just to be sure). GND is shared.

Here is the logic analyser output when using the particle:

Here when using the arduino:

Somehow the sensor is not answering the uart. One the logic analyser I have changed the threshold levels to (L<1.4V and H>3.6V).
Same code on both boards, nothing else is connected.

That’s odd, particularly when also using the level shifter.
How have you wired that in?

Here the setup:

So what I also discovered:
When only connecting the particle to the level shifter. LV1 and LV2 are both 3.3V as expected due to the pullups on the level shifter which is working like:
image
But when I only connect the sensor without the particle to the level shifter. HV1 and HV2 are not 5V but 1.25V. But they should defenitly be 5V for it to work.
Any idea where the 1.25V come from? A pulldown of 3.3k would lead to such voltage (because the level shifter has a 10k pullup). But when measuring for resistance of the tx and rx cable in respect to gnd (just the sensor wires, not connected to anything), i am not measuring any resistance (i measured till 200k, and didnt measure anything).

I now realise that this is a dedicated I2C level converter and not a bidirectional level shifter.
I2C works by actively pulling low while letting the high level be dictated by the pull-ups when both the master and slave(s) let go of the line.

For UART you’d rather want a bidirectional level shifter that actively drives the line high and actively pulls low.

BTW, since the Photon’s RX pin is 5V tolerant you can get by with a simple transistor level shifter on the TX line to boost the voltage over the needed threshold.

hmmm, makes sense.
But the same logic level schematics is used by Sparkfun and in their tutorial they are doing uart with it.

I will try the transistor approach

What sensor are you using?

I am using a pressure sensor from grundfos.
It is called RPS and has an analog output as well as a digital uart one.

I was thinking a bit about what you said about the level converter havin pullups. I found out that the sensor is ttl not cmos. So 3.3V shall work. Looking back at the logic analyser graphs, the RX line is low. But it should be high, because a transition from high to low will indicate a start bit. If compared to the logic analyser graph with the arduino, the RX line is high during idle. I added a pullup on the rx line, but without any success. Are their any more differences then the voltage between the uart interface of the photon and a conventional arduino uno? It is push pull on the photon? When measuring the open rx tx lines from the arduino vs the photon - both lines of the arduino are high, but on the photon only the tx line. Maybe that is the problem

Not any I’m aware of.
But you could try having the Uno and the Photon communicate and log that communication with you LA and see whether this reveals anything.

Are you sure you dont need a CR or LF or both at the end of your data your sending?

Hey, yes i am pretty confident it is not needed. I have tested it on an arduino and it worked.
The protocol of grundfos consists of a starting byte and a set length, so no cr or lf is needed.

I found some more informations on the sensor:

The sensor can be used as analog or digital on the same line. To achieve this it locks the digital. To unlock it you have to force the rx line to 5v. The arduino is doing that. The problem with the logic level shift is the 10k pullup on the 5v rail, which is not capable of forcing the line to 5V. The arduino is forcing the tx line without pullup, with directly connecting it to 5v. With the used logiclevel shifter this is not possible. So a different approch on shifting the 3.3 to 5v is necessary, where the 5V can be force without pullup but with directly connecting it to 5V. Any suggestions?

Thanks

Hey,
so I got it to work.
As the sensor has an own pulldown resistor of 3.3k. After exchanging the pullups from the levelshifter with 470ohm, the sensor now works.
The peculiar thing is that it works with the photon, but not with the e series.
I use the same hardware, the same code (on the e series I use Serial4, on the photon Serial1). As I understand the datasheet both are 5V tolerant on those pins, right? Any other reason why this could be?

Thanks