Line 35... |
Line 35... |
35 |
|
35 |
|
36 |
#define RF_PORT PORTB |
36 |
#define RF_PORT PORTB |
37 |
#define RF_DDR DDRB |
37 |
#define RF_DDR DDRB |
38 |
#define RF_PIN PINB |
38 |
#define RF_PIN PINB |
39 |
|
39 |
|
40 |
#define LED_PORT PORTD |
- |
|
41 |
#define LED_DDR DDRD |
- |
|
42 |
#define LED_PIN PIND |
- |
|
43 |
|
- |
|
44 |
#define LED0 4 -- PD4 |
- |
|
45 |
#define LED1 2 -- PD2 |
- |
|
46 |
|
- |
|
47 |
#define SDI 0 // SDI, -> RF02 Atmega PB0 Arduino 8 |
40 |
#define SDI 0 // SDI, -> RF02 Atmega PB0 Arduino 8 |
48 |
#define SCK 1 // SCK, -> RF02 Atmega PB1 Arduino 9 |
41 |
#define SCK 1 // SCK, -> RF02 Atmega PB1 Arduino 9 |
49 |
#define CS 2 // nSEL, -> RF02 Atmega PB2 Arduino 10 |
42 |
#define CS 2 // nSEL, -> RF02 Atmega PB2 Arduino 10 |
50 |
#define IRQ 4 // nIRQ, <- RF02 Atmega PB4 Arduino 12 |
43 |
#define IRQ 4 // nIRQ, <- RF02 Atmega PB4 Arduino 12 |
- |
|
44 |
#define FSK 3 // FSK, <- RF02 Atmega PB3 Arduino ??? |
51 |
//------------------// FSK: Pullupto VCC |
45 |
//------------------// FSK: Pullupto VCC |
52 |
|
46 |
|
53 |
#ifndef cbi |
47 |
#ifndef cbi |
54 |
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) |
48 |
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) |
55 |
#endif |
49 |
#endif |
56 |
#ifndef sbi |
50 |
#ifndef sbi |
57 |
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) |
51 |
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) |
58 |
#endif |
52 |
#endif |
59 |
|
53 |
|
60 |
#ifndef cLED0 |
- |
|
61 |
#define cLED0() (LED_PORT &= ~(1<<LED0)) |
- |
|
62 |
#endif |
- |
|
63 |
#ifndef sLED0 |
- |
|
64 |
#define sLED0() (LED_PORT |= (1<<LED0) ) |
- |
|
65 |
#endif |
- |
|
66 |
|
- |
|
67 |
#ifndef cLED1 |
- |
|
68 |
#define cLED1() (LED_PORT &= ~(1<<LED1)) |
- |
|
69 |
#endif |
- |
|
70 |
#ifndef sLED1 |
- |
|
71 |
#define sLED1() (LED_PORT |= (1<<LED1) ) |
- |
|
72 |
#endif |
- |
|
73 |
|
- |
|
74 |
|
- |
|
75 |
|
54 |
|
76 |
unsigned char test[32]=" 55555 \n"; |
55 |
unsigned char test[32]=" 55555 \n"; |
77 |
|
56 |
|
78 |
void rf02_changeText( unsigned char* ptr, uint8_t number){ |
57 |
void rf02_changeText( unsigned char* ptr, uint8_t number) |
- |
|
58 |
{ |
79 |
|
59 |
|
80 |
if (number> 32)number = 32; |
60 |
if (number> 32)number = 32; |
81 |
memcpy( test, ptr, number); |
61 |
memcpy( test, ptr, number); |
82 |
|
62 |
|
83 |
} |
63 |
} |
84 |
|
64 |
|
85 |
void rf02_prepAll434(){ |
65 |
void rf02_prepAll() |
86 |
|
66 |
{ |
87 |
rf02_init(); // ein paar Register setzen (z.B. CLK auf 10MHz) |
- |
|
88 |
rf02_setfreq(RF02FREQ(434)); // 433,92MHz |
67 |
RF_PORT=(1<<CS); |
89 |
rf02_setpower(1); // -12dBm Ausgangangsleistung |
- |
|
90 |
rf02_setmodfreq(3); // 120kHz Frequenzshift |
- |
|
91 |
rf02_setbaud(19200); // 19200 Baud |
68 |
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS); |
92 |
|
69 |
|
93 |
}// |
70 |
sbi(RF_PORT, FSK); |
94 |
|
71 |
|
95 |
void rf02_prepAll(unsigned short freq, uint8_t setPower,uint8_t modFreq,unsigned short baudRate){ |
- |
|
96 |
|
72 |
|
97 |
rf02_init(); // ein paar Register setzen (z.B. CLK auf 10MHz) |
- |
|
98 |
rf02_setfreq( RF02FREQ(freq) ); // Sende/Empfangsfrequenz auf 433,92MHz einstellen |
73 |
for (unsigned char i=0; i<15; i++) _delay_ms(10); // wait until POR done |
99 |
|
- |
|
100 |
if ( setPower < 0 ) setPower = 0; |
- |
|
101 |
if ( setPower > 4 ) setPower = 4; |
- |
|
102 |
rf02_setpower(setPower); // -12dBm Ausgangangsleistung |
- |
|
103 |
|
74 |
|
104 |
if ( modFreq < 0 ) modFreq = 0; |
- |
|
105 |
if ( modFreq > 8 ) modFreq = 8; |
- |
|
106 |
rf02_setmodfreq(modFreq); // 120kHz Frequenzshift |
- |
|
107 |
|
- |
|
108 |
rf02_setbaud(baudRate); // 19200 Baud |
- |
|
109 |
|
75 |
|
110 |
}// |
76 |
rf02_trans(0xCC00); //*// |
111 |
|
77 |
|
- |
|
78 |
// rf02_trans(0x8B61); //*// |
- |
|
79 |
rf02_trans(0x8000|0x1000|0x70|0x02); //*// |
- |
|
80 |
rf02_trans(0xA000|0x640); //*// |
- |
|
81 |
// rf02_trans(0xA640); ///= 434 MHz |
- |
|
82 |
|
- |
|
83 |
// rf02_trans(0xD2C0); // 33% PLL current |
- |
|
84 |
// rf02_trans(0xC823); // 9600 Bd |
- |
|
85 |
rf02_trans(0xD040); // RATE/2 |
- |
|
86 |
rf02_trans(0xC811); // 19200 => 9600 Bd |
- |
|
87 |
|
- |
|
88 |
rf02_trans(0xC0E0); // power settings |
- |
|
89 |
|
- |
|
90 |
rf02_trans(0xC220); //0xC2A0 |
- |
|
91 |
// rf02_trans(0xB100); |
- |
|
92 |
// rf02_trans(0x8F83); |
- |
|
93 |
//!!! |
- |
|
94 |
// rf02_trans(0xC001); |
112 |
|
95 |
|
113 |
void rf02_sendData(){ |
- |
|
114 |
|
96 |
|
115 |
rf02_txdata( test, sizeof test); |
- |
|
116 |
} |
97 |
} |
117 |
|
98 |
|
- |
|
99 |
void rf02_sendData() |
- |
|
100 |
{ |
118 |
|
101 |
|
- |
|
102 |
//!!! rf02_txdata( test, sizeof test); |
- |
|
103 |
rf02_txdata( test, 23); |
- |
|
104 |
} |
119 |
|
105 |
|
120 |
void rf02_trans(unsigned short value) |
106 |
void rf02_trans(unsigned short value) |
- |
|
107 |
{ |
121 |
{ uint8_t i; |
108 |
uint8_t i; |
122 |
|
109 |
|
123 |
cbi(RF_PORT, CS); |
110 |
cbi(RF_PORT, CS); |
124 |
|
111 |
|
125 |
for (i=0; i<16; i++) |
112 |
for (i=0; i<16; i++) |
126 |
{ if (value&0x8000) //0x8000 |
113 |
{ if (value&0x8000) //0x8000 |
Line 135... |
Line 122... |
135 |
} |
122 |
} |
136 |
sbi(RF_PORT, CS); |
123 |
sbi(RF_PORT, CS); |
137 |
} |
124 |
} |
138 |
|
125 |
|
139 |
|
126 |
|
140 |
|
- |
|
141 |
void rf02_init(void) |
- |
|
142 |
{ |
- |
|
143 |
RF_PORT=(1<<CS); |
- |
|
144 |
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS); |
- |
|
145 |
|
- |
|
146 |
for (unsigned char i=0; i<15; i++) |
- |
|
147 |
_delay_ms(10); // wait until POR done |
- |
|
148 |
rf02_trans(0xC0E0); // power settings |
- |
|
149 |
rf02_trans(0x8A75);// fsk in rfm02 = afc in rf12 |
- |
|
150 |
// rf02_trans(0x80C7); |
- |
|
151 |
rf02_trans(0xC2A0); // enable tx sync bit, disable low bat detector |
- |
|
152 |
|
- |
|
153 |
//LED_DDR= 0xFF; |
- |
|
154 |
} |
- |
|
155 |
|
- |
|
156 |
void rf02_setmodfreq(uint8_t bandwidth) |
- |
|
157 |
{ |
- |
|
158 |
rf02_trans(0x8F80|(bandwidth&7)); |
- |
|
159 |
//rf02_trans(0x8F70); |
- |
|
160 |
} |
- |
|
161 |
|
- |
|
162 |
void rf02_setfreq(unsigned short freq) |
- |
|
163 |
{ if (freq<96) // 430,2400MHz |
- |
|
164 |
freq=96; |
- |
|
165 |
else if (freq>3903) // 439,7575MHz |
- |
|
166 |
freq=3903; |
- |
|
167 |
rf02_trans(0xA000|freq); |
- |
|
168 |
|
- |
|
169 |
//rf02_trans(0xA640); //= 434 MHz |
- |
|
170 |
} |
- |
|
171 |
|
- |
|
172 |
void rf02_setpower(uint8_t power) |
- |
|
173 |
{ |
- |
|
174 |
rf02_trans(0xB000|((power&7)<<8)); |
- |
|
175 |
} |
- |
|
176 |
|
- |
|
177 |
void rf02_setbaud(unsigned short baud) |
- |
|
178 |
{ |
- |
|
179 |
|
- |
|
180 |
if (baud<1345) |
- |
|
181 |
baud=1345; |
- |
|
182 |
if (baud<19000) |
- |
|
183 |
rf02_trans(0xD240); // 25% PLL current |
- |
|
184 |
else if (baud<37000) |
- |
|
185 |
rf02_trans(0xD2C0); // 33% PLL current |
- |
|
186 |
else |
- |
|
187 |
rf02_trans(0xD200); // 50% PLL current |
- |
|
188 |
|
- |
|
189 |
//rf02_trans(0xC800|((344828UL/baud)-1)); // Baudrate= 344827,59/(R+1) |
- |
|
190 |
|
- |
|
191 |
rf02_trans(0xC806); |
- |
|
192 |
} |
- |
|
193 |
|
- |
|
194 |
void rf02_txdata( unsigned char * data, uint8_t number) |
127 |
void rf02_txdata( unsigned char * data, uint8_t number) |
195 |
{ |
128 |
{ |
196 |
uint8_t i,value; |
129 |
uint8_t i,value; |
197 |
value=0xC6; //1100 0110 |
130 |
value=0xC6; //1100 0110 |
198 |
cbi(RF_PORT, CS); //nSel |
131 |
cbi(RF_PORT, CS); //nSel |
199 |
|
132 |
|
- |
|
133 |
//!!!! |
- |
|
134 |
// rf02_trans(0xC039); // TX start |
- |
|
135 |
|
- |
|
136 |
|
200 |
for (i=0; i<8; i++) |
137 |
for (i=0; i<8; i++) |
201 |
{ if (value&0x80) //1000 0000 = 80 |
138 |
{ if (value&0x80) //1000 0000 = 80 |
202 |
sbi(RF_PORT, SDI); |
139 |
sbi(RF_PORT, SDI); |
203 |
else |
140 |
else |
204 |
cbi(RF_PORT, SDI); |
141 |
cbi(RF_PORT, SDI); |
Line 221... |
Line 158... |
221 |
rf02_shiftout(*data++); |
158 |
rf02_shiftout(*data++); |
222 |
|
159 |
|
223 |
sbi(RF_PORT, CS); |
160 |
sbi(RF_PORT, CS); |
224 |
while(RF_PIN&(1<<IRQ)); // wait until transfer done |
161 |
while(RF_PIN&(1<<IRQ)); // wait until transfer done |
225 |
rf02_trans(0xC464); // TX off after 10us |
162 |
rf02_trans(0xC464); // TX off after 10us |
- |
|
163 |
//rf02_trans(0xC001); // TX close |
226 |
|
164 |
_delay_ms(10); |
227 |
} |
165 |
} |
228 |
|
166 |
|
229 |
void rf02_shiftout(unsigned char value) |
167 |
void rf02_shiftout(unsigned char value) |
230 |
{ uint8_t j; |
168 |
{ uint8_t j; |
231 |
for (j=0; j<8; j++) |
169 |
for (j=0; j<8; j++) |
232 |
{ while(RF_PIN&(1<<IRQ)); |
170 |
{ while(RF_PIN&(1<<IRQ)); |
233 |
while(!(RF_PIN&(1<<IRQ))); |
171 |
while(!(RF_PIN&(1<<IRQ))); |
234 |
|
172 |
|
235 |
if (value&128) //100101000 |
173 |
if (value&128) //100101000 |
- |
|
174 |
{ |
236 |
sbi(RF_PORT, SDI); |
175 |
sbi(RF_PORT, SDI); |
- |
|
176 |
} |
237 |
else |
177 |
else |
- |
|
178 |
{ |
238 |
cbi(RF_PORT, SDI); |
179 |
cbi(RF_PORT, SDI); |
- |
|
180 |
} |
239 |
value<<=1; |
181 |
value<<=1; |
240 |
} |
182 |
} |
241 |
} |
183 |
} |
242 |
|
184 |
|