ShiftIn

From chipKIT
Jump to: navigation, search

Synopsis

 uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)

Description

shiftIn() utilises a pair of I/O pins to create a half-duplex synchronous serial interface. clockPin is toggled repeatedly and each time it goes HIGH the dataPin is sampled as one bit of a byte. That bit is added to the output value which is shifted either left or right to accommodate it. The parameter bitOrder indicates in which direction the shift should occur and to which end of the byte the incoming bit should be added. Possible values for bitOrder are MSBFIRST or LSBFIRST.

Eight bits are received in this manner before the function returns the value that has been received.

This functionality works akin to the receiving portion of a master SPI interface.

Return Value

The received byte.

Conforming To

shiftIn() conforms to the Arduino 1.6.x API.

Examples

 uint8_t val = shiftIn(3, 4, MSBFIRST);

See Also

digitalRead(), digitalWrite(), getPinMode(), pinMode(), pulseIn(), shiftOut()