-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.c
114 lines (92 loc) · 2.37 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stm32f4xx.h>
#include <stm32f4_discovery.h>
#include "nRF24L01.h"
#include <stdio.h>
#include <string.h>
// ñ÷åò÷èê
static __IO uint32_t TimingDelay;
// ïðîòîòèïû
void Delay(__IO uint32_t nTime);
void TimingDelay_Decrement(void);
nRF24L01_STATUS_REGISTER status_reg;
/* My address */
uint8_t MyAddress[] = {
0xE7,
0xE7,
0xE7,
0xE7,
0xE7
};
/* Receiver address */
uint8_t TxAddress[] = {
0x7E,
0x7E,
0x7E,
0x7E,
0x7E
};
void main(void){
// 0.001 ñ = 1/1000 ñ = 1ìñ
if (SysTick_Config(SystemCoreClock / 1000)){
/* åñëè âåðíóëñÿ íå íîëü - îøèáêà */
while (1);
}
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
STM_EVAL_LEDInit(LED5);
STM_EVAL_LEDInit(LED6);
nRF24L01_init();
nRF24L01_set_rf(nRF24L01_DataRate_2M, nRF24L01_OutputPower_M18dBm);
// óñòàíàâëèâàåì àäðåñà ïðèåìíèêà è ïåðåäàò÷èêà
nRF24L01_set_my_addr(MyAddress);
nRF24L01_set_tx_addr(TxAddress);
u8 str[32] = "Hello blablacode.ru by nRF24\n";
u8 dataIn[32];
u16 req = 0;
u16 badTransactions = 0;
u16 successfulTransactions = 0;
while (1) {
status_reg = nRF24L01_readStatus();
STM_EVAL_LEDToggle(LED3);
nRF24L01_writeTx(str);
do {
status_reg = nRF24L01_readStatus();
} while (status_reg.bit.MAX_RT == 0 && status_reg.bit.TX_DS == 0);
nRF24L01_ClearStatus();
nRF24L01_configure_rx();
do {
status_reg = nRF24L01_readStatus();
req++;
if (req > 1000)
{
req = 0;
break;
}
} while (status_reg.bit.RX_DR == 0);
if (status_reg.bit.RX_DR)
{
// ÷èñòèì áóôåð
memset(dataIn,0,32);
// ÷èòàåì
nRF24L01_readRx(dataIn,32);
// ñðàâíèâàåì
int ret = memcmp(dataIn,str,32);
if (ret == 0)
successfulTransactions++;
else
badTransactions++;
}
status_reg = nRF24L01_readStatus();
}
}
/* ôóíêöèÿ çàäåðæêè */
void Delay(__IO uint32_t nTime){
TimingDelay = nTime;
while(TimingDelay != 0);
}
/* äåêðåìåíò çíà÷åíèÿ ñ÷åò÷èêà çàäåðæêè, åñëè îí íå ðàâåí íóëþ */
void TimingDelay_Decrement(void){
if (TimingDelay != 0x00){
TimingDelay--;
}
}