serin/hserin fail when i break the standard...


Closed Thread
Results 1 to 18 of 18
  1. #1

    Default serin/hserin fail when i break the standard...

    I'm trying to connect a 18f2550 to a serial modem (aka phone) problem being the voltage of its serial data is 3v not 5v..

    now the device is 5v tolerant and I can send data to it, a simple ATDT123 causes a dialling to occur, problem is I cant receive the ''ok'' that says its acknowledged the dial string.

    the 3v data is good enough to brightly illuminate an led (with series resistor!) so i have a good bit of juice, but like i say i cat 'see' it with the serial commands.

    any idea if one port would be better than another or some software trick, or am i really going to have to build a level shifter into this and increase the old component count?

  2. #2
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    have you got an external pullup on your receive pin on the pic. ?

    If the device is 5v tollerant it shouldnt be unhappy with that but maybe it cant take the PIC pin high enough without some help. It shouldnt have any problem dragging it down to ground.
    Keith

    www.diyha.co.uk
    www.kat5.tv

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    If you have a Hardware COMPARATOR on the PIC, put your 3v SERIAL into one pin, set a low voltage Reference - say around 1v-2v (using the conveniently provided Voltage Reference Module of the PIC), and cross-connect the Hardware OUTPUT of the Comparator to either your USART input on the PIC or your chosen PIC pin for ASYNC Comms.

    Hey presto... you have your very own personal Voltage Convertor... and other than the software initialisation at the start of your program, no further software is required - so won't affect any critical timekeeping or interrupts or anything.

    What's even better, you can INVERT the Comparators output simply in SOFTWARE by setting the appropriate Register Bit... so you also have your own programmable HARDWARE INVERTOR... throw your MAX232 in the bin - your PIC (if it has Comparators) has one BUILT IN!!!!

    And if anyone is still using MAX232's for INPUT to a PIC... why??? The chances are if your PIC has a USART (like the 16F628), then it's probably got COMPARATORS too... so use them!

    Remember... your COMPARATOR's OUTPUT will swing 0v-Vdd (ie 0-5v on a 5v PIC) as long as the INPUT to the comparator reaches or exceeds the REFERENCE VOLTAGE. So if you have SERIAL Comms at say 15mV out of a Radio Receiver... feed it STRAIGHT into your Comparator, set the Reference to 10mV and suddenly you've got an amplified 0-5v SERIAL appearing on the Comparators Hardware OUTPUT pin.

    C'mon... if you've got a COMPARATOR you can rule the world!!!....
    Last edited by Melanie; - 25th March 2010 at 13:12.

  4. #4
    Join Date
    Aug 2008
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by f_lez View Post
    I'm trying to connect a 18f2550 to a serial modem (aka phone) problem being the voltage of its serial data is 3v not 5v..

    now the device is 5v tolerant and I can send data to it, a simple ATDT123 causes a dialling to occur, problem is I cant receive the ''ok'' that says its acknowledged the dial string.

    the 3v data is good enough to brightly illuminate an led (with series resistor!) so i have a good bit of juice, but like i say i cat 'see' it with the serial commands.

    any idea if one port would be better than another or some software trick, or am i really going to have to build a level shifter into this and increase the old component count?
    Are you running the PIC at 3 volts?

    Before you go to all of the hardware trouble it might be a good idea to post your code and configs.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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 13:52.

  7. #7
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    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.
    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

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  9. #9


    Did you find this post helpful? Yes | No

    Default

    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

  10. #10
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    What do you get with: serin portb.7,T9600,tempx,tempy
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  11. #11


    Did you find this post helpful? Yes | No

    Default

    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

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This is what you need with a 4MHz external
    Code:
    DEFINE OSC 48
    @ __CONFIG   _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @ __CONFIG   _CONFIG1H, _FOSC_HSPLL_HS_1H
    @ __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
    @ __CONFIG    _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H 
    @ __CONFIG    _CONFIG4L, _LVP_OFF_4L & _ICPRT_OFF_4L &_XINST_OFF_4L
    Dave
    Always wear safety glasses while programming.

  13. #13


    Did you find this post helpful? Yes | No

    Default

    thanks, i'll try that in the morning and report back, my net connections up at the moment! if its still up ion the morning i'll post pics off the scope etc of the data to from the gsm modem/phone.

  14. #14


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    This is what you need with a 4MHz external
    Code:
    DEFINE OSC 48
    @ __CONFIG   _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @ __CONFIG   _CONFIG1H, _FOSC_HSPLL_HS_1H
    @ __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
    @ __CONFIG    _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H 
    @ __CONFIG    _CONFIG4L, _LVP_OFF_4L & _ICPRT_OFF_4L &_XINST_OFF_4L

    Ok been away from this for a few days, sanity protection etc...

    tried that in my 18f2550.inc, all worked except for icprt_off_4l was causing an error, so i will leave that bit out for now.

    Am i right in the assumption if i want to also try with a 20mhz crystal then only thing i need change is the plldiv to a 5, and leaving cpudiv as is will still then give me 48mhz clocking?

    I have acquired a USB/rs232 dongle from the usual chinese supplys on ebay, I thought it would be pl2303 based inside but its a full 3 chipset device, so looks very reliable, made by targus, app not windows 7 compat, but on xp so...

    Anyhow, by plugging this in the folowing manner

    usb<----targus232-----<---max232----sniffer wire and spare tx wire

    by doing the above and setting xp's device mangler to 9600, i can see on my scope signals fro the targus are very like what i get from the 18f2550, by connecting the 'sniffer wire' to the 18f2550, i can see data from the pic, if i incorrectly set the targus, i dont, so the fail proves that its not autobauding and that when it receives char's at a displayed 9600, it really is 9600

    so, looks like the pic is tx'ing correctly, and i with the sniffer wire i can see when i connect the 'gsm unit' to the pic, and tell it to 'atdt123' that it replies with 'atdt123' (echo must be on) then after a pause it sends 'no carrier'

    I can not seem to receive the 'no carrier' with the pic, but the sniffer wire proves its being sent back, and at the same data rate, ie 9600

    so as i have no hadshaking, either i am misisng the window of opportunity, which i doubt as i have about 3 seconds to prep for it, or the 3v logic is too low to trigger hserin

  15. #15


    Did you find this post helpful? Yes | No

    Default

    Ok I have a small amount of progress...


    I have managed to receive a single char!

    I did this by connecting the pic to the max232 to the 232/usb dongle and using a comms app....

    I got the pic to wait for the char and output its binary value on portb, sure enough, 65 for an A

    Problem.....

    if i send 'A' then it works, if I send AA or AAA it works, but if I send AAAA ith receives the A and display 65, then goes deaf on me and recieves nothing after that.

    buffer overflow and then stalled?

    program still running, but it goes deaf as a post, 4 chars and deafness.

    It even seems to receive from the 3v gsm unit but says char received is 0, when it should be 'N', and then it goes deaf, no doubt as 'no carrier' is more than 4 chars as above.

    surely theres a simple way to resolve this ?

    I have set the buffer flag to clear over runs etc, and I read I have a 2 byte buffer, so do 2 hserins before i start the loop each time to clear it, I thought that would be enough....

    if i can stop it choking, then i can just leave it running in a loop echoing back allowing me to investigate the probably 3v/5 issue, although using the max232 i dont have that issue at the moment

  16. #16
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Try adding this after the HSERIN
    Code:
    RCSTA.4 = 0 : RCSTA.4 = 1
    Dave
    Always wear safety glasses while programming.

  17. #17


    Did you find this post helpful? Yes | No

    Default

    actually i think i have found an answer, may not be right one, gonna do some testing, but will try that too.

    one thing i can say, it works with 3v serial, infact i'm at about 2.8v, and its stable.

  18. #18


    Did you find this post helpful? Yes | No

    Default

    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 225 ' 9600 Baud @ 48MHz, 0,0%
    SPBRGH = 4
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

    the above lines cured all my serial in problems.

    I think the last 3 were the important bits, but now when the buffer fills it just ignores extra chars etc, no more ''going deaf''

    using them with

    Code:
            __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
            __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
            __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
            __CONFIG    _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_ON_3H
            __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    And a 20mhz crystal gives trouble free operation to the phone/module, and no issue with the 3v signals.

    I had to remove the resistor/led combination from the rx pin, it was loading the module a little and dropping its voltage down too low to be seen by the pic, but with a direct connection transfers have been error free. (measured on voltmeter as 2.8v, 2.75 and bits go missing...)


    Thanks to everyone for there input and ideas, I dont know where I would have been without you all this last few weeks!

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts