Advertisement
Guest User

Two SPI controllers

a guest
Mar 7th, 2022
17
250 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SmingCore.h>
  2. #include <Debug.h>
  3. #include <SPI.h>
  4.  
  5. #define SPI_MISO 4
  6. #define SPI_MOSI 16
  7. #define SPI_CLK 17
  8.  
  9. #define PIN_CARD_DO 14 /* Master In Slave Out */
  10. #define PIN_CARD_DI 13 /* Master Out Slave In */
  11. #define PIN_CARD_CK 12 /* Serial Clock */
  12.  
  13. #define SPI_FREQ_LIMIT 2000000
  14.  
  15. #define PIN_CARD_SS 27
  16. #define STM_CS 21
  17. #define PT100 15
  18.  
  19.  
  20. struct SpiPins spispi = {SPI_CLK, SPI_MISO, SPI_MOSI};
  21. struct SpiPins SDpins = {PIN_CARD_CK, PIN_CARD_DO, PIN_CARD_DI};
  22.  
  23. Timer spiTimer, spi2Timer;
  24.  
  25. SPIClass spi2;
  26.  
  27. void spi2f() {
  28.     spi2.beginTransaction(SPISettings(SPI_FREQ_LIMIT, MSBFIRST, SPI_MODE1));
  29.     Serial.printf("SPI2: %d\r\n", spi2.transfer(124));
  30.     spi2.endTransaction();
  31. }
  32.  
  33.  
  34. void spi1f() {
  35.     SPI.beginTransaction(SPISettings(SPI_FREQ_LIMIT, MSBFIRST, SPI_MODE1));
  36.     Serial.printf("SPI1: %d\r\n", SPI.transfer(5));
  37.     SPI.endTransaction();
  38. }
  39.  
  40. void init() {
  41.     Serial.begin(115200, SERIAL_8N1,
  42.                      SERIAL_FULL);
  43.     Debug.setDebug(Serial);
  44.     Debug.initCommand();
  45.     Serial.systemDebugOutput(true);
  46.     Serial.commandProcessing(true);
  47.  
  48.     pinMode(SPI_MISO, INPUT);
  49.     pinMode(PIN_CARD_DO, INPUT);
  50.     pinMode(SPI_MOSI, OUTPUT);
  51.  
  52.     SPI.setup(SpiBus::SPI2, spispi);
  53.     SPI.begin();
  54.  
  55.     spi2.setup(SpiBus::SPI3, SDpins);
  56.     spi2.begin();
  57.  
  58.     pinMode(PT100, OUTPUT);
  59.     digitalWrite(PT100, HIGH);
  60.  
  61.     pinMode(PIN_CARD_SS, OUTPUT);
  62.     digitalWrite(PIN_CARD_SS, HIGH);
  63.  
  64.     pinMode(STM_CS, OUTPUT);
  65.     digitalWrite(STM_CS, HIGH);
  66.  
  67.     spiTimer.initializeMs(1000, spi1f).start();
  68.     spi2Timer.initializeMs(1000, spi2f).start();
  69. }
Advertisement
RAW Paste Data Copied
Advertisement