Strange problem with Serin/Serout on 16F628


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Location
    Florida, USA
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Bruce - Thanks for your reply. What you said is starting to make sense... For a ST pin to recognize input, it has to reach ~4V. For a TTL pin to recognize input, it has to only reach ~2V. Is that correct? So what you are saying is that in order to use a ST pin for serial input, the "signal" needs to be ~4+ Volts. And I am assuming that in most cases this would require a MAX232 to achieve those levels. Correct?

    OK, let's just forget about the input for the time being. Can I use a ST pin for TXmit without any problems? Right now, the program transmits (supposed to) the commands to start playing when it receives a trigger. Well, I don't seem to be able to do that either. Any thoughts?

    Here's my code:
    Code:
         INCLUDE "modedefs.bas" 'Needed for serial communication
    
    @ DEVICE HS_OSC              ; Hi Speed Osc  
    
        ADCON1 = 7          ' Set PortA Pins as I/O pins
        CMCON = 7
    
        Trigger     var PORTC.6
        PlayLED     var PORTD.1
    
        TXPin       var PORTA.2 'E.1
        RXPin       var PORTA.3 'E.2
        
        B0          var byte
        CR          CON 13       ' constant value of a carriage return
    
    '****************************************************************
    
        low playled
        
    '****************************************************************    
        PAUSE 3000                               'allow VMusic2 to initialize
        SEROUT txpin, T9600,["VST",CR]           'stop anything that's playing
        
    '****************************************************************
    Loop0:
        if trigger = 0 then goto loop0 'button is pulled low via 10K resistor
        
        high playled
        SEROUT txpin, T9600,["VPF file000.mp3",CR] 'Play a file named "file000.mp3"
        PAUSE 2000
        
        SERIN rxpin, T9600, [">"],B0 'Waits for ">" to indicate playing done
        low playled
        PAUSE 2000
        goto loop0
    
    end

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


    Did you find this post helpful? Yes | No

    Default

    Look in the Electrical Characteristics section of the PIC data sheet. Look under Input
    High Voltage. For a Schmitt Trigger type input you'll see something like 0.8 Vdd under
    the Min column with Vdd under the MAX column.

    What this means is; Minimum input that will be recognized as a logic 1 would be about
    0.8 times Vdd. The MAX input level of course should not exceed Vdd.

    Now look a bit farther to the right under Conditions. If this states "for entire Vdd range"
    then this means 0.8 times whatever voltage you're operating at, that is within the spec
    for Vdd, would be what you use for the input threshold calculation.

    I.E. if the PIC you're using can operate from say 4V to 5.5V, then you would use whatever
    Vdd is to figure this out.

    Let's assume you're using a 4V supply. 0.8 * 4V = 3.2V. This would be the minimum input
    level you need on the ST input to be recognized as a solid logic 1. This is the logic 1 input
    threshold level.

    Now look at the TTL input requirement. It may look something like this. Under the Min
    column it shows 2. Under the Max column it shows Vdd. To the right it may be something
    like 4.5V ≤ VDD ≤ 5.5V

    2V is the minimum input level that will be recognized as a logic 1. Vdd is of course the MAX.

    The 4.5V ≤ VDD ≤ 5.5V means (if Vdd is greater than or equal to 4.5V and less than or
    equal to 5.5V), then you're operating within spec.

    Output levels are also listed just below this section. A pin outputting a logic 1 will normally
    be Vdd-0.7V, which just means you can expect a drop of around 0.7V due to the output
    driver. If you're operating at 5V, then 5V-0.7V is what you can expect the output pin to
    deliver to the load.

    Can I use a ST pin for TXmit without any problems?
    Yep. ST only refers to input pins. The DC Characteristics section of the data sheet will
    show what you can expect for a drop in the output driver. Normally it's around Vdd-0.7,
    but it never hurts to check.
    Regards,

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

  3. #3
    Join Date
    Sep 2006
    Location
    Florida, USA
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Bruce - Thanks for your elegant explanation - I now perfectly understand the difference between ST and TTL level inputs. Nicely stated!

    And what you said about ST pins being used as xmit pins indicates that I should probably not have a problem doing that (I'm running at 5V, btw). Did you see any problem with my code as to why I don't seem to be transmitting to the player? Since I am not using a 232 chip, I am using the T9600 command (as opposed to the N9600 command). The Xmit and RCV pins (A.2 and A.3) are wired directly to the Xmit and RCV pins of the player. Should I be doing anything special with these connections? Like I said earlier, this works fine on my 628 board.

    I appreciate your help. I am at wits end - it just doesn't make sense... Thanks!

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


    Did you find this post helpful? Yes | No

    Default

    How do you know that you're not transmitting data to the player?

    Have you looked at the tx output with a scope? Have you tried inverted mode?

    Could be your player requires inverted serial. That would explain why it isn't responding.

    Edit: You show @ DEVICE HS_OSC but you don't show any DEFINE OSC. If you're using
    anything other than 4MHz, you'll want to define that oscillator speed. PBP assumes 4MHz
    unless you specify otherwise, and that will for sure screw-the-pooch with timing if you're
    not using a 4MHz osc. If you are using a 4MHz osc, you may want to switch to @ DEVICE
    XT_OSC so you're not over-driving your 4MHz osc.
    Last edited by Bruce; - 21st August 2008 at 22:06.
    Regards,

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

  5. #5
    Join Date
    Sep 2006
    Location
    Florida, USA
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Bruce - When it gets the valid command to play the sound clip, it plays. There is a status LED on the player that flashes when it gets the comand. It does not do that. I can take this player off the 877 board and can put it on the 628 board running the same code and it works fine. The only difference is that I am using A.3 and A.4 on the 877 for communication and B.6 and B.7 on the 628 board. Everything else is the same. That is what is so frustrating - it's like rotating your tires and now your car won't start. Rotate them back and everything works fine! Makes no sense!

    Thanks again for all your help!

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


    Did you find this post helpful? Yes | No

    Default

    Interesting problem. You seem to have everything configured OK for A/D & comparators off
    with ADCON1 = 7 & CMCON = 7. Have you verified the PIC is even running by blinking an LED?

    Edit: hold the phone. Your code indicates you're using A2 for TX and A3 for RX.

    The only difference is that I am using A.3 and A.4 on the 877
    If you're using A4 for TX, this pin is an open drain output. I.E. it can't go high!
    Last edited by Bruce; - 21st August 2008 at 22:31.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Maybe, just maybe.
    http://www.picbasic.co.uk/forum/showthread.php?t=562

    I might be wrong But I do not think A.4 will work for tx.


    edit
    Better late than never, did not see the above post
    Last edited by mackrackit; - 21st August 2008 at 22:43.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    A4 can be used for an output, but it only goes high if you use an enternal pull-up resistor.
    Regards,

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

Similar Threads

  1. strange serout2 problem
    By KaanInal in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th January 2010, 09:33
  2. PIC stop responding - Strange Problem!
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 31st August 2009, 14:06
  3. strange problem 12f675
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th July 2007, 13:47
  4. Another Serin/Serout Problem!
    By jmbanales21485 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th June 2007, 16:26
  5. 16F628 on-chip eeprom problem
    By atomski in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 4th March 2004, 07:43

Members who have read this thread : 0

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