从esp32-c3移植到s3后spi读取结果错误

zhangkhjy
Posts: 4
Joined: Fri Aug 11, 2023 3:08 am

从esp32-c3移植到s3后spi读取结果错误

Postby zhangkhjy » Thu May 09, 2024 7:44 am

做了hal层的接口调用spi功能,在esp32-c3上测试结果没有问题,但是到s3上读取的结果就错了
int HA_spi_read(spi_device_handle_t spi, uint8_t *data)
{
esp_err_t ret;
spi_transaction_t t;
uint8_t data1 = 0xFF;

memset(&t, 0, sizeof(t));
t.length = sizeof(uint8_t) * 8;
t.rxlength = sizeof(uint8_t) * 8;
t.rx_buffer = &data1;
ret = spi_device_polling_transmit(spi, &t);
assert( ret == ESP_OK );

*data = data1;

return 0;
}

void HA_Spi_Init(HA_SPI_CONFIG_T *spi_config, spi_device_handle_t *spi)
{
esp_err_t ret;
spi_bus_config_t buscfg;
spi_device_interface_config_t devcfg;

buscfg.miso_io_num = spi_config->spi_miso;
buscfg.mosi_io_num = spi_config->spi_mosi;
buscfg.sclk_io_num = spi_config->spi_clk;
buscfg.quadwp_io_num = -1;
buscfg.quadhd_io_num = -1;
buscfg.flags = SPICOMMON_BUSFLAG_MASTER;

devcfg.command_bits = 0;
devcfg.address_bits = 0;
devcfg.dummy_bits = 0;
devcfg.clock_speed_hz = 1000 * 1000; // Clock out at 10 MHz
devcfg.input_delay_ns = 0;
devcfg.duty_cycle_pos = 0;
devcfg.mode = 0; // SPI mode 0
devcfg.spics_io_num = -1; // CS pin
devcfg.queue_size = 6; //queue 7 transactions at a time

ret = spi_bus_initialize(SPI2_HOST, &buscfg, 0);
if (ret != ESP_OK){
ESP_LOGI(SPI_TAG, "bus initialize failed!\n");
}else{
ESP_LOGI(SPI_TAG, "bus initialize successed!\n");
}
ret = spi_bus_add_device(SPI2_HOST, &devcfg, spi);
if (ret != ESP_OK){
ESP_LOGI(SPI_TAG, "device config error\n");
}else{
ESP_LOGI(SPI_TAG, "device config success\n");
}
}
测了波形,发送的数据是对的,从机回的数据看波形是EF16也是对的,但是api返回的结果是F768
想可能是c3和s3的差异,查了sdkconfig,关于spi的设置也都是一样的,代码里配置的参数也都一样。
是spi_device_polling_transmit不适用s3吗,但是也找不到其他关于spi通信api的说明了,换了spi_device_transmit结果也是一样的

Who is online

Users browsing this forum: No registered users and 198 guests