Naze32 clone with Frysky receiver
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

cc2500_BB_SPI.ino 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //-------------------------------
  2. //-------------------------------
  3. //CC2500 SPI routines
  4. //-------------------------------
  5. //-------------------------------
  6. #include <util/delay.h>
  7. void cc2500_readFifo(uint8_t *dpbuffer, int len)
  8. {
  9. ReadRegisterMulti(CC2500_3F_RXFIFO | CC2500_READ_BURST, dpbuffer, len);
  10. }
  11. //----------------------
  12. static void ReadRegisterMulti(uint8_t address, uint8_t data[], uint8_t length)
  13. {
  14. unsigned char i;
  15. CS_off;
  16. _spi_write(address);
  17. for (i = 0; i < length; i++) {
  18. data[i] = _spi_read();
  19. }
  20. CS_on;
  21. }
  22. //*********************************************
  23. void CC2500_WriteRegisterMulti(uint8_t address, const uint8_t data[], uint8_t length)
  24. {
  25. CS_off;
  26. _spi_write(CC2500_WRITE_BURST | address);
  27. for (int i = 0; i < length; i++) {
  28. _spi_write(data[i]);
  29. }
  30. CS_on;
  31. }
  32. void cc2500_writeFifo(uint8_t *dpbuffer, uint8_t len)
  33. {
  34. cc2500_strobe(CC2500_SFTX);//0x3B
  35. CC2500_WriteRegisterMulti(CC2500_3F_TXFIFO, dpbuffer, len);
  36. cc2500_strobe(CC2500_STX);//0x35
  37. }
  38. //--------------------------------------
  39. void _spi_write(uint8_t command)
  40. {
  41. uint8_t n = 8;
  42. SCK_off;//SCK start low
  43. MO_off;
  44. while (n--) {
  45. if (command & 0x80)
  46. MO_on;
  47. else
  48. MO_off;
  49. SCK_on;
  50. NOP();
  51. SCK_off;
  52. command = command << 1;
  53. }
  54. MO_on;
  55. }
  56. //----------------------------
  57. void cc2500_writeReg(uint8_t address, uint8_t data) //same as 7105
  58. {
  59. CS_off;
  60. _spi_write(address);
  61. NOP();
  62. _spi_write(data);
  63. CS_on;
  64. }
  65. uint8_t _spi_read(void)
  66. {
  67. uint8_t result;
  68. uint8_t i;
  69. result = 0;
  70. for (i = 0; i < 8; i++) {
  71. if (MI_1) ///
  72. result = (result << 1) | 0x01;
  73. else
  74. result = result << 1;
  75. SCK_on;
  76. NOP();
  77. SCK_off;
  78. NOP();
  79. }
  80. return result;
  81. }
  82. //--------------------------------------------
  83. unsigned char cc2500_readReg(unsigned char address)
  84. {
  85. uint8_t result;
  86. CS_off;
  87. address |= 0x80; //bit 7 =1 for reading
  88. _spi_write(address);
  89. result = _spi_read();
  90. CS_on;
  91. return (result);
  92. }
  93. //------------------------
  94. void cc2500_strobe(uint8_t address)
  95. {
  96. CS_off;
  97. _spi_write(address);
  98. CS_on;
  99. }
  100. //------------------------
  101. void cc2500_resetChip(void)
  102. {
  103. // Toggle chip select signal
  104. CS_on;
  105. _delay_us(30);
  106. CS_off;
  107. _delay_us(30);
  108. CS_on;
  109. _delay_us(45);
  110. cc2500_strobe(CC2500_SRES);
  111. _delay_ms(100);
  112. }