/Designs/duckweed_collector/SW/library/RF02/RF02.cpp
5,20 → 5,15
* $HeadURL$
* $Id$
*
* code based on the code of "benedikt k." and "contrechoc"
* code based on the code of "benedikt k." and "contrechoc"
*
* arduino 22
* tested on arduino 22
*
*********************************************/
 
 
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <string.h>
#include "rf02.h"
#include <util/delay.h>
42,34 → 37,19
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
 
unsigned char _tx_buffer[32];
 
unsigned char test[32]=" 55555 \n";
 
void rf02_changeText( unsigned char* ptr, uint8_t number)
{
 
if (number> 32)number = 32;
memcpy( test, ptr, number);
}
 
void rf02_prepAll()
{
RF_PORT=(1<<CS);
RF_DDR=(1<<SDI)|(1<<SCK)|(1<<CS);
 
sbi(RF_PORT, FSK);
 
 
for (unsigned char i=0; i<15; i++) _delay_ms(10); // wait until POR done
 
rf02_trans(0xCC00); //*//
rf02_trans(0xCC00); // cargo cult settings
 
// rf02_trans(0x8B61); //*//
rf02_trans(0x8000|0x1000|0x70|0x02); //*//
rf02_trans(0xA000|0x640); //*//
// rf02_trans(0xA640); ///= 434 MHz
rf02_trans(0x8000|0x1000|0x70|0x02);
rf02_trans(0xA000|0x640);
 
// rf02_trans(0xD2C0); // 33% PLL current
// rf02_trans(0xC823); // 9600 Bd
79,21 → 59,8
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;
121,10 → 88,6
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);
132,27 → 95,26
cbi(RF_PORT, SDI);
 
sbi(RF_PORT, SCK);
sbi(RF_PORT, SCK);
sbi(RF_PORT, SCK);
value<<=1;
_delay_us(0.2);
cbi(RF_PORT, SCK);
}
 
rf02_shiftout(0xAA);//10101010
rf02_shiftout(0xAA);//10101010 // RX AGC initiation
rf02_shiftout(0xAA);
rf02_shiftout(0xAA);
rf02_shiftout(0x2D);//00101101
rf02_shiftout(0x2D);//00101101 // preamble
rf02_shiftout(0xD4);//11010100
// no checkbit, in experimenting some letters were transmitted wrong!
 
for (i=0; i<number; i++)
for (i=0; i<number; i++) // payload
rf02_shiftout(*data++);
 
rf02_shiftout(0xAA); // dummy byte
 
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)
/Designs/duckweed_collector/SW/library/RF02/RF02.h
5,7 → 5,6
 
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);