{"id":16146167,"url":"https://github.com/libdriver/ds3231","last_synced_at":"2025-04-09T22:18:03.423Z","repository":{"id":40384135,"uuid":"366753392","full_name":"libdriver/ds3231","owner":"libdriver","description":"DS3231 full function driver library for general MCU and Linux.","archived":false,"fork":false,"pushed_at":"2025-03-02T09:49:08.000Z","size":4161,"stargazers_count":55,"open_issues_count":0,"forks_count":21,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-09T22:17:58.300Z","etag":null,"topics":["c","ds3231","full-function-driver","iic","linux","mcu","rtc"],"latest_commit_sha":null,"homepage":"https://www.libdriver.com","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libdriver.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-12T14:57:05.000Z","updated_at":"2025-04-02T14:18:09.000Z","dependencies_parsed_at":"2023-12-16T06:56:09.234Z","dependency_job_id":"1a11d736-e89c-4b2e-b070-8be8a301175c","html_url":"https://github.com/libdriver/ds3231","commit_stats":null,"previous_names":["libdriver/ds3231"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libdriver%2Fds3231","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libdriver%2Fds3231/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libdriver%2Fds3231/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libdriver%2Fds3231/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libdriver","download_url":"https://codeload.github.com/libdriver/ds3231/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119286,"owners_count":21050755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","ds3231","full-function-driver","iic","linux","mcu","rtc"],"created_at":"2024-10-10T00:19:19.204Z","updated_at":"2025-04-09T22:18:03.405Z","avatar_url":"https://github.com/libdriver.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"[English](/README.md) | [ 简体中文](/README_zh-Hans.md) | [繁體中文](/README_zh-Hant.md) | [日本語](/README_ja.md) | [Deutsch](/README_de.md) | [한국어](/README_ko.md)\n\n\u003cdiv align=center\u003e\n\u003cimg src=\"/doc/image/logo.svg\" width=\"400\" height=\"150\"/\u003e\n\u003c/div\u003e\n\n## LibDriver DS3231\n\n[![MISRA](https://img.shields.io/badge/misra-compliant-brightgreen.svg)](/misra/README.md) [![API](https://img.shields.io/badge/api-reference-blue.svg)](https://www.libdriver.com/docs/ds3231/index.html) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](/LICENSE)\n\nThe DS3231 is a low-cost, extremely accurate I2C real-time clock (RTC) with an integrated temperature compensated crystal oscillator (TCXO) and crystal. The device incorporates a battery input, and maintains accurate timekeeping when main power to the device is interrupted. The integration of the crystal resonator enhances the long-term accuracy of the device as well as reduces the piece-part count in a manufacturing line. The DS3231 is available in commercial and industrial temperature ranges, and is offered in a 16-pin, 300-mil SO package.\n\nLibDriver DS3231 is a full function driver of ds3231 launched by LibDriver.It provides time reading, alarm clock triggering, temperature reading, square wave output and other functions. LibDriver is MISRA compliant.\n\n### Table of Contents\n\n  - [Instruction](#Instruction)\n  - [Install](#Install)\n  - [Usage](#Usage)\n    - [example basic](#example-basic)\n    - [example alarm](#example-alarm)\n    - [example output](#example-output)\n  - [Document](#Document)\n  - [Contributing](#Contributing)\n  - [License](#License)\n  - [Contact Us](#Contact-Us)\n\n### Instruction\n\n/src includes LibDriver DS3231 source files.\n\n/interface includes LibDriver DS3231 IIC platform independent template.\n\n/test includes LibDriver DS3231 driver test code and this code can test the chip necessary function simply.\n\n/example includes LibDriver DS3231 sample code.\n\n/doc includes LibDriver DS3231 offline document.\n\n/datasheet includes DS3231 datasheet.\n\n/project includes the common Linux and MCU development board sample code. All projects use the shell script to debug the driver and the detail instruction can be found in each project's README.md.\n\n/misra includes the LibDriver MISRA code scanning results.\n\n### Install\n\nReference /interface IIC platform independent template and finish your platform IIC driver.\n\nAdd the /src directory, the interface driver for your platform, and your own drivers to your project, if you want to use the default example drivers, add the /example directory to your project.\n\n### Usage\n\nYou can refer to the examples in the /example directory to complete your own driver. If you want to use the default programming examples, here's how to use them.\n\n#### example basic\n\n```C\n#include \"driver_ds3231_basic.h\"\n\nuint8_t res;\nds3231_time_t time;\nint16_t raw;\nfloat s;\n\nres = ds3231_basic_init();\nif (res != 0)\n{\n    return 1;\n}\n\n...\n\nres = ds3231_basic_get_temperature((int16_t *)\u0026raw, (float *)\u0026s);\nif (res != 0)\n{\n    (void)ds3231_basic_deinit();\n\n    return 1;\n}\nds3231_interface_debug_print(\"ds3231: temperature is %0.2fC.\\n\", s);    \n\n...\nmode = DS3231_ALARM1_MODE_ONCE_A_SECOND;\ntime.am_pm = DS3231_AM;\ntime.date = data;\ntime.format = DS3231_FORMAT_24H;\ntime.hour = hour;\ntime.minute = minute;\ntime.month = month;\ntime.second = second;\ntime.week  = week;\ntime.year = year;\nres = ds3231_basic_set_time(\u0026time);\nif (res != 0)\n{\n    (void)ds3231_basic_deinit();\n\n    return 1;\n}\n\n...\n    \nres = ds3231_basic_get_time(\u0026time);\nif (res != 0)\n{\n    (void)ds3231_basic_deinit();\n\n    return 1;\n}\n\n\nif (time.format == DS3231_FORMAT_24H)\n{\n    ds3231_interface_debug_print(\"ds3231: %04d-%02d-%02d %02d:%02d:%02d %d.\\n\",\n                                 time.year, time.month, time.date,\n                                 time.hour, time.minute, time.second, time.week\n                                );\n}\nelse\n{\n    ds3231_interface_debug_print(\"ds3231: %04d-%02d-%02d %s %02d:%02d:%02d %d.\\n\",\n                                 time.year, time.month, time.date, (time.am_pm == DS3231_AM) ? \"AM\" : \"PM\",\n                                 time.hour, time.minute, time.second, time.week\n                                );\n}\n\n...\n\n(void)ds3231_basic_deinit();\n\nreturn 0;\n```\n\n#### example alarm\n\n```C\n#include \"driver_ds3231_alarm.h\"\n\nuint8_t res;\nds3231_time_t time;\nds3231_alarm1_mode_t mode;\n\nvoid alarm_receive_callback(uint8_t type)\n{\n    switch (type)\n    {\n        case DS3231_STATUS_ALARM_2 :\n        {\n            ds3231_alarm_clear_flag(DS3231_ALARM_2);\n            ds3231_interface_debug_print(\"ds3231: irq alarm2.\\n\");\n            \n            ...\n            \n            break;\n        }\n        case DS3231_STATUS_ALARM_1 :\n        {\n            ds3231_alarm_clear_flag(DS3231_ALARM_1);\n            ds3231_interface_debug_print(\"ds3231: irq alarm1.\\n\");\n            \n            ...\n            \n            break;\n        }\n        default :\n        {\n            ...\n            \n            break;\n        }\n    }\n}\n\n\nres = ds3231_alarm_init(alarm_receive_callback);\nif (res != 0)\n{\n    return 1;\n}\n\n...\n\nres = gpio_interrupt_init();\nif (res != 0)\n{\n    (void)ds3231_alarm_deinit();\n\n    return 1;\n}\n\n...\n\nmode = DS3231_ALARM1_MODE_ONCE_A_SECOND;\ntime.am_pm = DS3231_AM;\ntime.date = data;\ntime.format = DS3231_FORMAT_24H;\ntime.hour = hour;\ntime.minute = minute;\ntime.month = month;\ntime.second = second;\ntime.week  = week;\ntime.year = year;\nres = ds3231_alarm_set_alarm1(\u0026time, mode);\nif (res != 0)\n{\n    (void)ds3231_alarm_deinit();\n\n    return 1;\n}\n\n...\n\nres = ds3231_alarm_enable(DS3231_ALARM_1);\nif (res != 0)\n{\n    (void)ds3231_alarm_deinit();\n\n    return 1;\n}\n\n...\n\n(void)ds3231_alarm_deinit();\n\nreturn 0;\n```\n\n#### example output\n\n```C\n#include \"driver_ds3231_output.h\"\n\nuint8_t res;\n\nres = ds3231_output_init();\nif (res != 0)\n{\n    return 1;\n}\n\n...\n\nres = ds3231_output_set_square_wave(enable);\nif (res != 0)\n{\n    (void)ds3231_output_deinit();\n\n    return 1;\n}\n\n...\n\nres = ds3231_output_set_32khz_output(enable);\nif (res != 0)\n{\n    (void)ds3231_output_deinit();\n\n    return 1;\n}\n\n...\n\n(void)ds3231_output_deinit();\n\nreturn 0;\n```\n\n### Document\n\nOnline documents: [https://www.libdriver.com/docs/ds3231/index.html](https://www.libdriver.com/docs/ds3231/index.html).\n\nOffline documents: /doc/html/index.html.\n\n### Contributing\n\nPlease refer to CONTRIBUTING.md.\n\n### License\n\nCopyright (c) 2015 - present LibDriver All rights reserved\n\n\n\nThe MIT License (MIT) \n\n\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\n\nof this software and associated documentation files (the \"Software\"), to deal\n\nin the Software without restriction, including without limitation the rights\n\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n\ncopies of the Software, and to permit persons to whom the Software is\n\nfurnished to do so, subject to the following conditions: \n\n\n\nThe above copyright notice and this permission notice shall be included in all\n\ncopies or substantial portions of the Software. \n\n\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n\nSOFTWARE. \n\n### Contact Us\n\nPlease send an e-mail to lishifenging@outlook.com.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibdriver%2Fds3231","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibdriver%2Fds3231","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibdriver%2Fds3231/lists"}