0

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

mashhashkarma gravatar image

asked 2017-03-02 14:33:25 +0100

joh2 gravatar image

updated 2017-03-03 09:56:56 +0100

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

edit retag flag offensive close delete report spam

1 answer

Sort by » oldest newest most voted
0
joh2 gravatar image

answered 2017-03-03 10:30:39 +0100

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

edit flag offensive delete publish link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

Question Tools

1 follower

Stats

Asked: 2017-03-02 14:33:25 +0100

Seen: 165 times

Last updated: mars 03