RTThread的spi rt_spi_send_then_recv API 与HAl库的HAL_SPI_TransmitReceive使用是一样的吗
我使用RTTread的spiAPI rt_spi_send_then_recv(ble_spi, &header_master, HEADER_SIZE, &header_slave, HEADER_SIZE);发送一个header,同时收到的回复是:0x04ff030100,即从机芯片的异常返回
将对应的API换成 HAL_SPI_TransmitReceive(&hspi1, header_master, header_slave, HEADER_SIZE, BUS_SPI1_POLL_TIMEOUT);,同时收到的回复是: 0xff09010600, 即正确的数据大小约定包
我的SPI初始化代码如下:
/* SPI -----------------------------------------------*/
#define SPI_DEVICE_NAME "spi10" /* SPI 设备名称 */
struct rt_spi_device *ble_spi = RT_NULL;
ble_spi = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
if(RT_NULL == ble_spi)
{
rt_kprintf("Failed to malloc the spi device.");
return -RT_ENOMEM;
}
if (RT_EOK != rt_spi_bus_attach_device(ble_spi, "spi10", "spi1", RT_NULL))
{
rt_kprintf("Failed to attach the spi device.");
return -RT_ERROR;
}
/* spi设备配置 */
struct rt_spi_configuration cfg;
cfg.data_width = 8;
cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_1 | RT_SPI_MSB; // CPOL 0 CPHA 1
cfg.max_hz = 1 * 1000 * 1000; /* 1M */
if (RT_EOK != rt_spi_configure(ble_spi, &cfg)) {
rt_kprintf("Failed to config the spi device.");
return -RT_ERROR;
}
配置的数据位宽 工作模式 和频率应该都是没有问题的(否则应该不能准确收到异常返回0x04ff030100)
我点开rt_spi_send_then_recv 的源码看着好复杂,
这个API在发送的工作上和HAL_SPI_TransmitReceive有什么时序的区别吗
更多回帖