Shiftin & shiftout
nightsjudge
Posts: 6
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.
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
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.
WORD SHIFTIN(BYTE dpin, BYTE cpin, NIBBLE mode,BYTE bits);
But i also need what includes in shiftin and shiftout commands.