Naze32 clone with Frysky receiver
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

spi.c 868B

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