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 800B

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