Giter Site home page Giter Site logo

nopnop2002 / esp-idf-mcp3002 Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 4.0 24 KB

Driver for A/D converter with SPI serial interface

License: MIT License

CMake 5.14% Makefile 1.45% C 93.41%
mcp3001 mcp3002 mcp3004 mcp3008 mcp3201 mcp3202 mcp3204 mcp3208 mcp3301 mcp3302

esp-idf-mcp3002's Introduction

esp-idf-mcp3002

Driver for A/D converter with SPI serial interface.
esp-idf includes an ADC driver, but the convertible voltage is up to 3.3V.
By giving Vdd and Vref appropriately and level-shifting MOSI,MISO,CS and SCK, Higher voltages can be converted.
For example, when converting 5V, High Level Input Voltage of MOSI and SCK must be 0.7*5V=3.5V or higher.
And the high level output voltage of MISO will be 4.1V or higher.

Supported converters

Model Number of channels Resolution MinValue MaxValue Operating voltage
MCP3001 1 10Bits 0 1023 2.7V - 5.5V
MCP3002 2 10Bits 0 1023 2.7V - 5.5V
MCP3004 4 10Bits 0 1023 2.7V - 5.5V
MCP3008 8 10Bits 0 1023 2.7V - 5.5V
MCP3201 1 12Bits 0 4095 2.7V - 5.5V
MCP3202 2 12Bits 0 4095 2.7V - 5.5V
MCP3204 4 12Bits 0 4095 2.7V - 5.5V
MCP3208 8 12Bits 0 4095 2.7V - 5.5V
MCP3301 1 12Bits+Sign -4095 4095 4.5V - 5.5V
MCP3302 4 12Bits+Sign -4095 4095 4.5V - 5.5V
MCP3304 8 12Bits+Sign -4095 4095 4.5V - 5.5V

Software requirements

ESP-IDF V4.4/V5.x.
ESP-IDF V5.0 is required when using ESP32-C2.
ESP-IDF V5.1 is required when using ESP32-C6.

Installation

git clone https://github.com/nopnop2002/esp-idf-mcp3002
cd esp-idf-mcp3002/
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash

Note for ESP32C3
For some reason, there are development boards that cannot use GPIO06, GPIO08, GPIO09, GPIO19 for SPI clock pins.
According to the ESP32C3 specifications, these pins can also be used as SPI clocks.
I used a raw ESP-C3-13 to verify that these pins could be used as SPI clocks.

Configuration

config-top config-app

Device Setting

config-device-1 config-device-2 config-device-3

SPI Setting

config-spi-1

SPI BUS selection

config-spi-2

The ESP32 series has three SPI BUSs.
SPI1_HOST is used for communication with Flash memory.
You can use SPI2_HOST and SPI3_HOST freely.
When you use SDSPI(SD Card via SPI), SDSPI uses SPI2_HOST BUS.
When using this module at the same time as SDSPI or other SPI device using SPI2_HOST, it needs to be changed to SPI3_HOST.
When you don't use SDSPI, both SPI2_HOST and SPI3_HOST will work.
Previously it was called HSPI_HOST / VSPI_HOST, but now it is called SPI2_HOST / SPI3_HOST.

Wirering

MCP3xxx ESP32 ESP32-S2/S3 ESP32-C2/C3
MISO -- GPIO19 GPIO37 GPIO4
SCK -- GPIO18 GPIO36 GPIO3
MOSI -- GPIO23 GPIO35 GPIO2 *1
CS -- GPIO5 GPIO34 GPIO1
Vdd -- 3.3V 3.3V 3.3V
Vss -- GND GND GND

In addition to this, Vref and Agnd connections are required.
See the data sheet for details.

(*1)Not required for MCP3001/3201/3301.

Screen Shot

stdout

esp-idf-mcp3002's People

Contributors

hayschan avatar nopnop2002 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

esp-idf-mcp3002's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.