RF12 module need to convert some C to Basic


Closed Thread
Results 1 to 40 of 44

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,121


    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

  2. #2
    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?

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,121


    Did you find this post helpful? Yes | No

    Default

    If you check it with the manual, I understand that you cannot send a binary string that way. You have to use, as with most of the commands, a variable. Either byte or word size defined on top.

    So put the string in two byte variables or a word sized variable and then send it out with shiftout command. Check also if MSB or LSB is needed by the module.

    The 1100000011110111 string is exaclty 16bits.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default

    There is an example on the meLabs website showing how to use the synchronous serial port hardware to read/write from/to an SPI slave (e.g. RF12).Also, here is a link to a BasCOM program written for the RF12. While BasCOM is not PBP and an AVR chip is not a PIC, it should still give you a good understanding of what you need to do.
    Last edited by dhouston; - 9th June 2008 at 12:49.

  5. #5
    Join Date
    Dec 2007
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Shiftout

    Ioannis,

    I realised this not long after I posted.. I tried the following with no difference in results..

    Code:
    dout            var word
    dout = $C0F7
    shiftout SDO, SCK, 1, [dout]
    Tried with the HEX, and the binary values.
    I don't think it matters, but also tried [dout\16]

    Dhouston,

    Thanks for the links, I will study them closely tomorrow.

  6. #6
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: RF12 module need to convert some C to Basic

    Thank for the link.
    The program is written in German... but it is a great help.
    regards,
    Ambrogio

  7. #7
    Join Date
    Jan 2013
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: RF12 module need to convert some C to Basic

    Hi,
    Is this thread still open?
    I would like to ask questions
    Camerart

  8. #8
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: RF12 module need to convert some C to Basic

    I’m struggling to find C code in this thread that isn’t directly converted to PBP.

    C:
    Code:
    temp|=DATA;
    PBP:
    Code:
    temp = temp|data'
    C falls short of PBP or asm for bitwise operations because you can never access a bit in a single instruction,
    hence the bit mask is being used in C to only write the set bits in the temp variable.
    Code:
    B800 = 1011100000000000
    DATA = 0000000000001111
    
    B800 | DATA = 1011100000001111
    If you’re clocking the external chip, and then feeding the pic it’s output clock that would normally be a very good idea
    because once you send the command to PLL the external chip's clock higher, both chips are clocked at the higher speed,
    and no timing adjustment of the SPI or SHIFTOUT routines should need adjusting,
    EXCEPT for the fact that the pic’s instruction clock is divided by 4, so the two chip’s practical instruction timing is not increased evenly,
    so you will need two different communication timings for the two different speeds of the external chip.

  9. #9
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: RF12 module need to convert some C to Basic

    Nops in this function are a delay. The function (subroutine as you worked out) sends a single zero value out of the SPI bus.
    If you were to set SCK low, and then high again in the very next instruction, the receiving device might miss the signal.
    Especially if the external device runs slower than the transmitting device. You can use @nop in PBP.

    Since there are several flavours of SPI, it would be better to reproduce this then use PBP SHIFTOUT (unless it’s already working).
    They are really only turning two port bits on & off.

    Code:
    writezero:
    portb.something = 0’ clear SPI data
    portb.something = 0’ clear clock pin, the receiver will look at the value of the SPI data bit now.
    delay
    portb.something = 1’ set the clock pin, the receiver will look for the next bit on the next rising edge (next time you call this function, or the writeone function).
    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();
    }
    Last edited by Art; - 8th October 2016 at 10:50.

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