Melanie, I thought RS232 required negative voltage eg -12V? All this while I thought MAX232 is needed to generate +12V and -12V for the signalling.
Melanie, I thought RS232 required negative voltage eg -12V? All this while I thought MAX232 is needed to generate +12V and -12V for the signalling.
You can connect a PIC directly to RS232 (usually though a Resistor). The problem is YES it is inverted. For all intents and purposes a HIGH (say +12v) is ZERO, and a low (-12v) is a ONE. You can extend this by simply saying, that if it isn't a HIGH, then it's got to be a LOW. So again, if the signal is above 5v (ie it has swung to +12) the PIC will tollerate that (our Resistor helps) and Register a PIC LOGIC 1 (RS232=Zero), and if the swing goes to -12v, again our PIC doesn't care once it falls below 0v, because it registers a Logic 0 (RS232=1). So here +12/-12v is fine, just a Resistor and you're good to go.
If you use SOFTWARE ASYNC like SERIN, you do it simply by specifying that it is inverted and SERIN does the rest.
But if you use the HARDWARE USART, and HSERIN, there is no automatic way of inverting, so you need something like a MAX232 (or transistor or whatever) to HARDWARE INVERT the signal before you feed it into the PICs USART.
In this thread a 0v to +3v swing doesn't do it for the PIC running at 5v. 3v may or may not be sufficient to score a Logic 1 in the PIC. It's unreliable, and it looks like f-lez has a problem. But here is where the Comparator scores on TWO COUNTS. (1) it can RESTORE your 0-5v signal (from an input as little as only a few millivolts), and (2) it has the ability to INVERT the output for you (real convenient when you need to INVERT a signal for the USART).
The COMPARATOR won't give you +12/-12v for OUTPUT purposes, but it will take whatever cr*p you want to throw at it and give you clean Data with a nice solid 0-Vdd swing for the PIC to logically process thereafter. So treat the COMPARATOR as a LOGIC LEVEL SHIFTER, a DATA RESTORER, an INVERTOR, an AMPLIFYER, a NOISE FILTER... what more could you ask for? And you got it FREE all BUILT-IN to your PIC!
Last edited by Melanie; - 25th March 2010 at 14:52.
Except for the PIC18 chips by using RXDTP and TXCKP to invert your hardware UART.
See
http://www.picbasic.co.uk/forum/show...ight=inverting
By the way Melanie, your comparator solution is very slick! Thanks, I have a 3v to 5 volt issue I think I will use it on.
Thanks,
Walter
A lot of people miss this, but if you have an external 3V device, and it's not working on a
certain pin, make sure you're not using a pin with a Schmitt Trigger input buffer.
A pin with a TTL input buffer should work fine with the 3V input if VDD >= 4.5V and <= 5.5V.
A Schmitt Trigger input needs ~0.8 * VDD to meet the input logic 1 threshold.
The comparator trick is cool too, but you might fix it by just switching to a TTL input.
Ha ha some good ideas i like the comparator hack, i may have to try that as a test to see just if it is a level issue, as i would like to keep those pins free for the pwm.
Pic is 18f2550 so it has them, and I am running it at 5v, the phone/dsm module is 3v but 5v wont harm it.
I have tried input on both port b and C and tried with and without pullups enabled.
I will try the HW uart again with inverted as i am unsure of the stream polarity.
Heres the start of my code as a test etc and to show the configs I have
Code:;DEFINE RESET_ORG 800h ;DEFINE INTERRUPT_ORG 808h define OSC 48 ;dEFINE LOADER_USED 1 ; first four lines to fix broken pbp246 UIR VAR BYTE EXT UIE VAR BYTE EXT UEIE VAR BYTE EXT UEIR VAR BYTE EXT INCLUDE "MODEDEFS.BAS" include "c:\dtusbsvc.pbp" ' would not know what to do without them ! ' setup serial hardware comms DEFINE HSER_RCSTA 90h DEFINE HSER_TXSTA 20h ; try 24 if errors DEFINE HSER_BAUD 9600 DEFINE HSER_EVEN 1 DEFINE CHAR_PACING 1000 ' slow things a little DEFINE HSER_CLOERR 1 ' automatic clear overrun error ' DEFINE HSER_SPBRG 25 ' let picbasic set it from the baud def above DEFINE ADC_CLOCK 1 DEFINE ADC_BITS 8 DEFINE ADC_SAMPLEUS 10 ADCON1 = %10000011 ; not sure lol CMCON = 7 ' Disable Comparators INTCON2.7 = 0 ; should enable portb pullups. TRISA = 3 ; configure AN0 an1 as an input trisb = 255 trisc=255 tempx var byte ; temps.. tempy var byte ; temps.. loop: hserout ["atd123",13,10] for tempx=1 to 2 ; look for 2 chars from it for ''ok'' serin portb.7,n9600,10,tlable,tempy tlable: ; gosub send tempy to usb to pc terminal next goto loop
What do you get with: serin portb.7,T9600,tempx,tempy
OK its gone from bad to worse.....
On the downside my internet is down so I only have this mobile phone, but I have now dusted off my old dual trace scope...
What it Ias shown me is I seem to have a timing error...
I have changed from a 4 to a 20mhz crystal go case It was off freq.
I can't use the scope to check timing accuracy its very old and calibrated.
I can't cut and paste my configs now!
As a rule of thumb, if I use the right settings to clock the pic at 20mhz I would be right with pll/5 to be right for usb.
CAn I get a good 9600 set that way?
How many chars can be transferred in say 10 secs?
The scope shows returning data but it looks like the phone/modem. IS at a different speed
Bookmarks