请教一下SPI发送的问题

djqlyy
Posts: 52
Joined: Wed Oct 23, 2019 12:46 am

请教一下SPI发送的问题

Postby djqlyy » Wed Mar 23, 2022 12:52 am

我的应用是ESP32S2作SPI从机,通过FPGA给ESP32S2传输数据,一直传输,时钟为20MHZ,一次传输长度为1024BYTE,配置如下:
#define GPIO_MOSI GPIO_NUM_11
#define GPIO_MISO GPIO_NUM_13
#define GPIO_SCLK GPIO_NUM_12
#define GPIO_CS GPIO_NUM_10

#define RCV_HOST SPI3_HOST
#define DMA_CHAN RCV_HOST

spi_bus_config_t buscfg={
.mosi_io_num=GPIO_MOSI,
.miso_io_num=GPIO_MISO,
.sclk_io_num=GPIO_SCLK,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
};
spi_slave_interface_config_t slvcfg={
.mode=0,
.spics_io_num=GPIO_CS,
.queue_size=3,
.flags=0,
.post_setup_cb=my_post_setup_cb,
.post_trans_cb=my_post_trans_cb
};
gpio_set_pull_mode(GPIO_MOSI, GPIO_PULLDOWN_ONLY);
gpio_set_pull_mode(GPIO_SCLK, GPIO_PULLDOWN_ONLY);
gpio_set_pull_mode(GPIO_CS, GPIO_PULLUP_ONLY);

//Initialize SPI slave interface
spi_slave_initialize(RCV_HOST, &buscfg, &slvcfg, DMA_CHAN);

uint8_t cam_buf[1024]="";
uint8_t cam_buf2[1024]="";

int len = 1024*8;
spi_slave_transaction_t spi_recv;
spi_recv.length=len;
spi_recv.tx_buffer=cam_buf2;
spi_recv.rx_buffer=cam_buf;
gpio_set_level(ESP_RDY, 1);

配置完成后,在任务中循环执行
spi_slave_transmit(RCV_HOST, &spi_recv, portMAX_DELAY);
printf("rcv_size:%s\n",cam_buf);
另外:
void my_post_setup_cb(spi_slave_transaction_t *trans) {
gpio_set_level(ESP_RDY, 1);
}
void my_post_trans_cb(spi_slave_transaction_t *trans) {
gpio_set_level(ESP_RDY, 0);
}
FPGA那边发送数据正常,示波器测量波形正常,为什么打印出来的数据全部是0,这里面是哪个地方设置错了吗?
还有,CS的周期是550ns,1024个字节的话应该是550us左右才对,示波器测量到的ESP_RDY的周期有时候会连续很多个是28us,这个是什么意思呢?

djqlyy
Posts: 52
Joined: Wed Oct 23, 2019 12:46 am

Re: 请教一下SPI发送的问题

Postby djqlyy » Wed Mar 23, 2022 8:12 am

找到原因了,CS不能是一个字节使能一次,应该是1024个字节使能一次

Who is online

Users browsing this forum: No registered users and 51 guests