Skip to content

adafruit_ds1307 module does not respect user-changed values for Square Wave output #24

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

Merged
merged 3 commits into from
May 22, 2022

Conversation

coplate
Copy link
Contributor

@coplate coplate commented May 20, 2022

I am working on a project with my rp2040 where I am using my DS1307 to trigger an interrupt every 1 second.
I had started this project in MicroPython with another library, and had updated register 07 in the DS1307 with the flags to generate a 1Hz square wave. ( set bits in register to '00010000' ).

When I started updating my project to use CircuitPython, I imported this library and found that it used those bits to validate if it is a 1307, which will not work.

This pull request is to update the module to reflect the specifications provided by the manufacture for which fields are constant.

coplate added 2 commits May 19, 2022 22:06
The existing code relied on checking the values of the square wave register, and confirming that the default of 0x#3 was set.  These values are user selectable and should not be used to validate the device is an DS1307.
I followed the same logic, but applied it to the fields that are guaranteed to always be 0 in the DS1307 manual, instead of using user-changeable values.
Updated adafruit_ds1307.py to allow Square Wave settings
@tekktrik tekktrik requested a review from a team May 20, 2022 17:12
@ladyada
Copy link
Member

ladyada commented May 20, 2022

@caternuson any thoughts?

@caternuson
Copy link

This seems OK. But a little curious how one runs into this.

@coplate Are you restarting your code without a power cycle? Wondering how the check gets back anything from the register other than the expected power on defaults?

@coplate
Copy link
Contributor Author

coplate commented May 21, 2022

This seems OK. But a little curious how one runs into this.

@coplate Are you restarting your code without a power cycle? Wondering how the check gets back anything from the register other than the expected power on defaults?

@caternuson
My DS1307 has had a battery hooked up since I set it up a few weeks ago, so the IC itself has not had a power cycle. I kept the battery in to keep the clock accurate. I can imagine that previous tests on this would have passed if there wasn't a battery in the device, and it was relying on VCC power instead of VBAT. (If those tests including changing the SQW feature )

@caternuson
Copy link

oh yah, the battery. thanks. makes sense.

just dumping some datasheet info for ref:
image

there's really no dedicated who-am-i register. the existing check is making a flawed assumption that RS1 and RS0 will be power on defaults. using the always-read-0 bits seems like a better approach. and adding a second register (0x03) read should help to verify.

LGTM

@ladyada ladyada merged commit 83e9438 into adafruit:main May 22, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request May 24, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_BH1750 to 1.1.0 from 1.0.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_BH1750#6 from DeadSix27/main
  > Patch .pre-commit-config.yaml
  > change discord badge
  > Patch: Replaced discord badge image
  > Updated gitignore
  > Update Black to latest.
  > Fixed readthedocs build
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground to 5.2.1 from 5.2.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_CircuitPlayground#117 from Neradoc/frozen-module-subdirectory

Updating https://github.com/adafruit/Adafruit_CircuitPython_DS1307 to 2.1.10 from 2.1.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_DS1307#24 from coplate/main
  > Patch .pre-commit-config.yaml
  > change discord badge
  > Patch: Replaced discord badge image
  > Updated gitignore
  > Update Black to latest.
  > Fixed readthedocs build
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_UC8151D to 1.1.0 from 1.0.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_UC8151D#4 from HDR/main
  > Patch .pre-commit-config.yaml
  > change discord badge
  > Patch: Replaced discord badge image
  > Updated gitignore
  > Update Black to latest.
  > Fixed readthedocs build
  > Post-patch cleanup
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_BitmapSaver to 1.2.1 from 1.2.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_BitmapSaver#23 from matt-land/add-typing
  > Patch .pre-commit-config.yaml
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.

3 participants