Hi,
I have a question about ssel pin in SPI.
According to the Mbed OS 6 Document, It shows that only CS is config to DigitalOut.
It means that CS is controlled by GPIO, not by SPI right?
I think it may cost more latency during SPI transactions.
Can you help me how to config CS without DigitalOut API?
Hello MinHsuan_Wang
According to the Mbed API documentation for SPI you can use for that purpose the constructor with four arguments:
SPI | ( | PinName | mosi , |
---|---|---|---|
PinName | miso , | ||
PinName | sclk , | ||
PinName |
ssel = NC
|
||
) |
This constructor passes the SSEL pin selection to the target HAL. Not all targets support SSEL, so this cannot be relied on in portable code.
Parameters
mosi | SPI Master Out, Slave In pin. |
---|---|
miso | SPI Master In, Slave Out pin. |
sclk | SPI Clock pin. |
ssel | SPI Chip Select pin. |
To find out which pin can be used as Slave (Chip) Select
on STM targets open the corresponding PeripheralPins.c
file and search for PinMap_SPI_SSEL[]
. For example, in case of the NUCLEO-F446RE you can find the following array in the mbed-os/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F446xE/TARGET_NUCLEO_F446RE/PeripheralPins.c
:
...
MBED_WEAK const PinMap PinMap_SPI_SSEL[] = {
{PA_4, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)},
{PA_4_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)},
{PA_15, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)},
{PA_15_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)},
{PB_4, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF7_SPI2)},
{PB_9, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)},
{PB_12, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)},
{NC, NC, 0}
};
...
So if you’d like to use the SPI_1
peripheral then you can configure/initialize it as follows:
SPI spi(D11, D12, D13, PA_4); // mosi, miso, sclk, ssel
NOTE:
SSEL (Slave Select) = SS (Slave Select) = CS (Chip Select)