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

main.c 1.7KB

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