Pic does not respond to SERIN: Serial I/O expander project


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2006
    Posts
    10

    Default Pic does not respond to SERIN: Serial I/O expander project

    Hello all,

    I've built the Serial I/O expander that is detailed here. The only difference in my circuit is that I'm using a Pic16f818 (what I had laying around) and am driving simple LEDs instead of relays. My problem is that I can't seem to talk to the pic via Hyperterminal or other PC serial terminal programs (for example the Serial Communicator within MCS). I have COM port pin 3 hooked up to RA4 via a 22k resistor and COM port pin5 hooked to ground. I'm setting up the terminal program as 8bit word, 2400baud, non-parity, 1 stop bit. I open up hyper terminal and type in 254,1,1 and get nothing. Not sure if it's an issue with syntax. I've tried the following...

    254,1,1
    254 1 1 1
    254:1:1
    25411

    I've added a few LED flashes before the loop in the program to ensure that the pic is alive and it is. I also added a quick flash at the end of Loop: so that I can see when/if the pic actually goes through this subroutine. From what I can see, it never does. It looks like it is just hanging on the Serin command.

    What am I missing. Really hoping this is something silly.

    best,
    Brad

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

    Default Re: Pic does not respond to SERIN: Serial I/O expander project

    Hi,
    I only took a quick a look at this but it seems to me that code expects to receive three bytes where the first one is 254. However, when you type in 254,1,1 in Hyperterminal it sends 7 bytes (50-53-52-44-49-44-49) which is the ASCII representation for the text you typed - it does not send the "raw" binary values you type.

    There is a way to send what you want with the serial terminal in MCS. Make sure that the option Parse Control Characters are activated then Type #254#1#1 and press send. Look in the Help for more info on that option.

    /Henrik.

  3. #3
    Join Date
    Feb 2006
    Posts
    10

    Default Re: Pic does not respond to SERIN: Serial I/O expander project

    Thanks Henrik,

    Yes, the program is expecting to see the qualifier 254 before the 2 bytes of data that it sticks into variables. I tried what you suggested and it didn't seem to work either.

    I setup a mirrored output by connecting the PC pin 2 (PC Serial Input) to PC pin 3 (PC Serial output) via a resistor so that I can see what I am sending down the line in a parsed format. When I entered #254 #1 #1 in the send window and sent it, I got a symbol that looked kind of like a lower case b and lower case p were getting it on (LOL). Not sure what that was. No LED flash so the PIC didn't get what it wanted.

    At this point, I've modified the code a bit to simplify it and flash an LED when any qualified serial message is received.

    Code:
    INCLUDE "bs2defs.bas"relay   VAR    b3 'relay number storage variable
    stat    VAR    b4 'relay status ON/OFF variable
    serpin  VAR    porta.4 'serial input pin
    trisa     =    010000
    trisb     =    000000
    
    
    High 0
    pause 100
    Low 0
    Pause 200
    High 0
    Pause 300
    Low 0
    
    
    loop:
      SERIN serpin,N2400,[254],relay,stat 'serial data in on PortA.4
      High 0
      pause 500
      low 0
      pause 200
      high 0
      pause 500
      low 0
      GOTO loop
    Seems to me I'm just not sending the right thing down the pipe. Any additional help would be greatly and sincerely appreciated.

    best,
    Brad

  4. #4

    Default Re: Pic does not respond to SERIN: Serial I/O expander project

    It looks like what would help you the most would be to use a terminal program that has hexidecimal send and receive options. For Windows I like to use realterm. It has a lot of different options for data formats and has a packet send function that transmits user defined blocks of data. You can find it at http://realterm.sourceforge.net/
    Last edited by falingtrea; - 22nd November 2011 at 18:44. Reason: spelling fix
    Tim Barr

  5. #5
    Join Date
    Feb 2006
    Posts
    10

    Default Re: Pic does not respond to SERIN: Serial I/O expander project

    Unfortunately, Realterm won't install on my Windows7 box at work. I may try to find an XP box to transfer to later today but it sure seems like there must be a way to do it in either Hyperterminal or MCS serial communicator.

    B

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

    Default Re: Pic does not respond to SERIN: Serial I/O expander project

    Hi,
    Did you try without the spaces, ie #254#1#1?

    If you created a loopback you should be able to see what you send - as long as you send normal ASCII text like you initially did. When you type 254 and press send you should see 254 being "looped back" but when type #254 and press send you should NOT expect to see 254 being looped back because now a single byte with the value of 254 gets sent and 254 is non standard ASCII code so you'll get a weird character on the screen.

    Try this with your loopback:
    1) Type ABCD then press send (or enter).
    2) Type #65#66#67#68 then press send (or enter).

    What do you see? Now Google for ASCII chart or look in the back of the PBP manual, what does 65 correspond to?

    If skipping the spaces doesn't work then try modifying your PIC code so that, instead of 254, it waits for 65 or "A". By now you'd know that they are exactly the same thing. The value 65 is the ASCII code for the letter A. When you type A and press send the PC sends one byte out, that byte contains the value 65 of which when looped back to the PC gets displayed as A because that what's the value 65 represents.

    /Henrik.

  7. #7
    Join Date
    Feb 2006
    Posts
    10

    Default Re: Pic does not respond to SERIN: Serial I/O expander project

    Great explanation Henrik, thanks. Sounds absolutely logical. Unfortunately... still not working.

    I've modified the code to look for 65 as you suggested (see below). When I type #65#49#49 (49 would be ASCII for the number 1 which I'd like loaded into each of the variables, though for this exercise it obviously doesn't matter much) I see A11 in the loopback window. But... nothing happening on the PIC. Hmmmm.....

    Code:
    INCLUDE "bs2defs.bas"relay   VAR	b3 'relay number storage variable
    stat    VAR	b4 'relay status ON/OFF variable
    serpin  VAR	porta.4 'serial input pin
    trisa 	=	%00010000
    trisb 	=	%00000000
    
    
    High 0
    pause 100
    Low 0
    Pause 200
    High 0
    Pause 300
    Low 0
    
    
    loop:
      SERIN serpin,N2400,[65],relay,stat 'serial data in on PortA.4
      High 0
      pause 500
      low 0
      pause 200
      high 0
      pause 500
      low 0
      GOTO loop

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

    Default Re: Pic does not respond to SERIN: Serial I/O expander project

    Hi,
    Currently I can only think of three things:

    1) I don't see a DEFINE OSC in your code - are you using 4Mhz?
    2) PortA.4 is multiplexed with AN4 (analog input). Try adding ADCON1=7 to enable the digital input buffers on ALL analog inputs.
    3) You have the code set for 2400 baud, did you set the terminal up for that as well?

    Like you say, for this exercise it doesn't matter (since the PIC doesn't react at all) but with #65#49#49 the variables won't be loaded with 1 but with 49 since that's what your sending. To load them with 1 you'd do #65#1#1.

    /Henrik.

  9. #9
    Join Date
    Feb 2006
    Posts
    10

    Default Re: Pic does not respond to SERIN: Serial I/O expander project

    Henrik!! Yes! Thank you! The ADCON1=7 addition did the trick.

    thank you so much, you turned a bad day that was getting worse into a good one!

    best,
    Brad

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