Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for internal pull-up resistor #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jmhunter
Copy link

Add the ability to use internal pull-up resistor for device search. Greatly reduces required components for the simple use case of detecting the presence of a DS1990 or similar unit

On platforms such as Arduino, a new #define can now be set in OneWire.h
to enable the internal pull-up resistor. This means that no external
resistor is needed to search for 1-wire devices. Do not expect this to
work for temperature sensors and other such devices, that have higher
power requirements than simple serial number devices.
@PaulStoffregen
Copy link
Owner

Have this code been tested on any non-AVR chips?

@StephanFink
Copy link

I have tried it on a chipKit MAX32 Controller with a PIC chip and didn't manage it to work.
But it would be great to see that function in your library. I have used that page to change your library and the embedded one in chipKits mpide:
d8cbd47

@PaulStoffregen
Copy link
Owner

Any tried on any other non-AVR boards? (I'm pretty sure it will not work on any of them)

@jmhunter
Copy link
Author

jmhunter commented Mar 7, 2017

If it only works on AVR boards (sorry, I only have Arduino here to test with), would it be an idea to update this to have some kind of #ifdef that limits its use to AVR?

@orgua
Copy link

orgua commented Jul 16, 2017

it will work on some controllers like AVR, but won't do harm on the others. the changes could be more minimal though. the digitalWrite() in constructor shouldn't be needed

@PaulStoffregen
Copy link
Owner

PaulStoffregen commented Jul 18, 2017

but won't do harm on the others

Which others have you tested?

This code uses the AVR quirk where writing to the output register affects the input pullups. I do not intend to merge it as-is.

@orgua
Copy link

orgua commented Jul 19, 2017

-> I tested this code without the preprocessor-guards with atmega328p, teensy3.2 and the esp8266, works as expected on atmega. won't do harm on the others. but you are right. i wouldn't merge this either without some cleanup.

what do you expect to happen on other architectures? we are using macros that rely on low level register access. there is no controller in your list that magically changes the pin-direction after the pin is set to input and the output-registers are written afterwards. here is a list of gpio-behaviors (compiled from the datasheets) for proving my point:

(AVR)

ReferenceDataSheet atmega328p

  • DDRx – Data Direction Register
  • PORTx – Pin Output Register --> To activate/deactivate pull up resistors – when port is configures as input
  • PINx – Pin Input Register, read only
    -> used pin magic (PORTx has more than one meaning)

(MK20DX128) || (MK20DX256) || (MK66FX1M0) || (MK64FX512)

K20 / Cortex M4 Reference Manual
page 239FF - Port control : Individual pull control registers with pullup, pulldown and pull-disable support
page 1597FF - GPIO

  • GPIOx-PDOR - port data output registrer, also set, clear and toggle registers
    • 0 Logic level 0 is driven on pin provided pin is configured for General Purpose Output.
    • 1 Logic level 1 is driven on pin provided pin is configured for General Purpose Output.
  • GPIOx-PDIR - port data input register
  • GPIOx-PDDR - port data direction register
    -> no pin magic

MK64 / Cortex M4 Reference Manual
page 1757ff -> same design as K20

K66 / Cortex M4 Reference Manual
page 2185ff -> same design as K20

(MKL26Z64)

KL2x Cortex M0 Reference Manual
page 844ff -> same design as K20

(SAM3X8E) || (SAM3A8C) || (SAM3A4C)

SAM3X \ SAM3A Cortex M3 Datasheet
page 618ff PIO

  • pull-up resistor control (only, not PD)
  • PIO_OER - output enable register, also output disable and status register
  • PIO_SODR - set output data register, also clear and status register
  • PIO_PDSR - pin data status register
    -> no pin magic

(PIC32MX)

PIC32MX MIPS32 datasheet
page 307ff io ports

  • control over weak pull-ups and open-drain output via separate registers
  • PIO_TRIS register sets data direction
  • PIO_PORT register used to read current state of the applied signal
  • PIO_LAT register used to write data to pin
    -> no pin magic

(ARDUINO_ARCH_ESP8266)

ESP8266 Datasheet page 17: Each GPIO can be configured with internal pull-up

ESP8266 Technical Reference
page 14ff GPIO

  • GPIO_ENABE_W1TS: output enable register

  • GPIO_ENABE_W1TC: output disable register

  • GPIO_ENABLE: output enable status register

  • GPIO_OUT_W1TC: output low level register

  • GPIO_OUT_W1TS: output high level register, If the related bit is set to be 1, it means the IO output is high level (at the same time, users should enable the output).

  • GPIO_OUT: output status register

  • GPIO_Input_registers for input status

  • gpio parameter configuration with extra registers
    -> api uses macros for everything
    -> no pin magic

(SAMD21G18A)

SAMD21 Cortex M0+ Datasheet
page 339ff PORT IO PIN CONTROLLER

  • control of pull-up and pull-down via output-register IF pull is enabled
  • registers for direction, input-enable, pull-enable, output
    -> some pin magic (see table below)

DIR INEN PULLEN OUT Configuration
0 0 0 X Reset or analog I/O: all digital disabled
0 0 1 0 Pull-down; input disabled
0 0 1 1 Pull-up; input disabled
0 1 0 X Input
0 1 1 0 Input with pull-down
0 1 1 1 Input with pull-up
1 0 X X Output; input disabled
1 1 X X Output; input enabled

(RBL_NRF51822)

nRF51 Reference Manual
page 56ff: config registers for direction, drive strengh, pull-up and down resistors, pin sensing

  • GPIO_OUT - write gpio port, enable or disable pin driver
  • OUTSET and OUTCLR - work on individual bits
  • GPIO_IN - read port
  • GPIO_DIR - direction of gpio pins
  • DIRSET and DIRCLR - does the same with less cmds
  • PIN_CNFx for every pin -> odd thing: there is also a directional bit to set
    -> no pin magic

(arc) /* Arduino101/Genuino101 specifics */

Intel Curie Module (Quark SE C1000) Datasheet
page 54: Separate data register bit and data direction control bit for each GPIO

  • internal pull-ups and selectable drive strength
  • unused lines must be configured as inputs with internal pull-up or as GPIO with output set to low, or set
    as input with external pull-up.
    -> (most likely) no pin magic

Quark SE C1000
page 410 GPIO

  • registers for gpio data, data direction, data source and two configuration register
  • Port data: Values written to this register are output on the I/O signals for if the corresponding data direction bits are set to Output mode and the corresponding control bit for the Port is set to Software mode. The value read back is equal to the last value
    written to this register.
  • data direction: as expected
  • data source: change between hardware or software controllable
    -> no pin magic

else

  • mapping to regular arduino-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants