1652 |
kaklik |
1 |
/* mija 2008 |
|
|
2 |
demo for RFM02 - TX 868MHz |
|
|
3 |
|
|
|
4 |
CPU ATMEGA16 |
|
|
5 |
fcpu = 1MHz |
|
|
6 |
|
|
|
7 |
!! define PIN,PORT,DDR for IOpin !! |
|
|
8 |
|
|
|
9 |
tested with module RFM12B RX 9600 BW 134kHz |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
#define F_CPU 1000000UL |
|
|
13 |
|
|
|
14 |
#include <avr/io.h> |
|
|
15 |
#include <util/delay.h> |
|
|
16 |
#include "RFM02.h" |
|
|
17 |
|
|
|
18 |
//************************************************************************ |
|
|
19 |
|
|
|
20 |
#define SDI PB3 |
|
|
21 |
#define SDI_PORT PORTB |
|
|
22 |
#define SDI_DDR DDRB |
|
|
23 |
|
|
|
24 |
#define FSK PC1 |
|
|
25 |
#define FSK_PORT PORTC |
|
|
26 |
#define FSK_DDR DDRC |
|
|
27 |
|
|
|
28 |
#define SCK_PORT PORTB |
|
|
29 |
#define SCK_DDR DDRB |
|
|
30 |
|
|
|
31 |
|
|
|
32 |
#define nIRQ_PORT PORTD |
|
|
33 |
#define nIRQ_DDR DDRD |
|
|
34 |
#define nIRQ_PIN PIND |
|
|
35 |
|
|
|
36 |
|
|
|
37 |
#define nSEL_PORT PORTB |
|
|
38 |
#define nSEL_DDR DDRB |
|
|
39 |
|
|
|
40 |
|
|
|
41 |
#define LED_PORT PORTC |
|
|
42 |
#define LED_DDR DDRC |
|
|
43 |
|
|
|
44 |
|
|
|
45 |
#define SDI_H SDI_PORT |= _BV(SDI) |
|
|
46 |
#define SDI_L SDI_PORT &= (~(_BV(SDI))) |
|
|
47 |
#define SDI_INIT SDI_DDR |= _BV(SDI) |
|
|
48 |
|
|
|
49 |
|
|
|
50 |
#define FSK_L FSK_PORT &= (~(_BV(FSK))) |
|
|
51 |
#define FSK_INIT FSK_DDR |= _BV(FSK) |
|
|
52 |
|
|
|
53 |
|
|
|
54 |
#define SDO_INIT SDO_DDR &= (~(_BV(SDO))) |
|
|
55 |
|
|
|
56 |
|
|
|
57 |
#define SCK_L SCK_PORT &= (~(_BV(SCK))) |
|
|
58 |
#define SCK_INIT SCK_DDR |= _BV(SCK) |
|
|
59 |
|
|
|
60 |
|
|
|
61 |
#define nIRQ_INIT nIRQ_DDR &= (~(_BV(nIRQ))) |
|
|
62 |
|
|
|
63 |
|
|
|
64 |
#define nSEL_L nSEL_PORT &= (~(_BV(nSEL))) |
|
|
65 |
#define nSEL_INIT nSEL_DDR |= _BV(nSEL) |
|
|
66 |
|
|
|
67 |
|
|
|
68 |
#define LED_L LED_PORT &= (~(_BV(LED))) |
|
|
69 |
#define LED_INIT LED_DDR |= _BV(LED) |
|
|
70 |
|
|
|
71 |
|
|
|
72 |
#define STOP_TX RF_WRITE_CMD(CMD_POWER|POWER_DC) |
|
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
uint8_t test[17]="\n\rATmega16\n\r ---"; |
|
|
78 |
//uint8_t test[16]="0123456789abcdef"; |
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
{ |
|
|
85 |
while(time--) _delay_ms(1); |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
|
|
|
89 |
{ |
|
|
90 |
SDI_INIT; |
|
|
91 |
SCK_INIT; |
|
|
92 |
nIRQ_INIT; |
|
|
93 |
nSEL_INIT; |
|
|
94 |
FSK_INIT; |
|
|
95 |
LED_INIT; |
|
|
96 |
} |
|
|
97 |
|
|
|
98 |
|
|
|
99 |
{ |
|
|
100 |
nSEL_H; |
|
|
101 |
SDI_H; |
|
|
102 |
SCK_L; |
|
|
103 |
nIRQ_INPUT; |
|
|
104 |
FSK_H; |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
|
|
|
108 |
{ |
|
|
109 |
uint8_t i; |
|
|
110 |
|
|
|
111 |
|
|
|
112 |
nSEL_L; |
|
|
113 |
for (i=0;i<16;i++) |
|
|
114 |
{ |
|
|
115 |
SCK_L; |
|
|
116 |
SCK_L; |
|
|
117 |
if (cmd & 0x8000) SDI_H; |
|
|
118 |
else SDI_L; |
|
|
119 |
SCK_H; |
|
|
120 |
SCK_H; |
|
|
121 |
cmd <<= 1; |
|
|
122 |
} |
|
|
123 |
SCK_L; |
|
|
124 |
nSEL_H; |
|
|
125 |
} |
|
|
126 |
|
|
|
127 |
|
|
|
128 |
{ |
|
|
129 |
uint8_t i; |
|
|
130 |
|
|
|
131 |
|
|
|
132 |
{ |
|
|
133 |
while (nIRQ_INPUT); |
|
|
134 |
while (!nIRQ_INPUT); |
|
|
135 |
if (data & 0x80)FSK_H; |
|
|
136 |
else FSK_L; |
|
|
137 |
data <<= 1; |
|
|
138 |
} |
|
|
139 |
} |
|
|
140 |
|
|
|
141 |
|
|
|
142 |
{ |
|
|
143 |
uint8_t i,j,ChkSum; |
|
|
144 |
|
|
|
145 |
|
|
|
146 |
RF_INIT(); |
|
|
147 |
LED_H; |
|
|
148 |
delay_ms(100); |
|
|
149 |
|
|
|
150 |
|
|
|
151 |
RF_WRITE_CMD(CMD_SETTING |BAND_868 |C_12pF |TX_DEV_90); |
|
|
152 |
RF_WRITE_CMD(CMD_FREQUENCY |FREQUENCY_868); |
|
|
153 |
RF_WRITE_CMD(0xD040); |
|
|
154 |
RF_WRITE_CMD(CMD_RATE |RATE_9600); |
|
|
155 |
RF_WRITE_CMD(CMD_BATTERY |TX_EBS); |
|
|
156 |
RF_WRITE_CMD(CMD_POWER |POWER_DC); |
|
|
157 |
RF_WRITE_CMD(POWER_OUT_0); |
|
|
158 |
|
|
|
159 |
|
|
|
160 |
while (1) |
|
|
161 |
{ |
|
|
162 |
LED_H; |
|
|
163 |
|
|
|
164 |
|
|
|
165 |
ChkSum = 0; |
|
|
166 |
for (i=0;i<3;i++) RF_WRITE_DATA(0xAA); |
|
|
167 |
RF_WRITE_DATA(0x2D); |
|
|
168 |
RF_WRITE_DATA(0xD4); |
|
|
169 |
|
|
|
170 |
|
|
|
171 |
{ |
|
|
172 |
RF_WRITE_DATA(test[i]); |
|
|
173 |
ChkSum += test[i]; |
|
|
174 |
} |
|
|
175 |
RF_WRITE_DATA(ChkSum); |
|
|
176 |
RF_WRITE_DATA(0xAA); |
|
|
177 |
RF_WRITE_DATA(0xAA); |
|
|
178 |
STOP_TX; |
|
|
179 |
|
|
|
180 |
|
|
|
181 |
delay_ms(500); |
|
|
182 |
j++; |
|
|
183 |
test[13]=(j/100)+0x30; |
|
|
184 |
test[14]=((j%100)/10)+0x30; |
|
|
185 |
test[15]=((j%100)%10)+0x30; |
|
|
186 |
} |
|
|
187 |
return 0; |
|
|
188 |
} |
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
|