-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/add_spi_adc_sensor_mcp3201' into 'master'
add adc sensor: mcp3201 See merge request ae_group/esp-iot-solution!913
- Loading branch information
Showing
21 changed files
with
556 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# ChangeLog | ||
|
||
|
||
## v0.1.0 - 2025-1-16 | ||
|
||
### Enhancements: | ||
|
||
* Initial version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
idf_component_register(SRCS "mcp3201.c" | ||
INCLUDE_DIRS include) | ||
|
||
include(package_manager) | ||
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Component: MCP3201 | ||
|
||
MCP3201 device is a successive approximation 12-bit Analog-to-Digital (A/D) Converter with on-board sample and hold circuitry. The device provides a single pseudo-differential input.Differential Nonlinearity (DNL) is specified at ±1 LSB, and Integral Nonlinearity (INL) is offered in ±1 LSB (MCP3201-B) and ±2 LSB (MCP3201-C) versions. Communication with the device is done using a simple serial interface compatible with the SPI protocol. The device is capable of sample rates of up to 100 ksps at a clock rate of 1.6 MHz. The MCP3201 device operates over a broad voltage range (2.7V-5.5V).Low-current design permits operation with typical standby and active currents of only 500 nA and 300 μA, respectively. | ||
|
||
## Add component to your project | ||
|
||
Please use the component manager command `add-dependency` to add the `mcp3201` to your project's dependency, during the `CMake` step the component will be downloaded automatically | ||
|
||
``` | ||
idf.py add-dependency "espressif/mcp3201=*" | ||
``` | ||
|
||
## Example of MCP3201 usage | ||
|
||
```c | ||
static spi_bus_handle_t spi_bus = NULL; | ||
static mcp3201_handle_t mcp3201 = NULL; | ||
int16_t data; | ||
|
||
// Step1: Init SPI bus | ||
spi_config_t bus_conf = { | ||
.miso_io_num = SPI_MISO_IO, | ||
.mosi_io_num = -1, | ||
.sclk_io_num = SPI_SCLK_IO, | ||
}; | ||
spi_bus = spi_bus_create(SPI2_HOST, &bus_conf); | ||
TEST_ASSERT(spi_bus != NULL); | ||
|
||
// Step2: Init MCP3201 | ||
spi_device_config_t dev_cfg = { | ||
.mode = 0, | ||
.clock_speed_hz = SPI_FREQ_HZ, | ||
.cs_io_num = SPI_CS_IO, | ||
}; | ||
mcp3201 = mcp3201_create(spi_bus, &dev_cfg); | ||
|
||
// Step3: Read ADC value | ||
mcp3201_get_data(mcp3201, &data); | ||
ESP_LOGI(TAG, "MCP3201:%d,Convert:%.2f", data, 1.0f * data * (3.3f / 4096)); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: 0.1.0 | ||
description: SPI driver for MCP3201 adc sensor | ||
url: https://github.com/espressif/esp-iot-solution/tree/master/components/sensor/adc/mcp3201 | ||
repository: https://github.com/espressif/esp-iot-solution.git | ||
documentation: https://docs.espressif.com/projects/esp-iot-solution/en/latest/sensors/adc.html | ||
issues: https://github.com/espressif/esp-iot-solution/issues | ||
dependencies: | ||
spi_bus: | ||
public: true | ||
override_path: "../../../spi_bus" | ||
idf: '>=4.4' | ||
cmake_utilities: "0.*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "spi_bus.h" | ||
|
||
typedef void *mcp3201_handle_t; | ||
|
||
/** | ||
* @brief Create and init sensor object and return a sensor handle | ||
* | ||
* @param spi_bus SPI bus handle | ||
* @param dev_cfg SPI device configuration | ||
* | ||
* @return | ||
* - sht3x handle_t | ||
*/ | ||
mcp3201_handle_t mcp3201_create(spi_bus_handle_t spi_bus, spi_device_config_t *dev_cfg); | ||
|
||
/** | ||
* @brief Delete and release a sensor object | ||
* | ||
* @param sensor Point to object handle of mcp3201 | ||
* | ||
* @return | ||
* - ESP_OK Success | ||
* - ESP_FAIL Fail | ||
*/ | ||
esp_err_t mcp3201_delete(mcp3201_handle_t *sensor); | ||
|
||
/** | ||
* @brief Get device data of MCP3201 | ||
* | ||
* @param sensor Point to object handle of mcp3201 | ||
* @param data adc data | ||
* | ||
* @return | ||
* - ESP_OK Success | ||
* - ESP_FAIL Fail | ||
*/ | ||
esp_err_t mcp3201_get_data(mcp3201_handle_t sensor, int16_t *data); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Oops, something went wrong.