Naze32 clone with Frysky receiver
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

spi.c 914B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Bit-Banged SPI routines
  3. */
  4. //#define DEBUG_SLOW_SPI_TRAFFIC
  5. #include "spi.h"
  6. void spiInit(void) {
  7. #if !defined(__AVR__)
  8. gpioInit();
  9. #endif
  10. MI_dir;
  11. MO_dir;
  12. SCK_dir;
  13. CS_dir;
  14. SCK_off;
  15. MO_off;
  16. CS_on;
  17. }
  18. uint8_t spiReadWrite(uint8_t command) {
  19. SCK_off;
  20. MO_off;
  21. uint8_t result = 0;
  22. for (uint8_t i = 0; i < 8; i++) {
  23. if (command & 0x80) {
  24. MO_on;
  25. } else {
  26. MO_off;
  27. }
  28. command = command << 1;
  29. if (MI_1) {
  30. result = (result << 1) | 0x01;
  31. } else {
  32. result = result << 1;
  33. }
  34. SCK_on;
  35. NOP();
  36. #ifdef DEBUG_SLOW_SPI_TRAFFIC
  37. NOP();
  38. NOP();
  39. NOP();
  40. NOP();
  41. #endif
  42. SCK_off;
  43. NOP();
  44. #ifdef DEBUG_SLOW_SPI_TRAFFIC
  45. NOP();
  46. NOP();
  47. NOP();
  48. NOP();
  49. #endif
  50. }
  51. return result;
  52. }