SPI
概述
串行外设接口(Serial Peripheral Interface Bus, SPI)是一种用于短程通信的同步串行通信接口规范,装置之间使用全双工模式通信,是一个主机和一个或多个从机的主从模式。需要至 少4根线,事实上3根也可以(单向传输时),包括SDI(数据输入)、SDO(数据输出)、SCLK(时钟)、CS(片选)
注解
spi更多资料请参考 BL602参考手册 。
应用实例
串口实例: customer_app/peripheral/demo_spi
。
API参考
Header File
- components/platform/hosal/include/hosal_spi.h
Functions
-
int
hosal_spi_init
(hosal_spi_dev_t *spi) Initialises the SPI interface for a given SPI device.
- Return
- 0 : on success
- other : error
- Parameters
spi
: the spi device
-
int
hosal_spi_send
(hosal_spi_dev_t *spi, const uint8_t *data, uint16_t size, uint32_t timeout) Spi send.
- Return
- 0 : on success
- other : error
- Parameters
spi
: the spi devicedata
: spi send datasize
: spi send data sizetimeout
: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever
-
int
hosal_spi_recv
(hosal_spi_dev_t *spi, uint8_t *data, uint16_t size, uint32_t timeout) Spi recv.
- Return
- 0 : success
- other : error
- Parameters
spi
: the spi devicedata
: spi recv datasize
: spi recv data sizetimeout
: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever
-
int
hosal_spi_send_recv
(hosal_spi_dev_t *spi, uint8_t *tx_data, uint8_t *rx_data, uint16_t size, uint32_t timeout) spi send data and recv
- Return
- 0 : success
- other : error
- Parameters
spi
: the spi devicetx_data
: spi send datarx_data
: spi recv datasize
: spi data to be sent and recivedtimeout
: timeout in milisecond, set this value to HAL_WAIT_FOREVER if you want to wait forever
-
int
hosal_spi_irq_callback_set
(hosal_spi_dev_t *spi, hosal_spi_irq_t pfn, void *p_arg)
-
int
hosal_spi_set_cs
(uint8_t pin, uint8_t value) spi software set cs pin high/low only for master device
- Return
- 0 : success
- other : error
- Parameters
pin
: cs pinvalue
: 0 or 1
-
int
hosal_spi_finalize
(hosal_spi_dev_t *spi) De-initialises a SPI interface.
- Return
- 0 : success
- other : error
- Parameters
spi
: the SPI device to be de-initialised
Structures
-
struct
hosal_spi_config_t
Define spi config args.
-
struct
hosal_spi_dev_t
Define spi dev handle.
Public Members
-
uint8_t
port
spi port
-
hosal_spi_config_t
config
spi config
-
hosal_spi_irq_t
cb
spi interrupt callback
-
void *
p_arg
arg pass to callback
-
void *
priv
priv data
-
uint8_t