What about pin mode opendrain with a setting of 1? That should be open state.
Yes, could be an option. On the other hand, I have more the feeling that somehow the AD converter gets started but is not stopped or some other things like counters, muxes, etc. are running or set and keep drawing power because they are not reset. --- I have no clue what I'm talking about, but trying to understand hardware as can be seen at http://www.espruino.com/STM32+Peripherals makes me fish in that murky pond... I know that an NRF52 is not and STM32, but I expect similar 'intestines'; they are both ARMs after all.
@allObjects ADC looks stopped according to HW registers, it is the configuration of the GPIO pin that makes the difference, I guess even digital read would do same thing as long as the pin ends in same state. Actually the first idea was to read it as digital after reading as analog but that didn't help.
@Wilberforce thanks, didn't think about setting it as output. While open drain is perhaps not same thing as disconnected input, it might actually work as a workaround if set to right value. nrf has both settings disconnect at 1, normal 0 or disconnect at 0, normal 1. I wonder what happens in the circuit before I manage to set the right output value to disconnect it.
You can turn SPI/I2C/Serial off just by setting the pins to other things - then it'll happen automatically.
Internally you can do
jshPinSetState(pin, JSHPINSTATE_UNDEFINED);to disconnect the pin: https://github.com/espruino/Espruino/blob/master/targets/nrf5x/jshardware.c#L699
But I don't think that behaviour is exposed: https://github.com/espruino/Espruino/blob/master/src/jswrap_io.c#L389
So potentially a
disconnectedpin Mode could be added to the
pinModefunction pretty easily.
or perhaps the ADC input mode should instead not configure the pin as a digital input, but should configure it more like the 'undefined' state does? https://github.com/espruino/Espruino/blob/master/targets/nrf5x/jshardware.c#L731
As for automatically turning pin to disconnected mode after ADC is finished - makes sense to me. I was a bit surprised it ends in "input" mode as there is also "analog" pin mode string. Anyway, since the analog reading is just one shot it can be indeed disconnected after saadc is stopped here?
Also I just discovered Waveform class for analog sampling and I don't see any additional code related to this - doing direct analog sampling into longer buffer in targets/nrf5x/jshardware.c. So I guess it is all platform independent and only uses this same jshPinAnalog one time analog read method periodically(?)
As for having "disconnected" or "undefined" pin mode value - that makes sense to me too. And is not directly related to analog read. Like you mentioned it can be used also to disable SPI pins or any other digital pin then.
I need to discuss with you about a project but I couldn't find your email or telephone number or skype...
Please advise. It is important.
my email is firstname.lastname@example.org
well, you can use github https://github.com/fanoush/ds-d6 and create issue there. Or forum here can send messages.
I need a private communication.
Good point about actually switching after the analog read is finished - I wonder if that changes the accuracy of subsequent ADC readings though? As far as I can tell it may be that the input doesn't need to be connected at all for ADC to work - 'sense' exists more for digital and it might be ADC is connected all the time.
Waveform I guess it is all platform independent and only uses this same jshPinAnalog
s far as I can tell it may be that the input doesn't need to be connected at all for ADC to work
I see, in that case I will try to change line jshPinSetState(pin, JSHPINSTATE_ADC_IN); to jshPinSetState(pin, JSHPINSTATE_UNDEFINED ) tonight and see what happens with reported battery voltage.
or I better move the case JSHPINSTATE_ADC_IN: few lines up to be the same as case JSHPINSTATE_UNDEFINED: instead of being same as case JSHPINSTATE_GPIO_IN:
OK so I did that and moved the 'case' up and analogRead(D3) works and returns similar sensible values as before and peek32(0x5000070c) returns value of 2 after the read without a need to use poke32.
Great - thanks! I'll swap that around in Git head then - how's power usage?
edit: nice side-effect of that is that by setting the pin state to 'analog' you can get the low power mode as well.
Nice. So another disconnected mode string is not strictly needed as switching to analog would do. Also reporting "analog" is better than previous "input" as there was no difference with input buffer connected or disconnected. It is only a bit confusing to return "analog" mode for pins which cannot do analog input on nrf5x, which is most of them :-)
As for power draw, I guess it is ok now due to input buffer being disconnected. Unfortunately I don't have the tools to measure such low currents myself, it was reported to me by another guy who does. Anyway, I hope current 16 days of idle runtime will double or triple thanks to this :-)
As for analog vs digital GPIO modes I searched devzone and manuals but didn't find it anywhere said in clear. I guess it is obvious for them that once analog channel is used it takes over the pin and no GPIO config applies so no previous setup is needed. The only hint I found is the picture here which shows ANAEN to enable ANAIN input and disconnect everything else.
Hi! Am I right that now one should not switch pin mode after analogRead(), and no initial pin mode setting is needed, to save power?
Yes, I'm pretty sure. Everything should be configured ok at boot now
Cool, many thanks! +1 to Espruino karma: recall Arduino, where one needs to reset pinMode to output after reading a pin..
It looks like when reading battery voltage via analogRead(D3) on DS-D6 fitness tracker the power consumption after first such call rises by 70uA i.e. from ~44 uA to ~112 uA.
The solution to get back to original power draw is setting the pin to input with disconnected buffer like it is after reset. It can be done by calling
as per documentation and the power is back to where it was. However I did not find Espruino way e.g. something like D3.mode("off"). Is there such a way? If I set D3.mode("input") then it is still not enough and
returns 0 and the power draw is still higher instead of 2 which means disconected pin.
Also when thinking more about power draw I did not find a way to turn off SPI1 and I2C1 either, there is no unsetup() like with Serial1 (still don't know if it is problem or not, more measurings in various states will come)