Shop OBEX P1 Docs P2 Docs Learn Events
serial communication issue — Parallax Forums

serial communication issue

stelath_shadow9stelath_shadow9 Posts: 23
edited 2013-10-28 17:00 in Propeller 1
So I took the advice about using an external crystal. But now that I am at this point I am stuck again. The prop manual doesn't seem to be working for me. but here is what I have so far
'

CON
_clkmode = xtal2  +PLL4x           'no idea what this should be for 16Mhz crystal                     
_xinfreq = 4_000_000  
   
VAR
 byte char       'variable for incoming bytes
   
OBJ
  bs2   : "bs2"


pub start
bs2.start(31,30)


 this
PUB this


repeat
   char:=bs2.serin_char(1,9600,1,8)        'serin a byte and make char variable the same as that byte
      
     bs2.serout_char (30,char,9600,1,8)   'output char that just came in
    


The crystal I am using is 16Mhz and plugged into pin 25 and 26.

The odd thing about this is when I type a letter into pin1 the prop outputs a weird character. However if I change the output from "char" to something like "k" I will be able to see the "k" being output. But for whatever reason, I cannot see the appropriate character when I use the "char" variable.

I Haved checked the input into pin1 to ensure it is actually the correct ascii character I am typing. So...any ideas?

Comments

  • BeanBean Posts: 8,129
    edited 2013-10-24 18:12
    The propeller will not work with a 16Mhz xtal.
    10Mhz is the limit.
    Most programs are wtitten to use a 5Mhz xtal and the PLL16X setting to get 80Mhz clocck.

    Bean
  • Roger LeeRoger Lee Posts: 339
    edited 2013-10-24 21:09
    Bean, not sure that is correct.

    I may very well be wrong here, but isn't the 10Mhz crystal limit for PLL use.
    A 16Mhz crystal will just max out at 16Mhz, won't it?

    I totally agree you can't use it to wind up to 80Mhz.
  • Clock LoopClock Loop Posts: 2,069
    edited 2013-10-24 21:28
    Its because the prop is configured improperly, as bean states. His code shows PLLx4. The pll is ON, thus needs 4-8mhz.)

    attachment.php?attachmentid=104546&d=1382675219



    His code's first two lines need to be changed to this:
    CON 
     _clkmode = xtal2         'what this should be for 16Mhz crystal   
     _xinfreq = 16_000_000  
    
    

    Now if configured like this the 16mhz prop will run slow as molasses


    The 16mhz crystal prop could be used as a configurable clock SOURCE, if you have two props.

    Configure the 16mhz clock to run obex object http://obex.parallax.com/object/242 (im not sure if this object will like 16mhz)
    And have the object generate a 5mhz signal.
    Then run the 5mhz signal output pin on prop1 to the XI of prop 2.

    Configure prop2 as such.
    CON 
    _CLKMODE = XINPUT + PLL16X       
     _xinfreq = 5_000_000  
    
    
    And now the second prop is running 80mhz.

    And you wonder why they call me Clock Loop.
    :lol:
    1024 x 278 - 39K
  • stelath_shadow9stelath_shadow9 Posts: 23
    edited 2013-10-25 08:04
    Ok so I switched crystals to 8Mhz. I switched the code up with just trial and error until it started doing what I wanted it to do. Here is the new code. Can someone explain why these settings work in CON section. I really am not understanding this.
    con
    _clkmode = xtal1 +pll8x           'new settings for crystal                   
    _xinfreq = 4_000_000 
       
    VAR
     byte char
       
    OBJ
      bs2   : "bs2"
    Pub start
    bs2.start(31,30)
    This
    PUB this
        dira[14]~~
        repeat
         char:= bs2.serin_char(1,9600,1,8)    'bring in a character through serial (works now)
           bs2.serout_char(30,(char),9600,1,8)  'spit out that character into serial terminal(works now)
          If char== "u" 'If i push "u" then toggle the LED 
            
            !outa[14]
              waitcnt(32_000_000+cnt)
    
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-10-25 08:34
    The CON section is where constants are defined. Also here is where the clocking is defined - it is used by the compiler to set a couple of locations in hub in the binary that are then used by the rom boot loader.

    Perhaps it might be a good idea for you to do the examples that were downloaded with proptool. They will start you on your way. There are also examples of code usage etc here too. Also, look in the sticky thread at the top of these threads for more beginner info.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-10-25 08:38
    Now that you have a proper crystal, dump the BS2 object (which just applies the limitations of the BS2 to the Propeller) and use a typical serial object like FullDuplexSerial.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-10-25 08:52
    If you're using an 8 MHz crystal, _xinfreq should be 8_000_000, not 4_000_000.

    -Phil
  • stelath_shadow9stelath_shadow9 Posts: 23
    edited 2013-10-25 12:20
    If you're using an 8 MHz crystal, _xinfreq should be 8_000_000, not 4_000_000.

    -Phil

    Right? but when i use 8_000_000 it doesnt work. The characters out become all messed up.

    When I do the 4_000_000 though, it works.

    Thats why I was asking about what those constants are actually doing/ meaning.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-10-25 12:44
    Since you're specifying 9600 baud in your program, make sure that the baud rate specified in your serial terminal is also 9600 baud. Then the 8_000_000 should work.

    -Phil
  • kwinnkwinn Posts: 8,697
    edited 2013-10-25 16:28
    Right? but when i use 8_000_000 it doesnt work. The characters out become all messed up.

    When I do the 4_000_000 though, it works.

    Thats why I was asking about what those constants are actually doing/ meaning.

    _clkmode = xtal1 +pll8x 'This tells the software to have the PLL multiply the incoming frequency (from the xtal pin) by 8
    _xinfreq = 4_000_000 'This tells the software the frequency of the crystal connected to the xtal pins (4,000,000 Hz or 4MHz)

    If you had a 4MHz crystal connected then the propeller clock would be 32,000,000 Hz, and the software would use that to calculate the timing for each bit of your serial data. Since you have an 8MHz crystal connected the actual propeller clock frequency is 64,000,000 Hz. This means the baud rate of the propeller and terminal are off by a factor of 2. Make both baud rates the same, make _xinfreq = 8_000_000, and recompile the program.
  • stelath_shadow9stelath_shadow9 Posts: 23
    edited 2013-10-28 17:00
    kwinn wrote: »
    _clkmode = xtal1 +pll8x 'This tells the software to have the PLL multiply the incoming frequency (from the xtal pin) by 8
    _xinfreq = 4_000_000 'This tells the software the frequency of the crystal connected to the xtal pins (4,000,000 Hz or 4MHz)

    If you had a 4MHz crystal connected then the propeller clock would be 32,000,000 Hz, and the software would use that to calculate the timing for each bit of your serial data. Since you have an 8MHz crystal connected the actual propeller clock frequency is 64,000,000 Hz. This means the baud rate of the propeller and terminal are off by a factor of 2. Make both baud rates the same, make _xinfreq = 8_000_000, and recompile the program.

    when you say off by a factor of 2 what are you referring to. In the program the baud rate is set to 9600 and on my terminal it is set to 9600. so I dont understand what is off by 2.

    Also, why is it that the code I posted above is allowing the characters to show up correctly when the _xinfreq is set to 4_000_000 instead of 8_000_000
Sign In or Register to comment.