/Designs/duckweed_collector/SW/RF01/RF01.pde
45,10 → 45,10
char* buf = (char*) rf01_data;
buf[31]=0;
//if ((buf[0]=='$')&&(buf[3]=='\n'))
Serial.println(rf01_data);
Serial.println(buf);
for(n=0;n<32;n++) {Serial.print(rf01_data[n], HEX); Serial.print(' ');}
Serial.println();
 
delay(700);
delay(10);
}
/Designs/duckweed_collector/SW/RF02/RF02.pde
33,7 → 33,7
Serial.println("init" );
rf02_prepAll434();
rf02_prepAll();
Serial.println("done" );
pinMode(4, OUTPUT); //testing leds
48,21 → 48,30
digitalWrite(num, LOW);
delay(100);
}
 
unsigned int ble='a';
 
void loop()
{
// ledBlink(4);
delay(10);
delay(1000);
 
// unsigned char buf[] = { "01234567890123456789012345678901\n" }; // Motor, Rudder
unsigned char buf[] = { "012345678901234567890123456789012345678901234567890123456789" };
unsigned char buf[] = { "0123456789012345678$0123456789" };
 
buf[30]=0;
buf[31]=0xAA;
rf02_changeText( buf, 32);
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");
/Designs/duckweed_collector/SW/library/RF01/RF01.cpp
41,15 → 41,7
//----------------- // RF01 niRQ, arduino 02 cannot be changed
//------------------// RF01 nFFS: 1-10k Pullup too Vcc
 
#define LED_PORT PORTD
#define LED_DDR DDRD
#define LED_PIN PIND
 
#define LED0 5
#define LED1 6 //not used
 
// nFFS: 1-10k Pullup an Vcc !!!
 
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
57,20 → 49,6
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
 
#ifndef cLED0
#define cLED0() (LED_PORT &= ~(1<<LED0))
#endif
#ifndef sLED0
#define sLED0() (LED_PORT |= (1<<LED0) )
#endif
 
#ifndef cLED1
#define cLED1() (LED_PORT &= ~(1<<LED1))
#endif
#ifndef sLED1
#define sLED1() (LED_PORT |= (1<<LED1) )
#endif
 
// maximum receive buffer
#define RF_MAX 32
unsigned char rf01_buf[RF_MAX]; // recv buf
78,20 → 56,39
#include <util/delay.h>
 
void rf01_receive(){
rf01_rxdata(rf01_data, 32);
rf01_rxdata(rf01_data, 23); //!!!32
}
 
void rf01_prepAll(){
rf01_init(); // ein paar Register setzen (z.B. CLK auf 10MHz)
rf01_setfreq(RF01FREQ(434)); // Sende/Empfangsfrequenz auf 433,92MHz einstellen
rf01_setbandwidth(4); // 4 200kHz Bandbreite
rf01_setreceiver(2,4); //2,4 -6dB Verstärkung, DRSSI threshold: -79dBm
rf01_setbaud(57600); // 19200 Baud
static unsigned char sdrssi, sgain;
 
void rf01_prepAll()
{
RF_PORT=(1<<CS);
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
 
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); //434MHz
rf01_trans(0xC823); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 9600 Bd
rf01_trans(0xC69B);
rf01_trans(0xC42A);
rf01_trans(0xC240); //*
rf01_trans(0xC080); //*
rf01_trans(0xCE88); // FIFO mode
rf01_trans(0xCE8B); //*
rf01_trans(0xC081); //*
}
 
static unsigned char sdrssi, sgain;
 
void rf01_trans(unsigned short wert)
{ unsigned char i;
 
109,72 → 106,35
sbi(RF_PORT, CS);
}
 
void rf01_init(void)
{ unsigned char i;
 
RF_PORT=(1<<CS);
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
 
for (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(0xCE88); // FIFO mode
rf01_trans(0xC6F7); // AFC settings: autotuning: -10kHz...+7,5kHz
rf01_trans(0xE000); // disable wakeuptimer
rf01_trans(0xCC00); // disable low duty cycle
 
LED_DDR= 0xFF;//(1<<LED0)|(1<<LED1);
blinkLED();
 
}
 
void rf01_setbandwidth(unsigned char bandwidth)
{
rf01_trans(0x8970|((bandwidth&7)<<1));
}
 
void rf01_setreceiver(unsigned char gain, unsigned char drssi)
{
sdrssi=drssi;
sgain=gain;
}
 
void rf01_setfreq(unsigned short freq)
{ if (freq<96) // 430,2400MHz
freq=96;
else if (freq>3903) // 439,7575MHz
freq=3903;
rf01_trans(0xA000|freq);
}
 
void rf01_setbaud(unsigned short baud)
{
if (baud<336)
return;
if (baud<5400) // Baudrate= 344827,58621/(R+1)/(1+CS*7)
rf01_trans(0xC880|((43104/baud)-1));
else
rf01_trans(0xC800|((344828UL/baud)-1));
 
rf01_trans(0xC806);
}
 
void rf01_rxdata(unsigned char *data, unsigned char number)
{ unsigned char i,j,c;
 
rf01_trans(0xC0C1|((sgain&3)<<4)|((sdrssi&7)<<1)); // RX on
//!!!
// 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);
asm("nop");
asm("nop");
asm("nop");
for (i=0; i<number; i++)
{ cbi(RF_PORT, CS);
asm("nop");
asm("nop");
asm("nop");
while (!(RF_PIN&(1<<SDO))); // wait until data in FIFO
for (j=0; j<16; j++) // read and discard status register
{ sbi(RF_PORT, SCK);
{
sbi(RF_PORT, SCK);
asm("nop");
asm("nop");
asm("nop");
cbi(RF_PORT, SCK);
asm("nop");
asm("nop");
asm("nop");
}
c=0;
for (j=0; j<8; j++)
182,39 → 142,20
if (RF_PIN&(1<<SDO))
c|=1;
sbi(RF_PORT, SCK);
_delay_us(0.2);
asm("nop");
asm("nop");
asm("nop");
//!!! _delay_us(0.2);
cbi(RF_PORT, SCK);
asm("nop");
asm("nop");
asm("nop");
}
*data++=c;
sbi(RF_PORT, CS);
asm("nop");
asm("nop");
asm("nop");
}
//blinkLED();
rf01_trans(0xC0C0|((sgain&3)<<4)|((sdrssi&7)<<1)); // RX off
//!!! rf01_trans(0xC0C0|((sgain&3)<<4)|((sdrssi&7)<<1)); // RX off
}
 
void blinkLED(void){
for (unsigned char i=0; i<15; i++)
_delay_ms(5);
sLED1();
 
for (unsigned char i=0; i<15; i++)
_delay_ms(5);
cLED1();
 
}
 
void makePulse(int numberOfPulses){
if ( numberOfPulses > 0)
{
for (unsigned char i=0; i<numberOfPulses; i++)
{
_delay_ms(20);
sLED0();
_delay_ms(20);
cLED0();
}
_delay_ms(50);
}
 
}
 
/Designs/duckweed_collector/SW/library/RF01/RF01.h
11,16 → 11,6
extern void rf01_receive();
 
extern void rf01_trans(unsigned short wert);
extern void rf01_init(void);
extern void rf01_setbandwidth(unsigned char bandwidth);
extern void rf01_setreceiver(unsigned char gain, unsigned char drssi);
extern void rf01_setfreq(unsigned short freq);
extern void rf01_setbaud(unsigned short baud);
extern void rf01_rxdata(unsigned char *data, unsigned char number);
 
#define RF01FREQ(freq) ((freq-430.0)/0.0025)
 
extern void blinkLED(void);
extern void makePulse(int numberOfPulses);
 
#endif
/Designs/duckweed_collector/SW/library/RF02/RF02.cpp
37,17 → 37,11
#define RF_DDR DDRB
#define RF_PIN PINB
 
#define LED_PORT PORTD
#define LED_DDR DDRD
#define LED_PIN PIND
 
#define LED0 4 -- PD4
#define LED1 2 -- PD2
 
#define SDI 0 // SDI, -> RF02 Atmega PB0 Arduino 8
#define SCK 1 // SCK, -> RF02 Atmega PB1 Arduino 9
#define CS 2 // nSEL, -> RF02 Atmega PB2 Arduino 10
#define IRQ 4 // nIRQ, <- RF02 Atmega PB4 Arduino 12
#define FSK 3 // FSK, <- RF02 Atmega PB3 Arduino ???
//------------------// FSK: Pullupto VCC
 
#ifndef cbi
57,25 → 51,11
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
 
#ifndef cLED0
#define cLED0() (LED_PORT &= ~(1<<LED0))
#endif
#ifndef sLED0
#define sLED0() (LED_PORT |= (1<<LED0) )
#endif
 
#ifndef cLED1
#define cLED1() (LED_PORT &= ~(1<<LED1))
#endif
#ifndef sLED1
#define sLED1() (LED_PORT |= (1<<LED1) )
#endif
 
 
 
unsigned char test[32]=" 55555 \n";
 
void rf02_changeText( unsigned char* ptr, uint8_t number){
void rf02_changeText( unsigned char* ptr, uint8_t number)
{
 
if (number> 32)number = 32;
memcpy( test, ptr, number);
82,43 → 62,50
}
 
void rf02_prepAll434(){
void rf02_prepAll()
{
RF_PORT=(1<<CS);
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
 
rf02_init(); // ein paar Register setzen (z.B. CLK auf 10MHz)
rf02_setfreq(RF02FREQ(434)); // 433,92MHz
rf02_setpower(1); // -12dBm Ausgangangsleistung
rf02_setmodfreq(3); // 120kHz Frequenzshift
rf02_setbaud(19200); // 19200 Baud
sbi(RF_PORT, FSK);
 
}//
 
void rf02_prepAll(unsigned short freq, uint8_t setPower,uint8_t modFreq,unsigned short baudRate){
 
rf02_init(); // ein paar Register setzen (z.B. CLK auf 10MHz)
rf02_setfreq( RF02FREQ(freq) ); // Sende/Empfangsfrequenz auf 433,92MHz einstellen
for (unsigned char i=0; i<15; i++) _delay_ms(10); // wait until POR done
if ( setPower < 0 ) setPower = 0;
if ( setPower > 4 ) setPower = 4;
rf02_setpower(setPower); // -12dBm Ausgangangsleistung
if ( modFreq < 0 ) modFreq = 0;
if ( modFreq > 8 ) modFreq = 8;
rf02_setmodfreq(modFreq); // 120kHz Frequenzshift
rf02_setbaud(baudRate); // 19200 Baud
 
}//
rf02_trans(0xCC00); //*//
 
// rf02_trans(0x8B61); //*//
rf02_trans(0x8000|0x1000|0x70|0x02); //*//
rf02_trans(0xA000|0x640); //*//
// rf02_trans(0xA640); ///= 434 MHz
 
void rf02_sendData(){
// rf02_trans(0xD2C0); // 33% PLL current
// rf02_trans(0xC823); // 9600 Bd
rf02_trans(0xD040); // RATE/2
rf02_trans(0xC811); // 19200 => 9600 Bd
 
rf02_txdata( test, sizeof test);
rf02_trans(0xC0E0); // power settings
 
rf02_trans(0xC220); //0xC2A0
// rf02_trans(0xB100);
// rf02_trans(0x8F83);
//!!!
// rf02_trans(0xC001);
 
 
}
 
void rf02_sendData()
{
 
//!!! rf02_txdata( test, sizeof test);
rf02_txdata( test, 23);
}
 
void rf02_trans(unsigned short value)
{ uint8_t i;
{
uint8_t i;
 
cbi(RF_PORT, CS);
 
137,60 → 124,6
}
 
 
 
void rf02_init(void)
{
RF_PORT=(1<<CS);
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
 
for (unsigned char i=0; i<15; i++)
_delay_ms(10); // wait until POR done
rf02_trans(0xC0E0); // power settings
rf02_trans(0x8A75);// fsk in rfm02 = afc in rf12
// rf02_trans(0x80C7);
rf02_trans(0xC2A0); // enable tx sync bit, disable low bat detector
 
//LED_DDR= 0xFF;
}
 
void rf02_setmodfreq(uint8_t bandwidth)
{
rf02_trans(0x8F80|(bandwidth&7));
//rf02_trans(0x8F70);
}
 
void rf02_setfreq(unsigned short freq)
{ if (freq<96) // 430,2400MHz
freq=96;
else if (freq>3903) // 439,7575MHz
freq=3903;
rf02_trans(0xA000|freq);
 
//rf02_trans(0xA640); //= 434 MHz
}
 
void rf02_setpower(uint8_t power)
{
rf02_trans(0xB000|((power&7)<<8));
}
 
void rf02_setbaud(unsigned short baud)
{
if (baud<1345)
baud=1345;
if (baud<19000)
rf02_trans(0xD240); // 25% PLL current
else if (baud<37000)
rf02_trans(0xD2C0); // 33% PLL current
else
rf02_trans(0xD200); // 50% PLL current
 
//rf02_trans(0xC800|((344828UL/baud)-1)); // Baudrate= 344827,59/(R+1)
rf02_trans(0xC806);
}
 
void rf02_txdata( unsigned char * data, uint8_t number)
{
uint8_t i,value;
197,6 → 130,10
value=0xC6; //1100 0110
cbi(RF_PORT, CS); //nSel
 
//!!!!
// rf02_trans(0xC039); // TX start
 
 
for (i=0; i<8; i++)
{ if (value&0x80) //1000 0000 = 80
sbi(RF_PORT, SDI);
223,7 → 160,8
sbi(RF_PORT, CS);
while(RF_PIN&(1<<IRQ)); // wait until transfer done
rf02_trans(0xC464); // TX off after 10us
 
//rf02_trans(0xC001); // TX close
_delay_ms(10);
}
 
void rf02_shiftout(unsigned char value)
233,9 → 171,13
while(!(RF_PIN&(1<<IRQ)));
 
if (value&128) //100101000
sbi(RF_PORT, SDI);
{
sbi(RF_PORT, SDI);
}
else
{
cbi(RF_PORT, SDI);
}
value<<=1;
}
}
/Designs/duckweed_collector/SW/library/RF02/RF02.h
3,24 → 3,13
 
#include <stdint.h>
 
extern void rf02_prepAll434();
extern void rf02_prepAll(unsigned short freq, uint8_t setPower, uint8_t modFreq, unsigned short baudRate);
//extern void rf02_prepAll(unsigned short freq, uint8_t setPower, uint8_t modFreq, unsigned short baudRate);
extern void rf02_prepAll();
 
extern void rf02_sendData();
extern void rf02_changeText( unsigned char* ptr, uint8_t number);
 
extern void rf02_trans(unsigned short value);
extern void rf02_init(void); // init functions
extern void rf02_setmodfreq(uint8_t bandwidth); // set modulation deviation
extern void rf02_setfreq(unsigned short freq); // set tx frequency
extern void rf02_setpower(uint8_t power); // set power (0-7)
extern void rf02_setbaud(unsigned short baud); // set baudrate
extern void rf02_txdata(unsigned char* ptr, uint8_t number); // tx data
extern void rf02_shiftout(unsigned char value);
 
 
#define RF02FREQ(freq) ((freq-430.0)/0.0025)
 
#endif