Coder Social home page Coder Social logo

esp32-spibus's Introduction

SPIbus

SPI interface library in C++ for working with Espressif ESP32 IoT Development Framework (esp-idf), that supports master mode.

This SPIbus library is designed just as a high-level access of the ESP32's SPI peripheral, that actually, incorporates some of the basic functionality of spi_master driver from esp-idf, translating the SPI functions as object oriented code. Its purpose is to simplify the usage of the native spi-master driver, and it is most for communication with 8-bit register sensors.

So if you want to interact with a simple sensor over SPI protocol using C++, you can use this library to do so, a bit easier.

Install

You can clone it right into your project components directory or in your specific library path.

 git clone https://github.com/natanaeljr/esp32-SPIbus.git SPIbus

Usage

The ESP32 has four SPI peripheral devices, called SPI0, SPI1, HSPI and VSPI.

SPI0 is entirely dedicated to the flash cache, the ESP32 uses to map the SPI flash device it is connected to into memory. SPI1 is connected to the same hardware lines as SPI0 and is used to write to the flash chip. HSPI and VSPI are free to use and are the currently implemented ones in the esp-idf.

So we can start off initializing the default global objects hspi and vspi as follows:

hspi.begin(MOSI_1, MISO_1, SCLK_1)
vspi.begin(MOSI_2, MISO_2, SCLK_2)

HSPI and VSPI all have three chip select lines, allowing them to drive up to three SPI devices each as a master. To add a device to the controller, simply call addDevice() with the device configuration and a handle.

spi_device_handle_t sensor_handle
hspi.addDevice(SPIMODE, CLOCK, CS_PIN, &sensor_handle);

Now we read and write to the device with the specific methods.

hspi.writeByte(sensor_handle, REGISTER_ADDR, VALUE)
hspi.readBit(sensor_handle, REGISTER_ADDR, BITNUM, BUFFER)

The library has several methods to read/write which simplifies communication. See the header file for more info.


See also I2Cbus library: https://github.com/natanaeljr/esp32-I2Cbus

Copyright © 2017 Natanael Josue Rabello [[email protected]]

esp32-spibus's People

Contributors

natanaeljr avatar ahzf avatar sebastianpsm avatar

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.