NRF52 - need library function equivalent to SHiftIn() and bitWrite() in Arduino.Pls Help.

hi I'm porting Arduino code which has calls to ShiftIn() to read a byte from a GPIO Pin and bitWrite() to write a bit into a byte variable at a particular position. Below is example arduino code:

data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST);
data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST);
data[0] = shiftIn(DOUT, PD_SCK, MSBFIRST);
..
..
bitWrite(data[j], i, digitalRead(DOUT));

Kindly suggest an equivalent library function in SoftDevice S132.

thank you

  • Hi,

    shiftIn() seems like a software implementation of SPI. You can read about the SPI driver from our SDK here. There is also an example available here. On the nRF51 and nRF52 series, you can select any of the GPIOs as pins for the SPI interfaces.

    bitWrite is just basic bit manipulation. You can make this into a function if you use it frequently (you should extend it for other types and add some error checking):

    uint8_t bitWrite(uint8_t x, uint8_t n, uint8_t b)
    {
    	return (b ? (x | 1 << n) : (x & ~(1 << n)));
    }
    

    Best regards,

    Jørgen