PIC UART Level Issue - Page 1
Forum section: electronics / general

author: Joseph1
author_rank: Contributor
timestamp: October 08, 2021, 12:32:46 am
content: Want to connect PIC 16F628A directly to SIM800L (without any level converters) as in the schematic. The design works @ home, but in site condition it wont work.All the trouble comes in SIM800L Transmitt path (When GSM modules recieves a call & SMS) in site condition the PIC won't recieve data properly.But when PIC transmit data (send call, send sms) it works nicely.I have attached voltage levels of both PIC & SIM800L modules.Are those levels matching?

author: jpanhalt
author_rank: Super Contributor
timestamp: October 08, 2021, 10:13:05 am
content: Welcome to EEVBlogAt what voltage are you running the 16F628A? If 5V, then 0.8VDD = 4V for hi (see DO41), so there may be a problem with that. The 628A will operate at lower voltages, but at 3V its maximum operating frequency is lower. Newer chips are available that operate fully at 3.3V and would require little, if any additional programming. Although, I don't know (doubt) there is a pin compatible version.

author: JPortici
author_rank: Super Contributor
timestamp: October 08, 2021, 11:26:08 am
content: It's 3.3V nominal, he already posted the same question in the microchip forum.Have you (OP) tried looking at the data with an oscilloscope? In any case there is little margin for it to work, i would rather put a level translator (it can be as simple as two resistors and a mosfet)

author: Joseph1
author_rank: Contributor
timestamp: October 09, 2021, 02:53:14 am
content: Thanks both of you.My supply voltage for PIC is 3V3. After reading the comments I planned to change the design to power the PIC from 5V & add a level shifer.Quote from: JPortici on October 08, 2021, 11:26:08 amYou got it.My design is in marginal level.I guess that's why its why it is not working in noise environments.I planned to add a level shifter & check.Here is my drawing.How can I supply the low side Voltage for the level shifter? What voltage need & do I need another regulator for that?

author: MIS42N
author_rank: Frequent Contributor
timestamp: October 09, 2021, 05:09:57 am
content: I think your original scheme should work. The Voh output is minimum 2.7V, The required input to the 628A is 2.64V. Close but still within specification. If noise is your problem it is probably the earth connection between the two chips. It is better to fix that than redesign.If you do want to redesign, this might be useful. Many years ago, I made a Sidereal clock.http://www.cashin.net/sidereal/circuit.html, it shows how I used the 2N7000.Most device outputs are capable of sourcing and sinking current, so you shouldn't need a pull up resistor on low side. The gate voltage has to be a similar level to the low side high signal, so the 2N7000 is not conducting. This has to be balanced against the need to conduct with gate to low side low turning it on. You could determine it by experiment, but I would go for a gate voltage of 3.3V or thereabouts. You could provide it by a divider off the 5V rail and a bypass capacitor, the gate doesn't draw significant current.Unfortunately, the 628A USART input doesn't have a weak pullup. In my circuit one of the outputs (the 1pps signal) goes to a pin that does have a weak pullup, so no additional pullup was required.If you feel like doing something weird and had spare I/O pins, you could set up a comparator with input from the SIM800L and a reference voltage of say 2V, and send the comparator output to a pin which is connected to the RX pin. Get your level shift for free.

author: mikerj
author_rank: Super Contributor
timestamp: October 09, 2021, 09:33:57 am
content: Quote from: MIS42N on October 09, 2021, 05:09:57 amNoise is a fact of life, and with such little noise margin the design can be expected to be unreliable.

author: MIS42N
author_rank: Frequent Contributor
timestamp: October 09, 2021, 08:43:18 pm
content: Quote from: mikerj on October 09, 2021, 09:33:57 amIf designers had that attitude, HiFi amplifiers wouldn't exist. If the margin was microvolts, then it's challenging. 60mV not so hard. It's a schmitt trigger input so should have good noise immunity.

