Bez popisu
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.

main.c 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //#define F_CPU 1000000UL // Frequenz des Quarzes, ohne Quarz standardmäßig 1MHz
  2. #include <avr/io.h>
  3. #include <util/delay.h>
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "nrf24l01.h"
  9. #include "nrf24l01_definitions.h"
  10. #include "uart_debug.h"
  11. //#define LED_DDR DDRB //DDRA, DDRB...
  12. //#define LED_PORT PORTB //PORTA, PORTB...
  13. //#define LED_PORTPIN PB0 //PA0, PA1..., PB0, PB1..., ...
  14. //#define time_off 8
  15. /* SPI: */
  16. #define SPI_DDR DDRB
  17. #define SPI_SCK_PIN PB1
  18. #define SPI_MOSI_PIN PB2
  19. #define SPI_MISO_PIN PB3
  20. /* NRF24L01 */
  21. /*
  22. * CS: pin 9
  23. * CE: pin 8
  24. * IRQ: pin 7
  25. */
  26. char bool_case = 0;
  27. int timer = 0;
  28. int timer_max = 0;
  29. void Initialize_SPI(void);
  30. int main (void)
  31. {
  32. char debugString[50] = "";
  33. // uint8_t testRegisterContent = 0x0A;
  34. // uint8_t registerContent[5];
  35. // char registerContentString[30];
  36. // uint8_t lengthRead;
  37. /* Set baud rate */
  38. Initialize_UART(51);
  39. sprintf(debugString, "%s\r\n", "Program start");
  40. Print_Debug_String(debugString);
  41. /* Initialize the SPI */
  42. Initialize_SPI();
  43. /* Initialize the nrf24l01 */
  44. Initialize_NRF24L01();
  45. // The NRF24L01 is now in the mode Standby-I.
  46. /* Configure the transmission parameters (Enhanced ShockBurst)*/
  47. Configure_Transmission();
  48. // sprintf(debugString, "%s\r\n", "program end");
  49. // Print_Debug_String(debugString);
  50. while(1)
  51. {
  52. Send_Test_Message();
  53. _delay_ms(1000);
  54. }
  55. }
  56. void Initialize_SPI(void)
  57. {
  58. /* Set MOSI and SCK output, all others input */
  59. SPI_DDR = (1<<SPI_MOSI_PIN)|(1<<SPI_SCK_PIN);
  60. /* Enable SPI, Master, set clock rate fck/16 */
  61. SPCR = (1<<SPE)|(1<<MSTR);
  62. }