/* This code demonstrates how to use the SPI master half duplex mode to read/write a AT932C46D EEPROM (8-bit mode). This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.*//* ... */#pragmaonce#include"driver/spi_master.h"#include"driver/gpio.h"#include"sdkconfig.h"/// Configurations of the spi_eepromtypedefstruct{spi_host_device_thost;///< The SPI host used, set before calling `spi_eeprom_init()`gpio_num_tcs_io;///< CS gpio number, set before calling `spi_eeprom_init()`gpio_num_tmiso_io;///< MISO gpio number, set before calling `spi_eeprom_init()`boolintr_used;///< Whether to use polling or interrupt when waiting for write to be done. Set before calling `spi_eeprom_init()`.}{ ... }eeprom_config_t;typedefstructeeprom_context_t*eeprom_handle_t;/** * @brief Initialize the hardware. * * @param config Configuration of the EEPROM * @param out_handle Output context of EEPROM communication. * @return * - ESP_OK: on success * - ESP_ERR_INVALID_ARG: If the configuration in the context is incorrect. * - ESP_ERR_NO_MEM: if semaphore create failed. * - or other return value from `spi_bus_add_device()` or `gpio_isr_handler_add()`. *//* ... */esp_err_tspi_eeprom_init(consteeprom_config_t*config,eeprom_handle_t*out_handle);/** * @brief Release the resources used by the EEPROM. * * @param handle Context of EEPROM communication. * @return Always ESP_OK *//* ... */esp_err_tspi_eeprom_deinit(eeprom_handle_thandle);/** * @brief Read a byte from the EEPROM. * * @param handle Context of EEPROM communication. * @param addr Address to read. * @param out_data Buffer to output the read data. * @return return value from `spi_device_polling_transmit()`. *//* ... */esp_err_tspi_eeprom_read(eeprom_handle_thandle,uint8_taddr,uint8_t*out_data);/** * @brief Erase a byte in the EEPROM. * * @param handle Context of EEPROM communication. * @param addr Address to erase. * @return * - ESP_OK: on success * - ESP_ERR_TIMEOUT: if the EEPROM is not able to be ready before the time in the spec. This may mean that the connection is not correct. * - or return value from `spi_device_acquire_bus()` `spi_device_polling_transmit()`. *//* ... */esp_err_tspi_eeprom_erase(eeprom_handle_thandle,uint8_taddr);/** * @brief Write a byte into the EEPROM * * @param handle Context of EEPROM communication. * @param addr Address to write. * @param data The byte to write. * @return * - ESP_OK: on success * - ESP_ERR_TIMEOUT: if the EEPROM is not able to be ready before the time in the spec. This may mean that the connection is not correct. * - or return value from `spi_device_acquire_bus()` `spi_device_polling_transmit()`. *//* ... */esp_err_tspi_eeprom_write(eeprom_handle_thandle,uint8_taddr,uint8_tdata);/** * @brief Enable following write/erase to the EEPROM. * * @param handle Context of EEPROM communication. * @return return value from `spi_device_polling_transmit()`. *//* ... */esp_err_tspi_eeprom_write_enable(eeprom_handle_thandle);/** * @brief Disable following write/erase to the EEPROM. * * @param handle Context of EEPROM communication. * @return return value from `spi_device_polling_transmit()`. *//* ... */esp_err_tspi_eeprom_write_disable(eeprom_handle_thandle);#ifCONFIG_EXAMPLE_5V_COMMANDS/** * @brief Erase all the memory in the EEPROM. * * @note This is only supported when EEPROM VCC is 5V. * @param handle Context of EEPROM communication. * @return * - ESP_OK: on success * - ESP_ERR_TIMEOUT: if the EEPROM is not able to be ready before the time in the spec. This may mean that the connection is not correct. * - or return value from `spi_device_acquire_bus()` `spi_device_polling_transmit()`. *//* ... */esp_err_tspi_eeprom_erase_all(eeprom_handle_thandle);/** * @brief write all the memory in the EEPROM to the value given. * * @note This is only supported when EEPROM VCC is 5V. * @param handle Context of EEPROM communication. * @return * - ESP_OK: on success * - ESP_ERR_TIMEOUT: if the EEPROM is not able to be ready before the time in the spec. This may mean that the connection is not correct. * - or return value from `spi_device_acquire_bus()` `spi_device_polling_transmit()`. *//* ... */esp_err_tspi_eeprom_write_all(eeprom_handle_thandle,uint8_tdata);/* ... */#endif//CONFIG_EXAMPLE_5V_COMMANDS
Details
Show: from
Types: Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.