-
Notifications
You must be signed in to change notification settings - Fork 7
shiftIn
back to Command Reference / Advanced-IO
Shifts in a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. For each bit, the clock pin is pulled high, the next bit is read from the data line, and then the clock pin is taken low.
If you’re interfacing with a device that’s clocked by rising edges, you’ll need to make sure that the clock pin is low before the first call to shiftIn()
, e.g. with a call to pinLow().
Note: this is a software implementation. The STM8 also provides a SPI hardware, which is faster but only works on specific pins.
Notes:
- after reset all I/O pins are configured as
INPUT
- data pin needs to be configured as
INPUT*
, clock pin asOUTPUT*
using pinMode(). - generally it is a good idea to synchronize master and slave frames, e.g. via a dedicated pin like in SPI, or via a frame timeout
- defined in
shift.h
-
not loaded by
main_general.h
- no
#define
required
shiftIn(pPortData,pinData,pPortClock,pinClock,clockWidth,bitOrder)
-
input:
- pPortData: pointer to port for data input, e.g. &PORT_A
- pinData: pin number for data input
- pPortData: pointer to port for clock output, e.g. &PORT_B
- pinClock: pin number for clock output
- clockWidth: width of clock pulse in microseconds
- bitOrder: which order to shift in the bits (MSBFIRST / LSBFIRST)
-
output:
- none
- read byte
The below program shifts in data from a slave via pins PE5
and PD2
in master mode.
#include "main_general.h"
#include "shift.h"
void setup() {
pinMode(&PORT_E, 5, INPUT); // data: muBoard io_1
pinMode(&PORT_D, 2, OUTPUT); // clock: muBoard io_2
pinLow(&PORT_D, 2);
}
void loop() {
uint8_t val;
val = shiftIn(&PORT_E, 5, &PORT_D, 2, 10, MSBFIRST);
delay(200);
}
- tbd
To avoid damage
- do not expose I/Os to voltages outside [-0.3V; Vdd+0.3V], else limit injection currents to the specificied limits
- for
OUTPUT
pins assert that sink and source currents are below the specificied limits - do not directly connect two
OUTPUT
pins. If e.g. half-duplex is required, use a pull-up andOUTPUT_OPENDRAIN
, instead
-
Getting Started
-
- General Commands
- Libraries
- LCD BTHQ21605V
- poti AD5280
- poti AD5282
- freemodbus
- PetitFS SD-card (min)
- FatFS: SD card (full)
- Board Specific
-
- Universal
- Board Specific