Using my Oscilloscope, I am not seeing clock or data. The error I am getting is this: E (5804824) spi_master: check_trans_valid(684): invalid dev handle
Here is my SPI code.
- /*
- * temp_SPI-6.c
- *
- * Created on: Apr 12, 2023
- * Author: keith
- */
- #include <stdio.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "driver/gpio.h"
- #include "driver/spi_master.h"
- #include "temp_SPI-6.h"
- #define USE_SPI_MODE
- #define SPI_BUS SPI3_HOST
- #define GPIO_CS 4
- #define GPIO_SIO 37
- #define GPIO_CLK 36
- //#define GPIO_IRQ 2 // IRQ pin
- #define TMP127_REG_TEMP 0x01
- spi_device_handle_t spi_device;
- spi_transaction_t *trans_desc;
- void tmp127_spi_init()
- {
- spi_bus_config_t bus_cfg = {
- .miso_io_num = GPIO_SIO,
- .mosi_io_num = -1,
- .sclk_io_num = GPIO_CLK,
- .quadwp_io_num = -1,
- .quadhd_io_num = -1,
- .max_transfer_sz = 32,
- };
- spi_bus_initialize(SPI3_HOST, &bus_cfg, 1);
- spi_device_interface_config_t dev_cfg = {
- .clock_speed_hz = 1000000, // Clock out at 1 MHz
- .mode = 0, // SPI mode 0
- .spics_io_num = GPIO_CS, // CS pin
- .queue_size = 1,
- // .flags = SPI_DEVICE_NO_DUMMY,
- };
- // spi_bus_initialize(SPI_BUS, &bus_cfg, 1);
- // spi_bus_add_device(SPI_BUS, &dev_cfg, &spi_device);
- spi_bus_initialize(SPI3_HOST, &bus_cfg, 1);
- spi_bus_add_device(SPI3_HOST, &dev_cfg, &spi_device);
- spi_device_acquire_bus(spi_device, portMAX_DELAY);
- // gpio_set_direction(GPIO_CS, GPIO_MODE_OUTPUT);
- // gpio_set_direction(GPIO_CLK, GPIO_MODE_OUTPUT);
- // gpio_set_direction(GPIO_SIO, GPIO_MODE_INPUT);
- }
- int16_t tmp127_read_temperature()
- {
- // uint8_t tx_data[2] = {TMP127_REG_TEMP, 0};
- // uint8_t rx_data[2] = {0, 0};
- uint8_t rx_data[2] = {0};
- spi_transaction_t trans_desc = {
- // .tx_buffer = tx_data,
- .rx_buffer = rx_data,
- .length = 16,
- .flags = SPI_TRANS_USE_RXDATA,
- };
- // spi_device_transmit(spi_device, &trans_desc);
- spi_device_polling_start(spi_device, &trans_desc, portMAX_DELAY);
- spi_device_polling_transmit(spi_device, &trans_desc);
- int16_t temperature = (rx_data[0] << 8) | rx_data[1] >> 4;
- // int16_t temperature = (rx_data[1] << 8) | rx_data[2];
- // temperature >>= 4; // Remove lower 4 bits (fractional part)
- // temperature = temperature / 128;
- return temperature;
- }