You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: API.md
+1-95Lines changed: 1 addition & 95 deletions
Original file line number
Diff line number
Diff line change
@@ -327,101 +327,7 @@ This part describes the STM32 libraries provided with the core.
327
327
328
328
## SPI
329
329
330
-
STM32 SPI library has been modified with the possibility to manage several CS pins without to stop the SPI interface.
331
-
_We do not describe here the [SPI Arduino API](https://www.arduino.cc/en/Reference/SPI) but the functionalities added._
332
-
333
-
We give to the user 3 possibilities about the management of the CS pin:
334
-
* the CS pin is managed directly by the user code before to transfer the data (like the Arduino SPI library)
335
-
* or the user gives the CS pin number to the library API and the library manages itself the CS pin (see example below)
336
-
* or the user uses a hardware CS pin linked to the SPI peripheral
337
-
338
-
### New API functions
339
-
340
-
*`SPIClass::SPIClass(uint8_t mosi, uint8_t miso, uint8_t sclk, uint8_t ssel)`: alternative class constructor
341
-
_Params_ SPI `mosi` pin
342
-
_Params_ SPI `miso` pin
343
-
_Params_ SPI `sclk` pin
344
-
_Params_ (optional) SPI `ssel` pin. This pin must be an hardware CS pin. If you configure this pin, the chip select will be managed by the SPI peripheral. Do not use API functions with CS pin in parameter.
345
-
346
-
*`void SPIClass::begin(uint8_t _pin)`: initialize the SPI interface and add a CS pin
347
-
_Params_ SPI CS `pin` to be managed by the SPI library
348
-
349
-
*`void beginTransaction(uint8_t pin, SPISettings settings)`: allows to configure the SPI with other parameter. These new parameter are saved this an associated CS pin.
350
-
_Params_ SPI CS `pin` to be managed by the SPI library
351
-
_Params_ SPI `settings`
352
-
353
-
*`void endTransaction(uint8_t pin)`: removes a CS pin and the SPI settings associated
354
-
_Params_ SPI CS `pin` managed by the SPI library
355
-
356
-
**_Note 1_** The following functions must be called after initialization of the SPI instance with `begin()` or `beginTransaction()`.
357
-
If you have several device to manage, you can call `beginTransaction()` several time with different CS pin in parameter.
358
-
Then you can call the following functions with different CS pin without call again `beginTransaction()` (until you call `end()` or `endTransaction()`).
359
-
360
-
**_Note 2_** If the mode is set to `SPI_CONTINUE`, the CS pin is kept enabled. Be careful in case you use several CS pin.
_Params_ (optional) if `SPI_LAST``mode` the CS pin is reset, `SPI_CONTINUE``mode` the CS pin is kept enabled.
372
-
_Return_ 16 bits data received
373
-
374
-
*`void transfer(uint8_t pin, void *_buf, size_t _count, SPITransferMode _mode = SPI_LAST)`: write/read several bytes. Only one buffer used to write and read the data
375
-
_Params_ SPI CS `pin` managed by the SPI library
376
-
_Params_ pointer to `data` to write. The `data` will be replaced by the data read.
377
-
_Params_`count` is number of data to write/read.
378
-
_Params_ (optional) if `SPI_LAST``mode` the CS pin is reset, `SPI_CONTINUE``mode` the CS pin is kept enabled.
379
-
380
-
*`void transfer(byte _pin, void *_bufout, void *_bufin, size_t _count, SPITransferMode _mode = SPI_LAST)`: write/read several bytes. One buffer for the output data and one for the input data
381
-
_Params_ SPI CS `pin` managed by the SPI library
382
-
_Params_`_bufout` is pointer to data to write.
383
-
_Params_`_bufin` id pointer where to store the data read.
384
-
_Params_`count` is number of data to write/read.
385
-
_Params_ (optional) if `SPI_LAST``mode` the CS pin is reset, `SPI_CONTINUE``mode` the CS pin is kept enabled.
386
-
387
-
##### Example
388
-
389
-
This is an example of the use of the CS pin management:
390
-
391
-
```C++
392
-
#include<SPI.h>
393
-
// MOSI MISO SCLK
394
-
SPIClass SPI_3(PC12, PC11, PC10);
395
-
396
-
void setup() {
397
-
SPI_3.begin(2); //Enables the SPI_3 instance with default settings and attaches the CS pin
398
-
SPI_3.beginTransaction(1, settings); //Attaches another CS pin and configure the SPI_3 instance with other settings
399
-
SPI_3.transfer(2, 0x52); //Transfers data to the first device
400
-
SPI_3.transfer(1, 0xA4); //Transfers data to the second device. The SPI_3 instance is configured with the right settings
401
-
SPI_3.end() //SPI_3 instance is disabled
402
-
}
403
-
```
404
-
405
-
#### Change default `SPI` instance pins
406
-
It is also possible to change the default pins used by the `SPI` instance using above API:
407
-
408
-
[[/img/Warning-icon.png|alt="Warning"]] **Have to be called before `begin()`.**
409
-
410
-
* `void setMISO(uint32_t miso)`
411
-
* `void setMOSI(uint32_t mosi)`
412
-
* `void setSCLK(uint32_t sclk)`
413
-
* `void setSSEL(uint32_t ssel)`
414
-
* `void setMISO(PinName miso)`
415
-
* `void setMOSI(PinName mosi)`
416
-
* `void setSCLK(PinName sclk)`
417
-
* `void setSSEL(PinName ssel)`
418
-
419
-
##### Example:
420
-
```C++
421
-
SPI.setMISO(PC_4); // using pin name PY_n
422
-
SPI.setMOSI(PC2); // using pin number PYn
423
-
SPI.begin(2);
424
-
```
330
+
See [`SPI README.md`](../blob/main/libraries/SPI/README.md)
0 commit comments