weird RS232 problem......


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2012
    Posts
    3

    Default weird RS232 problem......

    Ok everyone....I have spent many hours trying to figure this out. I am trying to talk to an Entertron PLC through a 18F4550 PIC. I have the serial routine working through a terminal emulator with no problems @ all. But when I connect it to the PLC its not working right. The PLC is receiving commands (the PLC goes into stop mode) but when it sends the "K" back as an acknowledge...the 18F4550 does not receive it (although monitoring the comm between the PLC and PIC.....the PLC is sending back the "K") So the term emulator works throught the routine with out a problem but the PLC will not. Has me stumped........David


    Code:
    	Define	OSC	20	' 20 MHz oscillator
    	
    	RCSTA = %00000000
    	BAUDCON = %01000000
    	ADCON1 = 15		' All I/O pins digital
    	   Pause 100
    	   
    	   
    	   
     pause 3000
        :STPCMD
        HIGH PORTD.0
            PAUSE   10
        LOW PORTD.0
        
        Serout2 PORTC.6, 84, [$1B,"S",$d]  'SEND STOP COMMAND S
        SERIN2  PORTC.7, 84, 1000, STPCMD,[WAIT ("K")]
         HIGH   PORTD.1
         
        :DWNLDCMD 
        HIGH PORTD.0
            PAUSE   10
        LOW PORTD.0
        Serout2 PORTC.6, 84, [$1B,"D",$d]  'SEND STOP COMMAND S
        SERIN2  PORTC.7, 84, 1000, DWNLDCMD,[WAIT ("K")]
         HIGH   PORTD.2
    
    
    'SEND OUT CONFIG REGISTERS FOR TROUBLESHOOTING 
        Serout2 PORTC.6, 84, [$d]  
        Serout2 PORTC.6, 84, [".......BIT7^..BIT0^",$d]  
        Serout2 PORTC.6, 84, ["TXSTA......",BIN TXSTA,$d]  
        Serout2 PORTC.6, 84, ["RXSTA......",BIN RCSTA,$d]  
        Serout2 PORTC.6, 84, ["BAUDCON....",BIN BAUDCON,$d]  
        Serout2 PORTC.6, 84, ["OSCTUNE....",BIN OSCTUNE,$d]  
        Serout2 PORTC.6, 84, ["OSCCON.....",BIN OSCCON,$d]  
        Serout2 PORTC.6, 84, ["PORTC......",BIN PORTC,$d]  
        Serout2 PORTC.6, 84, ["LATC.......",BIN LATC,$d]  
        Serout2 PORTC.6, 84, ["TRISC......",BIN TRISC,$d]  
        Serout2 PORTC.6, 84, ["UCON.......",BIN UCON,$d]
       
        
        
        
        Serout2 PORTC.6, 84, ["HAVE A NICE DAY !",$d]  
        
        STOP

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521

    Default Re: weird RS232 problem......

    Hi David,
    Do you have a link to the PLC in question and/or its documentation?
    If you know that the PLC does indeed respond with the 'K' then about the only thing I can think of is that the PLC responds so fast that the PIC doesn't have enough time to "setup" the SERIN command - by the time its ready to receive the 'K' may already be partly sent. I see you're running at 20MHz so I admit I'd be a bit surprised if it doesn't but it's a thought.

    You could try to

    I feel there might be some confusion. SEROUT2/SERIN2 are bit-banged serial routines, they don't use the USART in the PIC. You're using PortC.6 and PortC.7 (which are the USART pins) and you're setting registers associated with the USART as if the USART was being used for the serial communication - when using SEROUT2 etc it's not. If you're intending to use the USART then the commands to look for are HSEROUT/HSERIN

    Also, what's this?
    Code:
     pause 3000
        :STPCMD
    Shouldn't the colon be after the label (STPCMD:) ? Same thing with WNLDCMD (EDIT: Stupid forum, that should read colon DWNLDCMD, not a smiley...)
    I'd expect that to not compile without errors but apparently it does...

    /Henrik.

  3. #3
    Join Date
    Mar 2012
    Posts
    3

    Default Re: weird RS232 problem......

    Henrick,

    That fixed it ! I really appreciate the help.....I have 100+ hours into this programming and was stumped. I like to try and figure things out myself but it was getting frustrating. I have used the software serial commands before and had never used the hardware.


    I am using an Entertron Smart Pak PLC http://www.entertron.com/smart-pak.htm


    I am actually trying to make a SD card downloader for ladder programs and also a datalogger with the SD card.

    I am using a USB/RS232/SD card from olimex https://www.olimex.com/Products/PIC/...t/PIC-USB-STK/


    Henrick....once again thank you very much. I work for entertron and if you are ever looking for a PLC to play around with let me know.

    Thanks,
    David

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521

    Default Re: weird RS232 problem......

    Hi David,
    Great news! May I ask what exactly fixed it, did you switch to HSEROUT/HSERIN?

    Reading my own post it doesn't make sense to me as there seems to be something missing. It looks like I had an idea for you to try but never told you what it was... Oh well, it was early in the morning ;-) Anyway, I'm glad it's working for you.

    I'll check the Entertron website!

    /Henrik.

  5. #5
    allen05's Avatar
    allen05 Guest

    Default Re: weird RS232 problem......

    I built three 7-foot diameter light displays using 7W incandescent bulbs, but I find them too unwieldly for making program changes in my PIC. I thought I would build a small 10" diameter display using LEDs and the same connectors and PCB (with my PIC on it) as I am for the large display. This is do-able, all I need is 96 LEDs in 4 different colors with maybe some transistors for boosting power.

    HOWEVER, I once saw a circuit simulation where "software" LEDS could be lit based on the circuit drawn in the simulator. Is there a software simulator that I could just draw my 96 LEDs out, then feed it the code from my PIC?

Similar Threads

  1. Weird Random problem
    By Del Tapparo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th August 2012, 22:06
  2. weird pulsout problem
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th January 2012, 19:39
  3. Weird code problem
    By Navaidstech in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th March 2009, 11:16
  4. Weird Problem
    By isaac in forum General
    Replies: 9
    Last Post: - 22nd September 2008, 19:30
  5. PIC18F got some weird problem?
    By NatureTech in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 19th February 2007, 16:18

Members who have read this thread : 1

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

Posting Permissions

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