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.

cc2500.c 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * CC2500 helper routines
  3. */
  4. #include <util/delay.h>
  5. #include "spi.h"
  6. #include "cc2500.h"
  7. void cc2500ReadFifo(uint8_t *dpbuffer, int len) {
  8. cc2500ReadRegisterMulti(CC2500_3F_RXFIFO | CC2500_READ_BURST, dpbuffer, len);
  9. }
  10. void cc2500ReadRegisterMulti(uint8_t address, uint8_t data[], uint8_t length) {
  11. CS_off;
  12. spiWrite(address);
  13. for (uint8_t i = 0; i < length; i++) {
  14. data[i] = spiRead();
  15. }
  16. CS_on;
  17. }
  18. void cc2500WriteRegisterMulti(uint8_t address, const uint8_t data[], uint8_t length) {
  19. CS_off;
  20. spiWrite(CC2500_WRITE_BURST | address);
  21. for (uint8_t i = 0; i < length; i++) {
  22. spiWrite(data[i]);
  23. }
  24. CS_on;
  25. }
  26. void cc2500WriteFifo(uint8_t *dpbuffer, uint8_t len) {
  27. cc2500Strobe(CC2500_SFTX); // 0x3B
  28. cc2500WriteRegisterMulti(CC2500_3F_TXFIFO, dpbuffer, len);
  29. cc2500Strobe(CC2500_STX); // 0x35
  30. }
  31. void cc2500WriteReg(uint8_t address, uint8_t data) {
  32. CS_off;
  33. spiWrite(address);
  34. NOP();
  35. spiWrite(data);
  36. CS_on;
  37. }
  38. uint8_t cc2500ReadReg(uint8_t address) {
  39. uint8_t result;
  40. CS_off;
  41. address |= 0x80; // bit 7 =1 for reading
  42. spiWrite(address);
  43. result = spiRead();
  44. CS_on;
  45. return result;
  46. }
  47. void cc2500Strobe(uint8_t address) {
  48. CS_off;
  49. spiWrite(address);
  50. CS_on;
  51. }
  52. void cc2500ResetChip(void) {
  53. // Toggle chip select signal
  54. CS_on;
  55. _delay_us(30);
  56. CS_off;
  57. _delay_us(30);
  58. CS_on;
  59. _delay_us(45);
  60. cc2500Strobe(CC2500_SRES);
  61. _delay_ms(100);
  62. }