@@ -120,6 +120,8 @@ enum {
120
120
TXPRE1, TXPRE2, TXPRE3, TXSYN1, TXSYN2,
121
121
};
122
122
123
+ static uint8_t cs_pin = SS_BIT; // address of this node
124
+
123
125
static uint8_t nodeid; // address of this node
124
126
static uint8_t group; // network group
125
127
static volatile uint8_t rxfill; // number of data bytes in rf12_buf
@@ -142,9 +144,17 @@ static uint32_t seqNum; // encrypted send sequence number
142
144
static uint32_t cryptKey[4 ]; // encryption key to use
143
145
void (*crypter)(uint8_t ); // does en-/decryption (null if disabled)
144
146
147
+ void rf12_set_cs (uint8_t pin)
148
+ {
149
+ if (pin==10 ) cs_pin = 2 ;
150
+ if (pin==9 ) cs_pin = 1 ;
151
+ if (pin==8 ) cs_pin = 0 ;
152
+ }
153
+
154
+
145
155
void rf12_spiInit () {
146
- bitSet (SS_PORT, SS_BIT );
147
- bitSet (SS_DDR, SS_BIT );
156
+ bitSet (SS_PORT, cs_pin );
157
+ bitSet (SS_DDR, cs_pin );
148
158
digitalWrite (SPI_SS, 1 );
149
159
pinMode (SPI_SS, OUTPUT);
150
160
pinMode (SPI_MOSI, OUTPUT);
@@ -201,10 +211,10 @@ static uint16_t rf12_xferSlow (uint16_t cmd) {
201
211
#if F_CPU > 10000000
202
212
bitSet (SPCR, SPR0);
203
213
#endif
204
- bitClear (SS_PORT, SS_BIT );
214
+ bitClear (SS_PORT, cs_pin );
205
215
uint16_t reply = rf12_byte (cmd >> 8 ) << 8 ;
206
216
reply |= rf12_byte (cmd);
207
- bitSet (SS_PORT, SS_BIT );
217
+ bitSet (SS_PORT, cs_pin );
208
218
#if F_CPU > 10000000
209
219
bitClear (SPCR, SPR0);
210
220
#endif
@@ -214,10 +224,10 @@ static uint16_t rf12_xferSlow (uint16_t cmd) {
214
224
#if OPTIMIZE_SPI
215
225
static void rf12_xfer (uint16_t cmd) {
216
226
// writing can take place at full speed, even 8 MHz works
217
- bitClear (SS_PORT, SS_BIT );
227
+ bitClear (SS_PORT, cs_pin );
218
228
rf12_byte (cmd >> 8 ) << 8 ;
219
229
rf12_byte (cmd);
220
- bitSet (SS_PORT, SS_BIT );
230
+ bitSet (SS_PORT, cs_pin );
221
231
}
222
232
#else
223
233
#define rf12_xfer rf12_xferSlow
0 commit comments