/Designs/duckweed_collector/SW/library/RF01/RF01.cpp |
---|
1,17 → 1,28 |
/********************************************* |
* |
* RFM01 simple library |
* draft version v 0.1, experimental |
* |
* $HeadURL: svn://www.mlab.cz/home/MLAB/Designs/duckweed_collector/SW/library/RF02/RF02.cpp $ |
* $Id: RF02.cpp 2129 2011-08-18 18:40:43Z kakl $ |
* code based on the code of "benedikt k." |
* this was an avr project from the site: http://www.mikrocontroller.net/topic/65984#541030 |
* |
* code based on the code of "benedikt k." and "contrechoc" |
* |
* tested on arduino 22 |
* code should be matched with RF01 |
* |
* up to now no transmission between the RF12 modules and Jeelabs.com RF12 lib |
* |
* this code has worked: transmitting using atmega168 and atmega328 in combination with RF01s and RF02s |
* |
* arduino 18 |
* |
* five march, contrechoc.com, june 2010 , october 2010 |
* |
* |
*********************************************/ |
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include <avr/eeprom.h> |
#include <stdlib.h> |
#include "rf01.h" |
27,7 → 38,7 |
#define SCK 4 // RF01 SCK, arduino 12 cannot be changed |
#define CS 3 // RF01 nSEL, arduino 11 cannot be changed |
#define SDO 2 // RF01 SDO, arduino 10 cannot be changed |
//----------------- // RF01 niRQ, arduino 2 cannot be changed |
//----------------- // RF01 niRQ, arduino 02 cannot be changed |
//------------------// RF01 nFFS: 1-10k Pullup too Vcc |
38,10 → 49,18 |
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) |
#endif |
unsigned char _rx_buffer[32]; // recv buf |
// maximum receive buffer |
#define RF_MAX 32 |
unsigned char rf01_buf[RF_MAX]; // recv buf |
#include <util/delay.h> |
void rf01_receive(){ |
rf01_rxdata(rf01_data, 23); //!!!32 |
} |
static unsigned char sdrssi, sgain; |
void rf01_prepAll() |
{ |
RF_PORT=(1<<CS); |
49,9 → 68,17 |
for (unsigned char i=0; i<11; i++) _delay_ms(10); // wait until POR done |
// rf01_trans(0xC2E0); // AVR CLK: 10MHz |
// rf01_trans(0xC42B); // Data Filter: internal |
// rf01_trans(0xC6F7); // AFC settings: autotuning: -10kHz...+7,5kHz |
// rf01_trans(0xE000); // disable wakeuptimer |
// rf01_trans(0xCC00); // disable low duty cycle |
// rf01_trans(0x8978); // band 433MHz, enable crystal + 12pF, 200kHz bandwidth |
rf01_trans(0x0000); |
// rf01_trans(0x898A); // band 433MHz, 134kHz bandwidth |
rf01_trans(0x8000|0x1000|0x70|0x02); //band |
rf01_trans(0xA640); // freq |
rf01_trans(0xA640); //434MHz |
rf01_trans(0xC823); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 9600 Bd |
rf01_trans(0xC69B); |
rf01_trans(0xC42A); |
72,9 → 99,8 |
else |
cbi(RF_PORT, SDI); |
sbi(RF_PORT, SCK); |
sbi(RF_PORT, SCK); |
sbi(RF_PORT, SCK); |
wert<<=1; |
_delay_us(0.2); |
cbi(RF_PORT, SCK); |
} |
sbi(RF_PORT, CS); |
83,6 → 109,10 |
void rf01_rxdata(unsigned char *data, unsigned char number) |
{ unsigned char i,j,c; |
//!!! |
// sgain=2; //2,4 -6dB LNA gain, DRSSI threshold: -79dBm |
// sdrssi=4; |
//!!! rf01_trans(0xC0C1|((sgain&3)<<4)|((sdrssi&7)<<1)); // RX on |
rf01_trans(0xCE89); // set FIFO mode |
rf01_trans(0xCE8B); // enable FIFO |
cbi(RF_PORT, SDI); |
115,6 → 145,7 |
asm("nop"); |
asm("nop"); |
asm("nop"); |
//!!! _delay_us(0.2); |
cbi(RF_PORT, SCK); |
asm("nop"); |
asm("nop"); |
126,4 → 157,5 |
asm("nop"); |
asm("nop"); |
} |
//!!! rf01_trans(0xC0C0|((sgain&3)<<4)|((sdrssi&7)<<1)); // RX off |
} |
/Designs/duckweed_collector/SW/library/RF01/RF01.h |
---|
5,9 → 5,10 |
#define rf01_data (rf01_buf + 2) |
extern unsigned char _rx_buffer[]; // recv/xmit buf including hdr & crc bytes |
extern unsigned char rf01_buf[]; // recv/xmit buf including hdr & crc bytes |
extern void rf01_prepAll(); |
extern void rf01_receive(); |
extern void rf01_trans(unsigned short wert); |
extern void rf01_rxdata(unsigned char *data, unsigned char number); |
/Designs/duckweed_collector/SW/RF01/RF01.pde |
---|
1,19 → 1,22 |
/* |
RF02 TX sample for Arduino |
connections arduino RF01 and RF02 |
in arduino version 022 |
in arduino version 018 |
(not yet tested in more recent arduino versions) |
tested with MLAB modules with ATmega 328 at 16MHz |
see RF02 library for a Band and Frequency |
tested with ATmega 328 |
on frequency 433 |
no range test done yet, just in one room |
*/ |
//connections RF01: (RX) |
// RF01 SDI, arduino 13, ATmega PB5, cannot be changed |
// RF01 SCK, arduino 12, ATmega PB4, cannot be changed |
// RF01 nSEL, arduino 11, ATmega PB3, cannot be changed |
// RF01 SDO, arduino 10, ATmega PB2, cannot be changed |
// RF01 niRQ, arduino 02, ATmega PD2, cannot be changed |
// RF01 nFFS: 1-10k Pullup too Vcc |
//connections RF01: (receiving) |
#define SDI 5 // RF01 SDI, arduino 13, ATmega PB5, cannot be changed |
#define SCK 4 // RF01 SCK, arduino 12, ATmega PB4, cannot be changed |
#define CS 3 // RF01 nSEL, arduino 11, ATmega PB3, cannot be changed |
#define SDO 2 // RF01 SDO, arduino 10, ATmega PB2, cannot be changed |
//--------------------- // RF01 niRQ, arduino 02, ATmega PD2, cannot be changed |
//----------------------// RF01 nFFS: 1-10k Pullup too Vcc |
// receiving words with RF01 |
20,26 → 23,32 |
#include <RF01.h> |
void setup() |
{ |
int serialTesting = 1; |
void setup() { |
Serial.begin(9600); |
Serial.println("\nRFM01 init"); |
Serial.println("\nRF02 receive"); |
delay(250); |
rf01_prepAll(); |
Serial.println("done"); |
delay(250); |
Serial.println("startup"); |
} |
void loop() |
{ |
void loop() { |
int n; |
char* buf = (char*) _rx_buffer; |
// unsigned char buf[] = { "$00\n" }; // Motor, Rudder |
for(n=0;n<32;n++) rf01_data[n]='$'; |
rf01_receive(); |
char* buf = (char*) rf01_data; |
buf[31]=0; |
//if ((buf[0]=='$')&&(buf[3]=='\n')) |
Serial.println(buf); |
for(n=0;n<32;n++) {Serial.print(rf01_data[n], HEX); Serial.print(' ');} |
Serial.println(); |
rf01_rxdata(_rx_buffer, 10); |
buf[11]=0; |
delay(10); |
Serial.println(buf); |
for(n=0;n<32;n++) {Serial.print(buf[n], HEX); Serial.print(' ');} |
Serial.println(); |
} |
/Designs/duckweed_collector/SW/RF02/RF02.pde |
---|
1,38 → 1,81 |
/* |
RF02 TX sample for Arduino |
connections arduino RF01 and RF02 |
in arduino version 022 |
in arduino version 018 |
(not yet tested in more recent arduino versions) |
tested with MLAB modules with ATmega 328 at 16MHz |
see RF02 library for a Band and Frequency |
tested with ATmega 328 |
on frequency 433 |
no range test done yet, just in one room |
*/ |
//connections RF02: (TX) |
// SDI, -> RF02 Atmega PB0 Arduino 8 cannot be changed |
// SCK, -> RF02 Atmega PB1 Arduino 9 cannot be changed |
// nSEL, -> RF02 Atmega PB2 Arduino 10 cannot be changed |
// nIRQ, <- RF02 Atmega PB4 Arduino 12 cannot be changed |
// FSK: Pullupto VCC |
//connections RF02: (sending) |
#define SDI 0 // SDI, -> RF02 Atmega PB0 Arduino 8 cannot be changed |
#define SCK 1 // SCK, -> RF02 Atmega PB1 Arduino 9 cannot be changed |
#define CS 2 // nSEL, -> RF02 Atmega PB2 Arduino 10 cannot be changed |
#define IRQ 4 // nIRQ, <- RF02 Atmega PB4 Arduino 12 cannot be changed |
//------------------// FSK: Pullupto VCC |
// RF02 sending words |
// tested with lib, november 2010 |
#include <RF02.h> |
#include <stdint.h> |
void setup() |
{ |
int wissel = 0;//wissel means change in dutch |
void setup() { |
Serial.begin(9600); |
Serial.println("\nSTM02 init" ); |
Serial.print("hello" ); |
Serial.println("init" ); |
rf02_prepAll(); |
Serial.println("done" ); |
Serial.println("done" ); |
pinMode(4, OUTPUT); //testing leds |
pinMode(5, OUTPUT); |
ledBlink(4); |
ledBlink(5); |
} |
void ledBlink(int num){ |
digitalWrite(num, HIGH); |
delay(100); |
digitalWrite(num, LOW); |
delay(100); |
} |
unsigned int ble='a'; |
void loop() |
{ |
unsigned char _tx_buffer[]="0123456789"; |
// ledBlink(4); |
delay(1000); |
rf02_txdata( _tx_buffer, sizeof(_tx_buffer)); |
// unsigned char buf[] = { "01234567890123456789012345678901\n" }; // Motor, Rudder |
unsigned char buf[] = { "0123456789012345678$0123456789" }; |
unsigned char sum=0; |
//buf[19]=ble; |
for(unsigned int a=0;a<20;a++) |
{ |
sum+=buf[a]; |
}; |
if(ble>'z') {ble='a';} else {ble++;} |
buf[20]=sum; |
buf[21]=0xAA; |
buf[22]=0xAA; |
rf02_changeText( buf, 23); |
// rf02_changeText( buf, sizeof buf); |
// Serial.println("M0R0\n"); |
rf02_sendData(); |
} |