Created
November 17, 2018 21:51
-
-
Save michprev/594d5005d55f77a7cfdf991623fb098b to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <stdbool.h> | |
#include <esp_err.h> | |
#include <freertos/FreeRTOS.h> | |
#include <freertos/task.h> | |
#include <driver/spi_master.h> | |
#define CS_PIN GPIO_NUM_26 | |
#define CLK_PIN GPIO_NUM_25 | |
#define MOSI_PIN GPIO_NUM_22 | |
#define MISO_PIN GPIO_NUM_21 | |
void app_main(void) | |
{ | |
spi_bus_config_t buscfg; | |
buscfg.miso_io_num = MISO_PIN; | |
buscfg.mosi_io_num = MOSI_PIN; | |
buscfg.sclk_io_num = CLK_PIN; | |
buscfg.quadwp_io_num = -1; | |
buscfg.quadhd_io_num = -1; | |
buscfg.max_transfer_sz = 0; | |
buscfg.flags = 0; | |
spi_device_interface_config_t devcfg; | |
devcfg.command_bits = 8; | |
devcfg.address_bits = 24; | |
devcfg.dummy_bits = 0; | |
devcfg.mode = 0; | |
devcfg.duty_cycle_pos = 0; | |
devcfg.cs_ena_pretrans = 0; | |
devcfg.cs_ena_posttrans = 0; | |
devcfg.clock_speed_hz = 8000000; | |
devcfg.spics_io_num = CS_PIN; | |
devcfg.flags = 0; | |
devcfg.queue_size = 7; | |
devcfg.pre_cb = 0; | |
devcfg.post_cb = 0; | |
devcfg.input_delay_ns = 0; | |
ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &buscfg, 0)); | |
spi_device_handle_t spi_device_handle; | |
ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &devcfg, &spi_device_handle)); | |
while (true) | |
{ | |
spi_transaction_t transaction; | |
transaction.cmd = 0x8F; | |
transaction.addr = 0xABCD; | |
transaction.flags = 0; | |
transaction.rxlength = 0; | |
transaction.length = 0; | |
ESP_ERROR_CHECK(spi_device_transmit(spi_device_handle, &transaction)); | |
vTaskDelay(50); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment