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

    Default RF12 module need to convert some C to Basic

    Hi,

    I have a few RFM12 modules that I have posted on here about before. I have started to delve into the coding side of things, but am somewhat lost. The datasheets for these modules have examples coded in C. But I currently have absolutely no knowledge of C. Can someone who knows picbasic, and C please point me in the right direction?

    The module is 'programmable' for a LOT of options. I am interested in getting just one to work, then I should be able to find my way from there. It has an osc output that can be used to supply the pic. I currently have that working, but at the default 1Mhz. This is the setting I have been attempting to change, as it should be easy to spot.

    The register is in the datasheet at: http://www.hoperf.com/pdf/RF12.pdf Page 22, item 14.

    according to what I can see, changing that register to 1100000011110111 should change the osc output to 10Mhz, and the low voltage detector to 4.5V

    The C example of how to do this, from what I can see uses a command called write.

    Code example is at: http://www.hoperf.com/pdf/RF12_code.pdf Page 20.
    The piece I'm particularly interested in is when it calls a subroutine called "WriteCMD()" and has the following:

    Code:
    void WriteCMD( uint CMD )
    {
        uchar n=16;
        SCK=0;
        nSEL=0;
        while(n--)
        {
            if(CMD&0x8000)
              Write1();
            else
              Write0();
            CMD=CMD<<1;
        }
        SCK=0;
        nSEL=1;
    }
    Can this be done in picbasic via shiftout, or serout?


    I am using a 16f877a


    Thanks in advance as always....

  2. #2
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default correction

    As I said I don't know any C.. But looking at the code more, I have just noticed that Write0 and Write1 seem to also be subroutines...

    Code:
    void Write0( void )
    {
      SDI=0;
      SCK=0;
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      NOP();
      SCK=1;
      NOP();
    }
    My revised question is:
    What is NOP() ????

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


    Did you find this post helpful? Yes | No

    Default

    Table 15-2 of the 16F877A data sheet says a NOP = No Operation

    I can not help with the "C".
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default NOP() = Nothing?

    Ok, so it seems that a NOP() is a nothing... which I assume is a timing thing. I can't really see how it turns a piece of HEX data into a string of ones and zero's and outputs them..

    Surely there is a simpler way of doing this in picbasic? Should it respond to a serout command?

    I thought I had researched all I could before I posted.... I know no-one is replying yet.. but I think asking the questions is helping my brain somehow.

    Still open for assistance!

  5. #5
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default thankyou

    Thanks mackrackit... I just found that out as you posted...

    Pity no-one has example code of these modules in picbasic.. would make my learning procedure easier...

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,947


    Did you find this post helpful? Yes | No

    Default

    Have you just tried to send this binary string with shiftout?

    I think there is not much needed to make it work. Just send the string. Serout will not work here.

    Ioannis

  7. #7
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Shiftout

    Ioannis,


    I have not used shiftout before... I have just tried..


    Code:
    SCK             var portb.6
    SDO             var portb.7
    shiftout SDO, SCK, 1, [%1100000011110111]
    This did not change the osc... still 1Mhz. Is my syntax ok?

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    void WriteCMD( uint CMD ) <-uint CMD takes in an unsigned integer
    {
        uchar n=16; <-unsigned character (byte) set to 16
        SCK=0; <- SCK to logic low
        nSEL=0; <- nSEL to logic low
        while(n--) <- while/wend loop, n gets decremented by 1 each time thru
        {
            if(CMD&0x8000) <- if high bit of CMD is set then
              Write1(); <-call the Write1() sub
            else
              Write0(); <-otherwise do this one
            CMD=CMD<<1; <-shift it left by one
        }
        SCK=0; <- SCK to logic low
        nSEL=1; <- nSEL to logic high
    }
    I might be totally wrong...not that familiar with C...but to me this means:

    Code:
    WriteCMD:
    n = 16 : SCK = 0 : nSEL = 0
    for nn = 16 to 0 step -1
    if cmd.15 = 1 then
    gosub write1
    else
    gosub write0
    endif
    cmd = cmd << 1 : sck = 0 : nSel = 1 : return
    
    Write0:
    SDI = 0 : SCK = 0 : pauseus 16 : SCK = 1 : return
    
    Write1:
    SDI = 1 : SCK = 0 : pauseus 16 : SCK = 1 : return
    And your issue might've been that you didn't turn the nSEL line on/off before writing out to the port...unless you didn't include that part in the posts.

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,947


    Did you find this post helpful? Yes | No

    Default

    I really wonder if the skimask's example will work because is the same shiftout command.

    I have also ordered a couple of the modules (the high power ones) but will be delay and cannot test them right now.

    Ioannis

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    I really wonder if the skimask's example will work because is the same shiftout command.
    Ioannis
    It is the same...
    I think the only difference is toggling the SEL line.

  11. #11
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default nSEL

    Skimask,

    Thankyou for doing that... From the little bit of C that I have learnt in the last 24 hours, that looks good.

    I did try nSEL last night with a couple of code attempts, but I did not try it consistantly.

    I did also try to use the SSP last night for a short period. No luck yet, but I didn't expect it to be easy, I haven't used the SSP yet.

    I am off to work now, but will try again later today.


    Thanks for the assistance.
    Last edited by davewanna; - 9th June 2008 at 23:09.

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,947


    Did you find this post helpful? Yes | No

    Default

    It could be a timing issue. No time to check now. If anyone could?

    Ioannis

Similar Threads

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