After more than 30 minutes,we found that sometimes the data on MOSI is different from the data which we put in "spi_device_transmit()".
Once the mismatch occurs. the scope stops and we take the picture like this:
channel 1 is spi clk;
channel 2 is spi mosi;
channel 3 is gpio signal from slaver(just to trig scope)
and we can find 8 pulses with no data on MOSI.
The spi mode is :
13.333Mhz
mode 3
HSPI_HOST
DMA enable
Help!!!!
code:
init part:
Code: Select all
#define SPI_MISO_PIN 13
#define SPI_MOSI_PIN 12
#define SPI_CLK_PIN 14
#define SPI_CS_PIN 15
#define SPI_WAIT_PIN 17
#define SPI_SPEED_HZ 10000000
static spi_device_handle_t Spi_Init()
{
esp_err_t ret;
//doesn't work
gpio_iomux_in(SPI_MISO_PIN,HSPID_IN_IDX);
gpio_iomux_out(SPI_MOSI_PIN,HSPIQ_OUT_IDX,false);
gpio_iomux_out(SPI_CLK_PIN,HSPICLK_OUT_IDX,false);
gpio_iomux_out(SPI_CS_PIN,HSPICS0_OUT_IDX,false);
spi_device_handle_t spi;
spi_bus_config_t buscfg={
.miso_io_num=SPI_MISO_PIN,
.mosi_io_num=SPI_MOSI_PIN,
.sclk_io_num=SPI_CLK_PIN,
.quadwp_io_num=-1,
.quadhd_io_num=-1,
.flags = SPICOMMON_BUSFLAG_MASTER,
.intr_flags = ESP_INTR_FLAG_IRAM
};
spi_device_interface_config_t devcfg={
.cs_ena_pretrans = 0,
.cs_ena_posttrans = 10,
.clock_speed_hz=SPI_SPEED_HZ,
.mode=3,
.spics_io_num=SPI_CS_PIN,
.queue_size=1,
.pre_cb=NULL,
.flags = SPI_DEVICE_NO_DUMMY,
};
spi_host_device_t spiName = HSPI_HOST;
//Initialize the SPI bus
ret=spi_bus_initialize(spiName, &buscfg, 2);
assert(ret==ESP_OK);
//Attach the DEVICE to the SPI bus
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
assert(ret==ESP_OK);
spiTxBuf = (uint8_t *)heap_caps_malloc(512, MALLOC_CAP_DMA);/
spiRxBuf = (uint8_t *)heap_caps_malloc(512, MALLOC_CAP_DMA);
return spi;
}
Code: Select all
spi_transaction_t t;
memset(&t, 0, sizeof(t));
memset(spiTxBuf, 0, 512);
memset(spiRxBuf, 0, 512);
spiTxBuf[0] = 0xaa;
t.length=8;
t.tx_buffer=spiTxBuf;
ret=spi_device_transmit(spi, &t);
assert(ret==ESP_OK);