{"id":20910534,"url":"https://github.com/ziteh/as5047p-driver","last_synced_at":"2025-09-01T03:06:56.068Z","repository":{"id":52956191,"uuid":"481537246","full_name":"ziteh/as5047p-driver","owner":"ziteh","description":"Platform independent AS5047P rotary position sensor library","archived":false,"fork":false,"pushed_at":"2023-03-16T02:52:43.000Z","size":68,"stargazers_count":10,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-31T22:02:43.989Z","etag":null,"topics":["as5047","library","platformio","sensor","spi","stm32"],"latest_commit_sha":null,"homepage":"https://registry.platformio.org/libraries/ziteh/as5047-driver","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/ziteh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-14T09:05:39.000Z","updated_at":"2025-01-17T08:51:23.000Z","dependencies_parsed_at":"2025-05-13T07:47:10.679Z","dependency_job_id":null,"html_url":"https://github.com/ziteh/as5047p-driver","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/ziteh/as5047p-driver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziteh%2Fas5047p-driver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziteh%2Fas5047p-driver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziteh%2Fas5047p-driver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziteh%2Fas5047p-driver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ziteh","download_url":"https://codeload.github.com/ziteh/as5047p-driver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziteh%2Fas5047p-driver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273068848,"owners_count":25039911,"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","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["as5047","library","platformio","sensor","spi","stm32"],"created_at":"2024-11-18T14:15:44.756Z","updated_at":"2025-09-01T03:06:56.021Z","avatar_url":"https://github.com/ziteh.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AS5047P Driver\n[![GitHub](https://img.shields.io/github/license/ziteh/as5047p-driver)](./LICENSE)\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/ziteh/as5047p-driver)](https://github.com/ziteh/as5047p-driver/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/ziteh/library/as5047-driver.svg)](https://registry.platformio.org/libraries/ziteh/as5047-driver)\n\nA platform independent library for [ams AS5047P](https://ams.com/as5047p) rotary position sensor/magnetic encoder.\n\n- `src/`: Main code.\n  - [`as5047p.c`](./src/as5047p.c)\n  - [`as5047p.h`](./src/as5047p.h)\n- `examples/`: Some examples.\n- `LICENSE`\n- `README.md` (*this file*)\n\n## Usage\n\n### Install\nThere are 3 ways to install:\n\n1. Go to VS Code \u003e PIO Home \u003e Libraries and search \"as5047-driver\", press the \"Add to Project\" button.\n\n2. Add `lib_deps = ziteh/as5047-driver@^2.0.0` in `platformio.ini` file, for example:\n```ini\n[env:nucleo_f446re]\nplatform = ststm32\nboard = nucleo_f446re\nframework = stm32cube\nlib_deps = ziteh/as5047-driver@^2.0.0\n```\n\n3. PIO CLI: `pio pkg install --library \"ziteh/as5047-driver@^2.0.0\"`.\n\n### Writing the Code\nInclude \n```c\n#include \u003cas5047p.h\u003e\n```\n\nThe following functions that must be implemented in the user file (e.g. `main.c`), function names are free:\n```c\nvoid as5047p_spi_send(uint16_t data);\nuint16_t as5047p_spi_read(void);\nvoid as5047p_spi_select(void);\nvoid as5047p_spi_deselect(void);\nvoid as5047p_delay(void)\n```\n\nTake STM32 HAL for example:\n```c\nvoid as5047p_spi_send(uint16_t data)\n{\n  HAL_SPI_Transmit(\u0026hspi1, (uint8_t *)\u0026data, 1, HAL_MAX_DELAY);\n}\n\nuint16_t as5047p_spi_read(void)\n{\n  uint16_t data = 0;\n  HAL_SPI_Receive(\u0026hspi1, (uint8_t *)\u0026data, 1, HAL_MAX_DELAY);\n  return data;\n}\n\nvoid as5047p_spi_select(void)\n{\n  HAL_GPIO_WritePin(AS5047P_SS_GPIO_Port, AS5047P_SS_Pin, GPIO_PIN_RESET);\n}\n\nvoid as5047p_spi_deselect(void)\n{\n  HAL_GPIO_WritePin(AS5047P_SS_GPIO_Port, AS5047P_SS_Pin, GPIO_PIN_SET);\n}\n\n// For 't_CSn': High time of CSn between two transmissions, \u003e350 ns.\nvoid as5047p_delay(void)\n{\n  HAL_Delay(1);\n}\n```\n\nMake handle and init:\n```c\nas5047p_handle_t as5047p;\nas5047p_make_handle(\u0026as5047p_spi_send,\n                    \u0026as5047p_spi_read,\n                    \u0026as5047p_spi_select,\n                    \u0026as5047p_spi_deselect,\n                    \u0026as5047p_delay,\n                    \u0026as5047p);\n\n// Configure SETTINGS1 and SETTINGS2.\nas5047p_config(\u0026as5047p, 0b00100101, 0b00000000); \n\n// Set specify position as zero.\nas5047p_set_zero(\u0026as5047p, 0);\n```\n\nRead angle in degree:\n```c\nfloat angle_deg;\nint8_t error = as5047p_get_angle(\u0026as5047p, without_daec, \u0026angle_deg);\n\nif (error == 0)\n{\n    printf(\"Angle: %f\\r\\n\", angle_deg);\n}\n```\n\nRead raw position:\n```c\nuint16_t position;\nint8_t error = as5047p_get_position(\u0026as5047p, without_daec, \u0026position);\n\nif (error == 0)\n{\n    printf(\"Raw: %5i\\r\\n\", position);\n}\n```\n\n## Examples\n- STM32 HAL: [`examples/stm32_hal/src/main.c`](./examples/stm32_hal/src/main.c)  \n- STM32 LibOpenCM3: [`examples/stm32_libopencm3/src/main.c`](./examples/stm32_libopencm3/src/main.c)\n\u003e [My blog](https://ziteh.github.io/2022/04/learningstm32-as5047p/) (Chinese) has more detailed descriptions.\n\n## AS5047P SPI Interface\n- SPI Mode = 1.\n    - CPOL = 0: Clock is low when idle.\n    - CPHA = 1: Data is sampled on the second edge (i.e. falling edge).\n- CS (chip select) pin active low.\n- Data size (data frame format) is 16-bit.\n- Bit order is MSB first.\n- Max clock rates up to 10 MHz.\n- Only supports slave operation mode.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziteh%2Fas5047p-driver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fziteh%2Fas5047p-driver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziteh%2Fas5047p-driver/lists"}