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.1KB

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