Author Topic: PIC USART communication problem  (Read 21916 times)

0 Members and 1 Guest are viewing this topic.

Offline Skimask

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: PIC USART communication problem
« Reply #50 on: March 21, 2014, 10:23:24 am »
Easily fast enough for serial signals.
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC USART communication problem
« Reply #51 on: March 21, 2014, 11:00:07 am »
Quote
What would be the best way to boost up the 2.78 V signal from GSM?

Not sure about the best. The easiest would be to use a pull-up (=resistor + diode).
================================
https://dannyelectronics.wordpress.com/
 

Offline granz

  • Regular Contributor
  • *
  • Posts: 136
  • Country: us
  • 6.62606957
Re: PIC USART communication problem
« Reply #52 on: March 21, 2014, 02:23:55 pm »
Use a single transistor and two resistors.  See the attached image.  You don't have to use a 2N3904 specifically, any garden variety NPN transistor is fine.  Depending on how fast you want to run your serial connection, you may need to reduce the values of the resistors.  The values shown should be fine for 9600 or 19200 baud.

This will invert the signal into the PIC, so you'll need to change the bit in the UART register for active-high/active-low.

The resistor/diode level shifting methods are safe for high-output-to-low-input voltage shifting, but there isn't a safe way to do it low-output-to-high-input, you always have some small current flowing back into the low-voltage supply rail.  That is bad because the low-voltage supply can potentially charge up to a higher voltage (most regulators can only source current, not sink).  Also, the high value resistors used limit the speed.

Transistors are dirt cheap, no reason to not use them  :D

Good luck!
 

Offline wicketTopic starter

  • Contributor
  • Posts: 35
Re: PIC USART communication problem
« Reply #53 on: March 21, 2014, 03:02:08 pm »
I've managed to get it working @ 5 V using 2k pullup resistor, but there was indeed 0.5 mA flowing back into the GSM. I'm not sure if that's enough to damage something.

I'll try to use the transistor now and invert the logic on PIC.
 

Offline granz

  • Regular Contributor
  • *
  • Posts: 136
  • Country: us
  • 6.62606957
Re: PIC USART communication problem
« Reply #54 on: March 21, 2014, 03:12:19 pm »
I've managed to get it working @ 5 V using 2k pullup resistor, but there was indeed 0.5 mA flowing back into the GSM. I'm not sure if that's enough to damage something.

I'll try to use the transistor now and invert the logic on PIC.

The main issue is if the GSM phone goes into a low-power mode and requires less than the current flowing back into it on its supply rail.  Since the internal voltage regulator won't be able to sink the extra current, the internal supply voltage rail will rise up a higher voltage, which can damage things.  Since you are working with a "black box" (the phone) you really don't know what's going on inside it.

Edit: Also consider what happens when the battery is removed from the GSM phone: you then have current flowing into the phone's supply rail, but on the output side of the regulator, so the voltage can rise above the normal supply voltage.
« Last Edit: March 21, 2014, 03:16:32 pm by granz »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC USART communication problem
« Reply #55 on: March 21, 2014, 03:47:53 pm »
Quote
See the attached image.

That would require negative logic.

What's best is highly subjective. The pull-up idea is simple. But it may not work in all cases.

A more complex approach is to use a logic level mosfet (or bjt + diode). It has the advantage of being positive logic and bi-directional.
================================
https://dannyelectronics.wordpress.com/
 

Offline granz

  • Regular Contributor
  • *
  • Posts: 136
  • Country: us
  • 6.62606957
Re: PIC USART communication problem
« Reply #56 on: March 21, 2014, 03:52:59 pm »
Quote
See the attached image.

That would require negative logic.


Hence why I said to switch the bit in the PIC UART config register.

 

Offline wicketTopic starter

  • Contributor
  • Posts: 35
Re: PIC USART communication problem
« Reply #57 on: March 21, 2014, 04:21:42 pm »
Use a single transistor and two resistors.

Works like a charm!  :-+  I don't have any mosfets at home, so I'll stick to this for now.
 

Offline granz

  • Regular Contributor
  • *
  • Posts: 136
  • Country: us
  • 6.62606957
Re: PIC USART communication problem
« Reply #58 on: March 21, 2014, 04:26:13 pm »
Glad it's working and you can now move on to other (more interesting) things! :)

 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC USART communication problem
« Reply #59 on: March 21, 2014, 04:43:34 pm »
Here is a bjt - implementation of the phillips' bi-directional level shifter.

V1 is the signal to be transmitted and the pick up, in this case, is on the bjt's collector (or emitter in case the transmission is the other way around).

