Shiftout question about the manual statement
+ Reply to Thread
Results 1 to 7 of 7
  1. #1

    Default Shiftout question about the manual statement

    In the PBP3 manual there is this paragraph:

    SHIFTOUT is a software-based command and does not require that the target device have synchronous serial capability. The ClockPin and DataPin parameters may be set to any digital I/O pins, and may be different in different commands within the same program.
    \Bits optionally specifies the number of bits to be shifted out. If it is not specified, 8 bits are shifted out, independent of the variable type. The Bits shifted out are always the low order bits, regardless of the Mode used, LSB or MSB. Up to 32 Bits can be shifted out of a single (long) variable. If more than 32 Bits are required, multiple variables or constants may be included between the square brackets.


    I am trying to understand the statement that is underlined, can anyone help?
    does it mean that if you use the /Bits modifier at all that the bit order is not affected by Mode ?

    Thanks!

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,242

    Default Re: Shiftout question about the manual statement

    Hi,
    If you have WORD sized variable and specify 12bits, MSBFIRST, one might think that it would shift out bits 15-4 but it doesn't. It shifts out bits 11-0. With LSB first it shifts out bits 0-11.

    At least that's how I interpret it.

    /Henrik :-)

  3. #3

    Default Re: Shiftout question about the manual statement

    I assume you are correct, thanks but I really think that could be worded much more clearly if so.

    The manual says SHIFTOUT is about 50kHz clock dependent on osc freq, what is 50k based on osc 4MHz?
    so 20MHz would be about 250k?

    I am debating whether to use SHIFTOUT or the MSSP module for SPI which I have never used. 50k might be fast enough (might not) but it is too close to the audio band for what I am doing.
    Are there some basic code examples here for SPI with the MSSP ?

    I can probably figure out how to configure the registers to set it up but what is the general program flow?
    set a pin, any pin, to enable slave device
    then what ? I see this code fragment from Steve here on the forum
    Write_MRF_SPIData:
    MRFDataSel=0 'Select the chip
    SSP1BUF = MRFSPIdata
    while !PIR1.3 : wend
    PIR1.3=0 'Reset the flag
    SSP1CON1.7=0 'Clear collision bit
    MRFDataSel=1 'Deselect the chip
    return

    so you set the register with the data to transmit and the While loop waits for an interrupt ?
    what exactly initiates the transmission? simply the act of setting the register?

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,242

    Default Re: Shiftout question about the manual statement

    so you set the register with the data to transmit and the While loop waits for an interrupt ?
    what exactly initiates the transmission? simply the act of setting the register?
    Correct on both accounts. As the SPI clock frequency goes up there's not much gain going the interrupt route so you can just as well poll the flag like that. The MSSP module CAN be a bit tricky to set up with the various polarities and "sample locations" but once you have it running it's really quite simple.

    /Henrik.

    EDIT: Sorry, I don't know how the SHIFTOUT clock frequency "scales" with oscillator frequency but I would GUESS it's pretty linear like you suggest.

  5. #5

    Default Re: Shiftout question about the manual statement

    Do you think it would be too risky to just assume the transmission is complete if I am only sending a byte or two?
    just send using MSSP and go about your business or must I poll the flag?
    do I have to clear anything when it is complete? or if I can guarantee it is complete just send another byte or two?

  6. #6
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    222

    Default Re: Shiftout question about the manual statement

    Do you think it would be too risky to just assume the transmission is complete if I am only sending a byte or two?
    just send using MSSP and go about your business or must I poll the flag?
    "SSP1BUF = MRFSPIdata": This loads real fast. But the actual transmission that takes place after that, takes a lot more micro seconds.
    If you write to the SSP1BUF back to back, the TX buffer gets over written with a new value before the module has had a chance to finish sending the 1st byte and the result is trash sent. Speaking from experience here.
    That's why you have to monitor and clear the "I'm done transmitting flag", PIR1.3 bit before loading the SSP1BUF with the next byte again.

    This little routine sends and reads 1 byte in 43us with 4MHz OSC:
    Code:
    '||||||||||||||||||||||| Device ID Verification |||||||||||||||||||||||||
    ' Device ID should come back as 00110011, $31 or DEC 51, takes 43us
    ' If the register is be to read then bit 7 has to be set.
    '   Example: WHO_AM_I | $80 will send $10001111
    '||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    Device_ID:
    ' Send register to read
      CS = 0                   ' Enable Chip Select
      SSP1BUF = WHO_AM_I|$80   ' Register $0F with :7 read bit set
      GOSUB SSP_INT            ' Wait until MSSP module finishes task
      SSPBUF = $0              ' Send 8 clock cycles
      GOSUB SSP_INT            ' Wait until MSSP module finishes task
      CS = 1
      ID = SSPBUF              ' Load ID variable with buffer value
    RETURN
    
    ' Allow MSSP module to finish task
    SSP_INT: 
       WHILE !PIR1.3: WEND
       PIR1.3 = 0
    RETURN
    Last edited by LinkMTech; - 21st February 2019 at 04:11.
    Louie

  7. #7

    Default Re: Shiftout question about the manual statement

    Louie, thank you for this, I will have hardware soon and report back hopefully with good news

Similar Threads

  1. PBP IF statement nesting question
    By lurker in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th September 2012, 22:03
  2. Question about the switch circuit in the PBP manual
    By schu4647 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th April 2010, 13:37
  3. Shiftout - shiftin question
    By Lasse1 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 5th April 2010, 16:34
  4. Shiftout question.
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd April 2007, 15:57
  5. Another Shiftout question
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st September 2004, 23:07

Members who have read this thread : 18

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts