My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SPI.cpp 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
  3. * SPI Master library for arduino.
  4. *
  5. * This file is free software; you can redistribute it and/or modify
  6. * it under the terms of either the GNU General Public License version 2
  7. * or the GNU Lesser General Public License version 2.1, both as
  8. * published by the Free Software Foundation.
  9. */
  10. #include "pins_arduino.h"
  11. #include "SPI.h"
  12. SPIClass SPI;
  13. void SPIClass::begin() {
  14. // Set direction register for SCK and MOSI pin.
  15. // MISO pin automatically overrides to INPUT.
  16. // When the SS pin is set as OUTPUT, it can be used as
  17. // a general purpose output port (it doesn't influence
  18. // SPI operations).
  19. pinMode(SCK, OUTPUT);
  20. pinMode(MOSI, OUTPUT);
  21. pinMode(SS, OUTPUT);
  22. digitalWrite(SCK, LOW);
  23. digitalWrite(MOSI, LOW);
  24. digitalWrite(SS, HIGH);
  25. // Warning: if the SS pin ever becomes a LOW INPUT then SPI
  26. // automatically switches to Slave, so the data direction of
  27. // the SS pin MUST be kept as OUTPUT.
  28. SPCR |= _BV(MSTR);
  29. SPCR |= _BV(SPE);
  30. }
  31. void SPIClass::end() {
  32. SPCR &= ~_BV(SPE);
  33. }
  34. void SPIClass::setBitOrder(uint8_t bitOrder)
  35. {
  36. if(bitOrder == LSBFIRST) {
  37. SPCR |= _BV(DORD);
  38. } else {
  39. SPCR &= ~(_BV(DORD));
  40. }
  41. }
  42. void SPIClass::setDataMode(uint8_t mode)
  43. {
  44. SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
  45. }
  46. void SPIClass::setClockDivider(uint8_t rate)
  47. {
  48. SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK);
  49. SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((rate >> 2) & SPI_2XCLOCK_MASK);
  50. }