If you only care about 2.7v -> 5v transmission, you can eliminate R1 / D1. If you replace Q1 with a mosfet, you can eliminate R2.

I typically include them all in the layout but don't solder them in if the transmission is one directional.
================================
https://dannyelectronics.wordpress.com/
 

Offline granz

  • Regular Contributor
  • *
  • Posts: 136
  • Country: us
  • 6.62606957
Re: PIC USART communication problem
« Reply #60 on: March 21, 2014, 04:55:15 pm »
Also, if you aren't sure if the input (RX) on the GSM phone is really 5V tolerant, consider adding level shifting in the other direction as well.  In that case (5V down to 2.7V) at only 9600 baud a simple voltage divider will be fine.  Try a 1.8k + 2.2k to ground from the PIC TX line and take the output to the phone from the midpoint.  (2.2k+2.2k may be close enough, but the output will be a bit low).

If you aren't too concerned about damaging the input on the phone, you can just leave it alone, but two resistors is cheap insurance.

 

Offline granz

  • Regular Contributor
  • *
  • Posts: 136
  • Country: us
  • 6.62606957
Re: PIC USART communication problem
« Reply #61 on: March 21, 2014, 04:57:24 pm »
Here is a bjt - implementation of the phillips' bi-directional level shifter.

V1 is the signal to be transmitted and the pick up, in this case, is on the bjt's collector (or emitter in case the transmission is the other way around).

If you only care about 2.7v -> 5v transmission, you can eliminate R1 / D1. If you replace Q1 with a mosfet, you can eliminate R2.

I typically include them all in the layout but don't solder them in if the transmission is one directional.

Is a fine circuit for sure, but requires access to the 2.7V supply rail, which I don't believe is available outside the phone....
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC USART communication problem
« Reply #62 on: March 21, 2014, 05:05:37 pm »
You can simply pad up the output with a led (or diode string) and tie the base to the 5v rail.
================================
https://dannyelectronics.wordpress.com/
 

Offline granz

  • Regular Contributor
  • *
  • Posts: 136
  • Country: us
  • 6.62606957
Re: PIC USART communication problem
« Reply #63 on: March 21, 2014, 06:32:16 pm »
You can simply pad up the output with a led (or diode string) and tie the base to the 5v rail.

It is definitely a nice level shifter topography, I've used it for I2C level shifting.  I guess I just don't really see the advantage in this case if you add more components to drop down the 5V rail down to 2.7V.  Then you have to either string diodes together, or find an LED with the right forward drop after tweaking the current through it.

Actually, reading your sentence again, I'm not really sure what you mean "simply pad up the output with an led (or diode string)"?  Adding diodes on the collector side (5V side) will just shift the whole 2.7V waveform up by the diode drop.  Sure, he could reach the 4V high level required, but then the low level will be up above 1V which is required by the PIC (0.2*VCC for Schmitt Trigger inputs).  But perhaps I am misunderstanding what you mean.  Either way, I still posit that the inverting unidirectional shifter is the simplest for this application.

 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC USART communication problem
« Reply #64 on: March 21, 2014, 07:06:37 pm »
I would have simply used a pull-up resistor + diode, and call it a day.
================================
https://dannyelectronics.wordpress.com/
 

Offline granz

  • Regular Contributor
  • *
  • Posts: 136
  • Country: us
  • 6.62606957
Re: PIC USART communication problem
« Reply #65 on: March 21, 2014, 07:45:24 pm »
I would have simply used a pull-up resistor + diode, and call it a day.

I think you must be thinking of 5V to 2.7V translation, in which case a single diode+resistor is perfectly safe.

Show me how you would drive an input > 4V and < 1V from a 2.7V signal with a pull-up resistor and diode only, with no flowing current back into the 2.7V output.  You might as well just leave the diode out, and just use a pull-up resistor, as already discussed (not a great idea).

 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: PIC USART communication problem
« Reply #66 on: March 24, 2014, 02:25:38 am »
Maybe the modem echos commands sent to it?

You really need to hook this thing up to some terminal software so you can see exactly what is being sent by each side.
 

Offline wicketTopic starter

  • Contributor
  • Posts: 35
Re: PIC USART communication problem
« Reply #67 on: March 24, 2014, 09:01:21 am »



Is at displayed here because I typed it, or is it echoed back, how do I know that?
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: PIC USART communication problem
« Reply #68 on: March 24, 2014, 09:30:25 am »
Is at displayed here because I typed it, or is it echoed back, how do I know that?

You have "local echo" turned off, so the modem must be echoing it back.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf