RF12 module need to convert some C to Basic


Closed Thread
Results 1 to 40 of 44

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default clock

    on first turn-on, the RFM12 outputs a 1Mhz osc for the pic, which I am putting in on OSC1.
    After I write the command ... dout = $C0F7 : gosub Writecmd ... this changes that osc freq from 1MHz to 10MHz... so my pic will run at 10MHz. I have figured out the problem to just be that my crystal setting was on XT, not HS.

    I am onto the next part of converting C to Basic if anyone dare to assist....
    Code:
    void WriteFSKbyte( uchar DATA )
    {
      uchar RGIT=0;
      uint temp=0xB800;
      temp|=DATA;
    Loop: SCK = 0;
      nSEL=0;
      SDI=0;
      SCK=1;
      if(SDO)         //polling SDO
      {
        RGIT=1;
      }
      else
      {
        RGIT=0;
        WriteCMD(temp);
      }
    }
    So far I have...

    Code:
    WriteFSKbyte:
    temp = $B800
    
    Loop:
    SCK = 0
    nSEL = 0
    SDI = 0
    SCk = 1
    if SDO = 1 then
      rgit = 1
    else
      rgit = 0
    endif
    SCK = 0
    SDI = 1
    nSEL = 1
    if rgit = 0 then
      goto loop
    endif
    rgit = 0
    dout = temp
    gosub writecmd
    return
    The part I am struggling with right now is...

    Code:
      uchar RGIT=0;
      uint temp=0xB800;
      temp|=DATA;
    Does this take bit 0 of DATA and stick it to temp somehow??

    Someone with some C knowledge please help me!

    Thanks!

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default

    Why are you compilcating things?

    Just put a crystal or resonator on the pic and have it working on a precise time base. What you are doing now is screwing the timing of the commands and may be locks the pic at the time the freq. is changing. Also at 4MHz and lower the PIC should use XT settings and above that HS settings.

    I strongly recommend the PIC using its own clock.

    Ioannis

  3. #3
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Post Complicating..

    This is mostly just an excercise for a project of mine. The way the module is toted, is that it can output a clock signal for the pic, so only the crystal on the module is needed, and not 2 seperate oscillators. The examples I have seen of this module being used in the real world have had the osc out line connected to the pic. I have now got this part working though, and it is not a problem.

    Cheers

  4. #4
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Do you have to reset the registers each time the RF12 starts or are they non-volatile so that the clock frequency will always be 10MHz (or whatever) once set? In my experience, registers like these are usually non-volatile.

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


    Did you find this post helpful? Yes | No

    Default

    uchar RGIT=0; unsigned char RGIT = 0
    uint temp=0xB800; unsigned int temp = B800 hex
    temp|=DATA; temp = temp ORed with the value in DATA
    Regards,

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

  6. #6
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default registers

    dhouston,

    So far the registeres are reset when the power is removed. i.e. everytime I restart the module, the OSC is back to 1MHz.

    I did read in one of the datasheets, but I can't find it now, something along the lines of that you have to reset the module after changing settings for them to be stored. Not 100% sure of this right now. But I haven't had any luck attempting it so far.


    Bruce,

    What do you mean ORed?

    I'm struggling to get the over-all picture of what it sends here.

    From my understanding.. to actually send data.. I must use the "WriteCMD loop from earlier, to send first $b8, and then another 8bits of data.

    Which I have done by...
    Code:
    WriteFSKbyte:
    ...
    temp = $b8
    SCK = 0
    SDI = 1
    nSEL = 1
    dout.highbyte = temp
    dout.lowbyte = dat
    gosub writecmd
    Now currently there is what I presume is a preamble..

    Code:
      dout = $8228            'open PA
      gosub writecmd
      pauseus 4
      dout = $8238            'something to do with transmit register
      gosub writecmd
      pauseus 2
      dat = $AA
      gosub writefskbyte    'send $B8AA
      gosub writefskbyte    'send $B8AA
      dat = $2D
      gosub writefskbyte    'send $B82D
      dat = $D4
      gosub writefskbyte    'send $B8D4
    That should actually transmit.... "$AAAA, $2DD4 " ????????

    Suffering from severe lack of experience in RF and/or serial transmission, when should I send the pre-amble? Before every transmission?

    i.e.
    Preamble,
    Transmit data, - Several 16bit segments...
    Pause
    do whatever else..
    Preamble
    Transmit data
    etc??

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by davewanna View Post
    I did read in one of the datasheets, but I can't find it now, something along the lines of that you have to reset the module after changing settings for them to be stored. Not 100% sure of this right now. But I haven't had any luck attempting it so far.
    Don't see anything about that.

    What do you mean ORed?
    Logical OR'ing. It's in the manual, or look it up on Wiki under Boolean logic.

    I must use the "WriteCMD loop from earlier, to send first $b8, and then another 8bits of data.
    ShiftIn/ShiftOut will work just fine with this chip, no need to reinvent the wheel as you have been doing.

Similar Threads

  1. Version Control
    By btaylor in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 16th October 2011, 18:12
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  3. Replies: 1
    Last Post: - 27th July 2008, 07:14
  4. using AND as an IF statement
    By dw_pic in forum mel PIC BASIC
    Replies: 27
    Last Post: - 8th June 2006, 19:05
  5. convert Basic Stamp2 (BS2) => Pic
    By bs2rdu in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th September 2005, 20:55

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