author: Joseph1
author_rank: Contributor
timestamp: October 10, 2021, 02:27:39 am
content: Quote from: MIS42N on October 09, 2021, 05:09:57 amExcellant clear reply.You got it.After failing many times I redesigned the PCB layout as in the original schematic.The problems came down to half way mark.I think there is a long routed ground path issues (I don't know that).But further I want to clear all customer complaints (Again Not working....) by adding a level shifter.Because sometimes this unit has to place nearby RF panels, low GSM signal areas etc...So the pcb signal path has to be super steady in any environment.I have attached the new schematic.See how it looks likes.It is nice that I can form a divider voltage from a normal 7805 rather than GSM supply voltage (4.2V).Because When GSM signal recieving, the buck converter voltage fluctuates due to drawing large currents that can misbehaves the FET gate voltage.

author: Joseph1
author_rank: Contributor
timestamp: October 11, 2021, 05:39:08 am
content: A small doubt regarding choosing the level shifter transistor.Can this 2N7000 operates from 2.7V? Is its Vgs is can be low as that? I don't have BSS138.

author: jpanhalt
author_rank: Super Contributor
timestamp: October 11, 2021, 08:48:19 am
content: Its gate threshold is nominally 2.1V but it can be as high as 3V.

author: Joseph1
author_rank: Contributor
timestamp: October 11, 2021, 09:20:21 am
content: Ok.My divider resistors generates 2.7V for gate, is it work reliably or need to up the gate voltage level to 3V ?

author: jpanhalt
author_rank: Super Contributor
timestamp: October 11, 2021, 09:37:29 am
content: In my view, any project that depends on selecting components from a batch with certain characteristics is asking to be redesigned.Have you considered conventional level shifters:Microchip:http://ww1.microchip.com/downloads/en/DeviceDoc/chapter%208.pdfTI:http://www.ti.com/lit/sg/scyb018f/scyb018f.pdfN-channel bidirectional mosfet:Philips 1997 (secondary site):http://www.adafruit.com/datasheets/an97055.pdfNXP 2007https://www.nxp.com/docs/en/application-note/AN10441.pdfSparkfun board and schematic:https://learn.sparkfun.com/tutorials/bi-directional-logic-level-converter-hookup-guideThat is just copy and pasted from my files. The NXP reference is often cited.

author: Joseph1
author_rank: Contributor
timestamp: October 13, 2021, 09:43:59 am
content: Hi All.I made the following circuit with added FET level converter for UART. But the results are worst.Earlier when I lower the PIC supply voltage to 3V3 & directly drive the SIM800L it works nicely (even though it is in marginal).But with the new modification the data is coming weirdly. Sometimes coming & sometimes it takes time to come.

author: jpanhalt
author_rank: Super Contributor
timestamp: October 13, 2021, 10:09:32 am
content: Have you looked at the input signal to the PIC? Here's the recommended level shifter (source:https://www.gme.cz/data/attachments/dsh.775-083.1.pdf,page 31).Why not use it?

author: Joseph1
author_rank: Contributor
timestamp: October 13, 2021, 11:08:38 am
content: Quote from: jpanhalt on October 13, 2021, 10:09:32 amIts hard to find SMD unfamiliar Transistors.I am not sure it can be done using commonly available 2N2222 part....!!!

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 13, 2021, 05:31:15 pm
content: It should work with pretty much any NPN transistor here.

author: MIS42N
author_rank: Frequent Contributor
timestamp: October 13, 2021, 09:07:14 pm
content: I don't think you mentioned what baud rate you are using. It should be the lowest rate that gets the job done. Although speeds of 115,200 work, the faster they are the less tolerant to external interference. Also some high baud rates are hard to match with the processor clock, so there is a residual speed error. Up to 2% is OK, over 5% things stop working. And I did recommend 3.3V for the gate, the 2N7000 should be off with less than 0.7V, but on can be as high as 3V. There is no need to use a FET, the advantage they have is they are bidirectional.

author: Joseph1
author_rank: Contributor
timestamp: October 13, 2021, 11:42:43 pm
content: Quote from: MIS42N on October 13, 2021, 09:07:14 pmThanks.I am using 9600bps.Just thinking what to do.Do some experiments with FET thing (increase gate voltage etc...) or Just stick with direct connection method..!!

author: MIS42N
author_rank: Frequent Contributor
timestamp: October 14, 2021, 08:54:10 am
content: Quote from: Joseph1 on October 13, 2021, 11:42:43 pmYou didn't say if you have an oscilloscope. If you are using one of the cheap 3A buck converters, their output is quite noisy when the current draw is small. You should look there. You don't show any additional bypass capacitors on the SIM800L supply, it may pay to put more capacitance there, low ESR electrolytic and a ceramic. It seems people do have trouble with the power supply because of the very short 2A bursts of current. Also need a bypass on the FET gate to GND. You may have one but don't show it.

author: DavidAlfa
author_rank: Super Contributor
timestamp: October 14, 2021, 11:48:53 pm
content: If your application doesn't really need 20MHz to comply the requirements, easy fix, it's 4V for 16MHz and 3V for 10MHz. (Datasheet page 136)0.8x4VDD is 3.2V, still very close but might work. The best is to run it at 3.3V if possible.Of course, the rest of the circuitry should be capable of working at such voltage.Thats a prehistoric pic BTW.

author: Joseph1
author_rank: Contributor
timestamp: October 17, 2021, 04:05:50 pm
content: Quote from: MIS42N on October 14, 2021, 08:54:10 amYes I have an oscilloscope. BUt didn't try to capture some waveforms yet. I use cheap LM2596 buck modules Like these.https://www.amazon.com/Lysignal-LM2596-Supply-Adjustable-Converter/dp/B074J4NXCMI don't use any capacitors on the PCB except the 0.1uF ceramic cap to PIC micro.I guess the SIM800L modules have some 100uF cap & two ceramic caps on its board.DO I need additional caps for SIM800L module?https://www.amazon.com/DAOKI-SIM800L-MicroSIM-Quad-Band-3-7-4-2V/dp/B08212SNVQ/ref=sr_1_6?crid=13FM1A01M2P14&dchild=1&keywords=sim800l&qid=1634486701&s=electronics&sr=1-6

author: Joseph1
author_rank: Contributor
timestamp: October 17, 2021, 04:09:11 pm
content: Quote from: DavidAlfa on October 14, 2021, 11:48:53 pmFor 9600bps I'm using internal 4Mhz oscillator.I'm doing testing on my original design (the 3V3 version).Most tries are ok.But sometimes in the noisy environment it misses the incoming phone number captured by the PIC..!!

author: oPossum
author_rank: Super Contributor
timestamp: October 17, 2021, 04:55:08 pm
content: Are you using the hardware UART? If so, what is the baud rate generator configuration. I suspect you have a more than 7% error on the bit rate. Should be under 2% for reliable operation.

author: Joseph1
author_rank: Contributor
timestamp: October 17, 2021, 05:36:21 pm
content: Quote from: oPossum on October 17, 2021, 04:55:08 pmI use hardware UART.SPBRG =25(decimal)oscillator =4Mhz internal oscOn SIM800L Init I dont send any baudrate commands in power up sequence.(Using the factory default ones).