| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include <avr/io.h>
- #include <util/delay.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include "nrf24l01.h"
- #include "nrf24l01_definitions.h"
- #include "bme280_interface.h"
- #include "bme280_defs.h"
- #include "uart_debug.h"
-
- //#define LED_DDR DDRB //DDRA, DDRB...
- //#define LED_PORT PORTB //PORTA, PORTB...
- //#define LED_PORTPIN PB0 //PA0, PA1..., PB0, PB1..., ...
- //#define time_off 8
-
- /* SPI: */
- #define SPI_DDR DDRB
- #define SPI_SCK_PIN PB1
- #define SPI_MOSI_PIN PB2
- #define SPI_MISO_PIN PB3
-
- /* NRF24L01 */
-
-
-
- /*
- * CS: pin 9
- * CE: pin 8
- * IRQ: pin 7
- */
-
-
-
- char bool_case = 0;
- int timer = 0;
- int timer_max = 0;
-
-
- void Initialize_SPI(void);
-
- int main (void)
- {
- char debugString[50] = "";
- struct bme280_data sensorData;
- // uint8_t testRegisterContent = 0x0A;
- // uint8_t registerContent[5];
- // char registerContentString[30];
- // uint8_t lengthRead;
-
- /* Set baud rate */
- Initialize_UART(51);
-
- sprintf(debugString, "%s\r\n", "Program start");
- Print_Debug_String(debugString);
-
- /* Initialize the SPI */
- Initialize_SPI();
-
- /* Initialize the nrf24l01 */
- Initialize_NRF24L01();
- // The NRF24L01 is now in the mode Standby-I.
-
- /* Configure the transmission parameters (Enhanced ShockBurst)*/
- Configure_Transmission();
-
- /* Initialize the BME280 */
- Initialize_BME280();
-
-
- #if 0
- /* Test the BME280 by reading the ID */
- uint8_t id = Read_BME280_Register(0xD0);
- sprintf(debugString, "ID: 0x%x\r\n", id);
- Print_Debug_String(debugString);
- #endif
-
-
-
-
-
- // sprintf(debugString, "%s\r\n", "program end");
- // Print_Debug_String(debugString);
-
- while(1)
- {
- BME280_Get_Measurement(&sensorData);
- NRF24L01_Send_Message((uint8_t*)&sensorData, sizeof(sensorData));
- _delay_ms(1000);
- }
- }
-
- void Initialize_SPI(void)
- {
- /* Set MOSI and SCK output, all others input */
- SPI_DDR = (1<<SPI_MOSI_PIN)|(1<<SPI_SCK_PIN);
- /* Enable SPI, Master, set clock rate fck/16 */
- SPCR = (1<<SPE)|(1<<MSTR);
- }
|