Shop OBEX P1 Docs P2 Docs Learn Events
Shiftin & shiftout — Parallax Forums

Shiftin & shiftout

nightsjudgenightsjudge Posts: 6
edited 2011-04-02 13:14 in BASIC Stamp
Hi everybody,

I never worked on BS so i do really need help.

I have H48C 3D accelerometer. I need to connect this acc. to the AT89C52.
I am programming in C so i need to convert these commands "SHIFTIN and SHIFTOUT" to C codes.

i will be appreciated if you help me.

Thanks for replies.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-01 09:47
    This is a support forum for the Parallax Stamps. A more appropriate place for your question would be the Sensors forum.

    In any event, we can't help you with the C program or the AT89C52. The accelerometer is an SPI device which uses a chip select line (/CS) which is brought to ground to activate the device, then data is clocked out of the device with the clocks on the CLK line and the data itself is on the DIO line in most significant bit first order.

    The SHIFTOUT simply clocks out the data, putting the data bit on the DIO line, then producing a clock pulse and repeating this until all the data is sent. Read the MCP3204 ADC datasheet for details of what's what in the data interchange. Pages 15 and 16 of the datasheet (here) show very nicely what's sent.

    The SHIFTIN produces a clock as well and shifts in data from the DIO line, in this case MSB first. The MCP3204 provides 13 bits which the sample program puts in a variable. Note that the MCP3204 has separate Din and Dout lines that are connected together in the accelerometer module to make DIO since Din and Dout are never both active at the same time.

    I suggest you look in the AT89C52 and its C compiler's documentation for examples of the use of SPI devices. The MCP3204 is not so different from other SPI devices that you can't adapt some existing sample code.
  • nightsjudgenightsjudge Posts: 6
    edited 2011-03-01 10:00
    Thanks for reply.
  • neurocyberneurocyber Posts: 9
    edited 2011-03-04 22:35
    This is what I use, maybe it will help;

    WORD SHIFTIN(BYTE dpin, BYTE cpin, NIBBLE mode,BYTE bits);
    BIT SHIFTOUT(BYTE dpin, BYTE cpin, BIT mode,WORD outputdata, BYTE bits);

  • nightsjudgenightsjudge Posts: 6
    edited 2011-04-02 13:14
    Thanks for reply neurocyber,

    But i also need what includes in shiftin and shiftout commands.
Sign In or Register to comment.