C driver for the AMS AS5600 magnetic rotary position sensor
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
To get a local copy up and running follow these simple steps.
-
Navigate to your project's source directory
-
Clone the repo
git clone https://github.com/raulgotor/ams_as5600.git
-
Write a transfer function (see next section)
A transfer function is needed by the driver to know how to use the I2C of your specific hardware. Above, a simple example of how this could be implemented for STM32 MCUs using the STM32 HAL Libraries is shown:
I2C_HandleTypeDef * hi2c;
uint32_t const my_i2c_xfer(uint8_t const slave_address,
uint8_t const * const p_tx_buffer,
size_t const tx_buffer_size,
uint8_t * const p_rx_buffer,
size_t const rx_buffer_size)
{
uint32_t const timeout = 100;
HAL_StatusTypeDef result = HAL_OK;
bool is_rx_operation = true;
if ((NULL == p_tx_buffer) || (0 == tx_buffer_size)) {
result = HAL_ERROR;
} else if ((NULL == p_rx_buffer) || (0 == rx_buffer_size)) {
is_rx_operation = false;
}
if (HAL_OK == result) {
// TX operation
result = HAL_I2C_Master_Transmit(hi2c,
slave_address,
p_tx_buffer,
(uint16_t)tx_buffer_size,
timeout);
}
if ((HAL_OK == result) && (is_rx_operation)) {
// RX operation
result = HAL_I2C_Master_Receive(hi2c,
slave_address,
p_rx_buffer,
rx_buffer_size,
timeout);
}
return result;
}
After declaring the transfer function, initialize the module with the following call:
as5600_error_t result = as5600_init(my_i2c_xfer);
Please refer to the in code documentation and to the AMS AS5600 Datasheet
See the open issues for a list of proposed features (and known issues).
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Raúl Gotor
Project Link: https://github.com/raulgotor/ams_as5600