sandeepmistry / arduino-nRF5

Arduino Core for Nordic Semiconductor nRF5 based boards
Other
873 stars 278 forks source link

Invalid port mapping in pulse.c pulseIn #420

Closed sanyi closed 3 years ago

sanyi commented 3 years ago

I tried to use a distance sensor on BBC:microbit PIN2. uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout) failed to work correctly. I realized in NRF_GPIO->IN PIN2 modifies bit 1 not bit 2 as L:36 implies.

Modifying L:36 uint32_t bit = 1 << pin; //p.ulPin; to uint32_t bit = 1 << pin - 1; //p.ulPin; fixes the thing and enables the desired functionality.

sandeepmistry commented 3 years ago

Should be addressed as part of https://github.com/sandeepmistry/arduino-nRF5/pull/439.