Shop OBEX P1 Docs P2 Docs Learn Events
Strange SX-48 Behavior — Parallax Forums

Strange SX-48 Behavior

RS_JimRS_Jim Posts: 1,771
edited 2008-09-10 04:38 in General Discussion
I have been running the TX_HEX2 subroutine that is in the example programs and had it work successfully. Now all of a sudden it prints $E for the second digit regardless of what the input is.· Watching it in single step mode, what is happening, no matter what the character stored in the tmpB2 register the W register is getting loaded with $FE.· I put in a \ Mov W,#0 command prior to loading the tmpB2 but to no avail.· It loads $FE in the W regester.
I tried moving the Subroutine code to another page, again the same problem.
Anyone have any ideas?
Jim
roll.gif·

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-08-11 05:54
    Have you also checked it with SxSim?
    Can you post the code?

    regards peter
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-11 17:14
    I think that's probably one of my subroutines -- and you may be using an older version of it. Since TX_HEX2 uses TX_BYTE you need to make sure that there is no negative interaction. This is the code that I am presently using for both routines:

    ' Use: TX_BYTE aByte
    
    SUB TX_BYTE
      SEROUT TX, Baud, __PARAM1
      ENDSUB
    
    ' -------------------------------------------------------------------------
    
    ' Use: TX_HEX2 byteVal
    ' -- transmit byte in HEX2 format
    
    SUB TX_HEX2
      tmpB1 = __PARAM1
      
      tmpB2 = tmpB1 & $F0                           ' isolate high nib
      SWAP tmpB2                                    ' move for READ
      READ Hex_Digits + tmpB2, tmpB2                ' convert to ASCII
      TX_BYTE tmpB2
      tmpB1 = tmpB1 & $0F                           ' isolate low nib
      READ Hex_Digits + tmpB1, tmpB1
      TX_BYTE tmpB1
      ENDSUB
    
    ' -------------------------------------------------------------------------
    ' User Data
    ' -------------------------------------------------------------------------
    
    Hex_Digits:
      DATA  "0123456789ABCDEF"
    

    Post Edited (JonnyMac) : 8/11/2008 5:25:30 PM GMT
  • RS_JimRS_Jim Posts: 1,771
    edited 2008-08-17 15:06
    Jonny Mac,
    Thanks for the insite. I am using an interupt driven version of your code for TX and RX. The TX-HEX2 sub I think I used from the help file on SXB
    I will lookinto it. Thanks
    Jim
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-17 18:02
    You might want to use the attached program as reference. Since I do so many SX projects with serial comms I am constantly refining my code -- what's attached is the current state of my efforts and will move easily between the SX28 and SX48. It's important to know that in SX/B the global vars are in BANK $00 for the SX18/20/28 and in BANK $10 for the SX48/52. As this can affect assembly segments (e.g., ISR-driven UARTs) this program has a constant called __DEFAULT that you must change based on the processor you're using. In SX/B 2.0 the __DEFAULT constant is built in, so when that is released you'll need to delete that CON definition.

    [noparse][[/noparse]Edit] Added BIN8 and DEC3 output routines
    [noparse][[/noparse]Edit] Improved and updated -- see post below

    Post Edited (JonnyMac) : 8/19/2008 5:19:44 AM GMT
  • RS_JimRS_Jim Posts: 1,771
    edited 2008-08-19 04:57
    Thanks Jonny,

    That solves all sorts of problems! Now I have to recalculate the baud rate constants for a 20 MHz xtal, but I believe I have downloaded a calculator that does all that for virtual periferals. I was going to put the __default in an ifdef statement but it did not want to compile right so will figure that out later.

    Jim
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-19 05:13
    No, no, no! You don't have to recalculate anything. The rate parameter of of INTERRUPT takes care of all the gnarly work for the ISR (setting the OPTION bits and RETURNINT value) -- so don't screw it up with unnecessary experimenting! tongue.gif All you have to do is change the FREQ and OSC settings. There are constants defined for common baud rates.

    I didn't have any trouble with a conditional compilation setup for the __DEFAULT constant. See attached.

    Post Edited (JonnyMac) : 8/19/2008 5:23:01 AM GMT
  • RS_JimRS_Jim Posts: 1,771
    edited 2008-09-10 04:38
    jonny Mac,

    leave it to me to do things the hard way.· I was having trouble trying to determine how to set the interupt rate until I figured out that it was the recipricol of the interupt timing. The problem I had with the if def was failing to write it with the ' in front of the { . When I looked at your example I saw the error of my ways.· You might emphasise the importance of the '{ } structure in an example in the help file.· One of the difficulties I have in reading the help file is that the highlighted segments sometimes mask important features like a comma after a command statement or a ' infront of something.

    Thanks again for all you do!

    Jim
Sign In or Register to comment.