浏览代码

Move SPI initialization and pin definitions to spi.c

Bernd Gottschlag 5 年前
父节点
当前提交
f1b0ebf618
共有 3 个文件被更改,包括 18 次插入17 次删除
  1. 1
    16
      weather-sensor/firmware/main.c
  2. 16
    1
      weather-sensor/firmware/spi.c
  3. 1
    0
      weather-sensor/firmware/spi.h

+ 1
- 16
weather-sensor/firmware/main.c 查看文件

7
 #include <stdlib.h>
7
 #include <stdlib.h>
8
 #include <string.h>
8
 #include <string.h>
9
 
9
 
10
+#include "spi.h"
10
 #include "nrf24l01.h"
11
 #include "nrf24l01.h"
11
 #include "nrf24l01_definitions.h"
12
 #include "nrf24l01_definitions.h"
12
 #include "bme280_interface.h"
13
 #include "bme280_interface.h"
13
 #include "bme280_defs.h"
14
 #include "bme280_defs.h"
14
 
15
 
15
 
16
 
16
-/* SPI: */
17
-/* TODO: move to spi.h */
18
-#define SPI_DDR       DDRB
19
-#define SPI_SCK_PIN   PB5
20
-#define SPI_MOSI_PIN  PB3
21
-#define SPI_MISO_PIN  PB4
22
 
17
 
23
 /* Debug LED: */
18
 /* Debug LED: */
24
 #define LED_DDR   DDRD
19
 #define LED_DDR   DDRD
36
 volatile uint8_t executionFlag;
31
 volatile uint8_t executionFlag;
37
 
32
 
38
 
33
 
39
-void Initialize_SPI(void);
40
 void Enter_Power_Save_Mode(void);
34
 void Enter_Power_Save_Mode(void);
41
 void Exit_Power_Save_Mode(void);
35
 void Exit_Power_Save_Mode(void);
42
 
36
 
129
 	}
123
 	}
130
 }
124
 }
131
 
125
 
132
-void Initialize_SPI(void)
133
-{
134
-	/* TODO: move to spi.h */
135
-	/* Set MOSI and SCK output, all others input */
136
-	SPI_DDR = (1<<SPI_MOSI_PIN)|(1<<SPI_SCK_PIN);
137
-	/* Enable SPI, Master, set clock rate fck/16 */
138
-	SPCR = (1<<SPE)|(1<<MSTR);
139
-}
140
-
141
 void Set_Up_Power_Save_Mode(void)
126
 void Set_Up_Power_Save_Mode(void)
142
 {
127
 {
143
 	// Disable Brown-Out-Detection by setting the BODLEVEL 2:0 Fuses to 0b111 (should be default)
128
 	// Disable Brown-Out-Detection by setting the BODLEVEL 2:0 Fuses to 0b111 (should be default)

+ 16
- 1
weather-sensor/firmware/spi.c 查看文件

1
 #include <avr/io.h>
1
 #include <avr/io.h>
2
 
2
 
3
+/* Pin Definitions: */
4
+#define SPI_DDR       DDRB
5
+#define SPI_SCK_PIN   PB5
6
+#define SPI_MOSI_PIN  PB3
7
+#define SPI_MISO_PIN  PB4
8
+
9
+
10
+void Initialize_SPI(void)
11
+{
12
+	/* Set MOSI and SCK output, all others input */
13
+	SPI_DDR = (1<<SPI_MOSI_PIN)|(1<<SPI_SCK_PIN);
14
+	/* Enable SPI, Master, set clock rate fck/16 */
15
+	SPCR = (1<<SPE)|(1<<MSTR);
16
+}
17
+
3
 void SPI_Start_Transmission(volatile uint8_t *port, uint8_t pinNumber)
18
 void SPI_Start_Transmission(volatile uint8_t *port, uint8_t pinNumber)
4
 {
19
 {
5
 	*port &= ~(1<<pinNumber);
20
 	*port &= ~(1<<pinNumber);
14
 
29
 
15
 void SPI_Stop_Transmission(volatile uint8_t *port, uint8_t pinNumber)
30
 void SPI_Stop_Transmission(volatile uint8_t *port, uint8_t pinNumber)
16
 {
31
 {
17
-	*port |= (1<<pinNumber); // Stop the transmission
32
+	*port |= (1<<pinNumber);
18
 }
33
 }

+ 1
- 0
weather-sensor/firmware/spi.h 查看文件

1
 #ifndef SPI_H
1
 #ifndef SPI_H
2
 #define SPI_H
2
 #define SPI_H
3
 
3
 
4
+void Initialize_SPI(void);
4
 void SPI_Start_Transmission(volatile uint8_t *port, uint8_t pinNumber);
5
 void SPI_Start_Transmission(volatile uint8_t *port, uint8_t pinNumber);
5
 uint8_t SPI_Transfer_Byte(uint8_t byte);
6
 uint8_t SPI_Transfer_Byte(uint8_t byte);
6
 void SPI_Stop_Transmission(volatile uint8_t *port, uint8_t pinNumber);
7
 void SPI_Stop_Transmission(volatile uint8_t *port, uint8_t pinNumber);

正在加载...
取消
保存