Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 17th, 2018 74 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <esp_err.h>
  4. #include <freertos/FreeRTOS.h>
  5. #include <freertos/task.h>
  6. #include <driver/spi_master.h>
  7.  
  8. #define CS_PIN      GPIO_NUM_26
  9. #define CLK_PIN     GPIO_NUM_25
  10. #define MOSI_PIN    GPIO_NUM_22
  11. #define MISO_PIN    GPIO_NUM_21
  12.  
  13. void app_main(void)
  14. {
  15.     spi_bus_config_t buscfg;
  16.     buscfg.miso_io_num = MISO_PIN;
  17.     buscfg.mosi_io_num = MOSI_PIN;
  18.     buscfg.sclk_io_num = CLK_PIN;
  19.     buscfg.quadwp_io_num = -1;
  20.     buscfg.quadhd_io_num = -1;
  21.     buscfg.max_transfer_sz = 0;
  22.     buscfg.flags = 0;
  23.  
  24.     spi_device_interface_config_t devcfg;
  25.     devcfg.command_bits = 8;
  26.     devcfg.address_bits = 24;
  27.     devcfg.dummy_bits = 0;
  28.     devcfg.mode = 0;
  29.     devcfg.duty_cycle_pos = 0;
  30.     devcfg.cs_ena_pretrans = 0;
  31.     devcfg.cs_ena_posttrans = 0;
  32.     devcfg.clock_speed_hz = 8000000;
  33.     devcfg.spics_io_num = CS_PIN;
  34.     devcfg.flags = 0;
  35.     devcfg.queue_size = 7;
  36.     devcfg.pre_cb = 0;
  37.     devcfg.post_cb = 0;
  38.     devcfg.input_delay_ns = 0;
  39.  
  40.     ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &buscfg, 0));
  41.  
  42.     spi_device_handle_t spi_device_handle;
  43.     ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &devcfg, &spi_device_handle));
  44.  
  45.     while (true)
  46.     {
  47.         spi_transaction_t transaction;
  48.         transaction.cmd = 0x8F;
  49.         transaction.addr = 0xABCD;
  50.         transaction.flags = 0;
  51.         transaction.rxlength = 0;
  52.         transaction.length = 0;
  53.         ESP_ERROR_CHECK(spi_device_transmit(spi_device_handle, &transaction));
  54.  
  55.         vTaskDelay(50);
  56.     }
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top