Ingen beskrivning
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.9KB

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