/Designs/HOPEwireless/SW_TX_RFM02/atmel/RFM02.h |
---|
0,0 → 1,82 |
/* mija 2008 |
defines for module RFM02 - TX 868MHz |
*/ |
#define CMD_SETTING 0x8000 // b1, b0, d2..d0, x3..x0, ms, m2..m0 |
#define CMD_POWER 0xC000 // a1, a0, ex, es, ea, eb, et, dc |
#define CMD_POWER_OUT 0xB000 // p2..p0 -3*Pmax dBm |
#define CMD_FREQUENCY 0xA000 // f11..f0 860+F*0.005 MHz 36..3903 |
#define CMD_RATE 0xC800 // r7..r0 BR=10M/29/(R+1) |
#define CMD_WAKE_UP 0xE000 // r4..r0, m7..m0 T=M*2^R [ms] |
#define CMD_SLEEP 0xC400 // s7..s0 S stop CLK |
#define CMD_BATTERY 0xC200 // dwc, ebs , t4..t0 |
#define CMD_STATUS 0xCC00 // for read status |
// CMD_SETTING |
#define BAND_315 0x0000 |
#define BAND_433 0x800 |
#define BAND_868 0x1000 |
#define BADN_915 0x1800 |
#define C_8_5pF 0x00 |
#define C_9pF 0x10 |
#define C_9_5pF 0x20 |
#define C_10pF 0x30 |
#define C_10_5pF 0x40 |
#define C_11pF 0x50 |
#define C_11_5pF 0x60 |
#define C_12pF 0x70 |
#define C_12_5pF 0x80 |
#define C_13pF 0x90 |
#define C_13_5pF 0xA0 |
#define C_14pF 0xB0 |
#define C_14_5pF 0xC0 |
#define C_15pF 0xD0 |
#define C_15_5pF 0xE0 |
#define C_16pF 0xF0 |
#define SETTING_MS 0x08 // modulation polarity |
#define TX_DEV_30 0x00 // select frequency deviation |
#define TX_DEV_60 0x01 |
#define TX_DEV_90 0x02 |
#define TX_DEV_120 0x03 |
#define TX_DEV_150 0x04 |
#define TX_DEV_180 0x05 |
#define TX_DEV_210 0x06 |
// CMD_POWER |
#define POWER_A1 0x80 // enable crystal and syntheesizer by sleep |
#define POWER_A0 0x40 // enable PA by sleep |
#define POWER_EX 0x20 // enable transmitter |
#define POWER_ES 0x10 // enable synthesizer |
#define POWER_EA 0x08 // enable PA (power amplifier) |
#define POWER_EB 0x04 // enable low battery detector |
#define POWER_ET 0x02 // enable wake up timer |
#define POWER_DC 0x01 // disable clock output of CLK pin |
// CMD_POWER_OUT |
#define POWER_OUT_0 0xB000 // -0dBm |
#define POWER_OUT_3 0xB100 // -3dBm |
#define POWER_OUT_6 0xB200 // -6dBm |
#define POWER_OUT_9 0xB300 // -9dBm |
#define POWER_OUT_12 0xB400 // -12dBm |
#define POWER_OUT_15 0xB500 // -15dBm |
#define POWER_OUT_18 0xB600 // -18dBm |
#define POWER_OUT_21 0xB700 // -21dBm |
// CMD_FREQUENCY |
#define FREQUENCY_867 0x578 |
#define FREQUENCY_868 0x640 |
#define FREQUENCY_869 0x708 |
// CMD_RATE |
#define RATE_2400 0x8F |
#define RATE_4800 0x47 |
#define RATE_9600 0x23 |
#define RATE_19200 0x11 |
#define RATE_38400 0x8 |
#define RATE_57600 0x5 |
#define RATE_115200 0x2 |
// CMD_BATTERY |
#define WAKE_UP_DWC 0x80 // disable wake-up timer periodical calibration |
#define TX_EBS 0x20 // enable TX bit synchronization function |
/Designs/HOPEwireless/SW_TX_RFM02/atmel/TX_RFM02.c |
---|
0,0 → 1,197 |
/* mija 2008 |
demo for RFM02 - TX 868MHz |
CPU ATMEGA16 |
fcpu = 1MHz |
!! define PIN,PORT,DDR for IOpin !! |
tested with module RFM12B RX 9600 BW 134kHz |
*/ |
#include <avr/io.h> |
#include <util/delay.h> |
#include "RFM02.h" |
//************************************************************************ |
#define SDI PB3 |
#define SDI_PORT PORTB |
#define SDI_DDR DDRB |
#define FSK PC1 |
#define FSK_PORT PORTC |
#define FSK_DDR DDRC |
#define SDO PB4 // input for mega |
#define SDO_PORT PORTB |
#define SDO_DDR DDRB |
#define SDO_PIN PINB |
#define SCK PB5 |
#define SCK_PORT PORTB |
#define SCK_DDR DDRB |
#define nIRQ PD2 // input for mega |
#define nIRQ_PORT PORTD |
#define nIRQ_DDR DDRD |
#define nIRQ_PIN PIND |
#define nSEL PB2 |
#define nSEL_PORT PORTB |
#define nSEL_DDR DDRB |
#define LED PC3 |
#define LED_PORT PORTC |
#define LED_DDR DDRC |
// interni |
#define SDI_H SDI_PORT |= _BV(SDI) |
#define SDI_L SDI_PORT &= (~(_BV(SDI))) |
#define SDI_INIT SDI_DDR |= _BV(SDI) |
#define FSK_H FSK_PORT |= _BV(FSK) |
#define FSK_L FSK_PORT &= (~(_BV(FSK))) |
#define FSK_INIT FSK_DDR |= _BV(FSK) |
#define SDO_INPUT (SDO_PIN & _BV(SDO)) |
#define SDO_INIT SDO_DDR &= (~(_BV(SDO))) |
#define SCK_H SCK_PORT |= _BV(SCK) |
#define SCK_L SCK_PORT &= (~(_BV(SCK))) |
#define SCK_INIT SCK_DDR |= _BV(SCK) |
#define nIRQ_INPUT (nIRQ_PIN & _BV(nIRQ)) |
#define nIRQ_INIT nIRQ_DDR &= (~(_BV(nIRQ))) |
#define nSEL_H nSEL_PORT |= _BV(nSEL) |
#define nSEL_L nSEL_PORT &= (~(_BV(nSEL))) |
#define nSEL_INIT nSEL_DDR |= _BV(nSEL) |
#define LED_H LED_PORT |= _BV(LED) |
#define LED_L LED_PORT &= (~(_BV(LED))) |
#define LED_INIT LED_DDR |= _BV(LED) |
#define START_TX RF_WRITE_CMD(CMD_POWER|POWER_EX|POWER_ES|POWER_EA|POWER_DC) |
#define STOP_TX RF_WRITE_CMD(CMD_POWER|POWER_DC) |
//************************************************************************ |
//uint8_t test[16]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x03b,0x3c,0x3d,0x3e,0x3f}; |
uint8_t test[17]="\n\rATmega16\n\r ---"; |
//uint8_t test[16]="0123456789abcdef"; |
//************************************************************************ |
void delay_ms(uint16_t time) |
{ |
while(time--) _delay_ms(1); |
} |
void IO_INIT(void) |
{ |
SDI_INIT; |
SDO_INIT; |
SCK_INIT; |
nIRQ_INIT; |
nSEL_INIT; |
FSK_INIT; |
LED_INIT; |
} |
void RF_INIT(void) |
{ |
nSEL_H; |
SDI_H; |
SCK_L; |
nIRQ_INPUT; |
SDO_INPUT; |
FSK_H; |
} |
void RF_WRITE_CMD(uint16_t cmd) |
{ |
uint8_t i; |
SCK_L; |
nSEL_L; |
for (i=0;i<16;i++) |
{ |
SCK_L; |
SCK_L; |
if (cmd & 0x8000) SDI_H; |
else SDI_L; |
SCK_H; |
SCK_H; |
cmd <<= 1; |
} |
SCK_L; |
nSEL_H; |
} |
void RF_WRITE_DATA(uint8_t data) |
{ |
uint8_t i; |
for (i=0;i<8;i++) |
{ |
while (nIRQ_INPUT); |
while (!nIRQ_INPUT); |
if (data & 0x80)FSK_H; |
else FSK_L; |
data <<= 1; |
} |
} |
int main() |
{ |
uint8_t i,j,ChkSum; |
IO_INIT(); |
RF_INIT(); |
LED_H; |
delay_ms(100); |
RF_WRITE_CMD(CMD_STATUS); |
RF_WRITE_CMD(CMD_SETTING |BAND_868 |C_12pF |TX_DEV_90); |
RF_WRITE_CMD(CMD_FREQUENCY |FREQUENCY_868); |
RF_WRITE_CMD(0xD040); |
RF_WRITE_CMD(CMD_RATE |RATE_19200); |
RF_WRITE_CMD(CMD_BATTERY |TX_EBS); |
RF_WRITE_CMD(CMD_POWER |POWER_DC); |
RF_WRITE_CMD(POWER_OUT_0); |
j= 0; |
while (1) |
{ |
LED_H; |
START_TX; |
ChkSum = 0; |
for (i=0;i<3;i++) RF_WRITE_DATA(0xAA); |
RF_WRITE_DATA(0x2D); |
RF_WRITE_DATA(0xD4); |
for (i=0;i<16;i++) |
{ |
RF_WRITE_DATA(test[i]); |
ChkSum += test[i]; |
} |
RF_WRITE_DATA(ChkSum); |
RF_WRITE_DATA(0xAA); |
RF_WRITE_DATA(0xAA); |
STOP_TX; |
LED_L; |
delay_ms(500); |
j++; |
test[13]=(j/100)+0x30; |
test[14]=((j%100)/10)+0x30; |
test[15]=((j%100)%10)+0x30; |
} |
return 0; |
} |
/Designs/HOPEwireless/SW_TX_RFM02/atmel/TX_RFM02.hex |
---|
0,0 → 1,39 |
:100000000C942A000C9447000C9447000C94470071 |
:100010000C9447000C9447000C9447000C94470044 |
:100020000C9447000C9447000C9447000C94470034 |
:100030000C9447000C9447000C9447000C94470024 |
:100040000C9447000C9447000C9447000C94470014 |
:100050000C94470011241FBECFE5D4E0DEBFCDBF16 |
:1000600010E0A0E6B0E0EEE3F2E002C005900D92F1 |
:10007000A237B107D9F710E0A2E7B0E001C01D92A6 |
:10008000A237B107E1F70E948C000C941E010C947A |
:100090000000AC01892B59F020E030E08AEF90E0BD |
:1000A0000197F1F72F5F3F4F24173507B9F70895F0 |
:1000B000BB9ABC98BD9A8A98BA9AA19AA39A0895B5 |
:1000C000C29AC39AC59880B386B3A99A0895C59871 |
:1000D000C29820E0C598C598992314F4C39A01C02A |
:1000E000C398C59AC59A2F5F203119F0880F991FC0 |
:1000F000F1CFC598C29A089590E08299FECF829B75 |
:10010000FECF882314F4A99A01C0A9989F5F983064 |
:1001100010F4880FF2CF0895CF92DF92EF92FF9202 |
:100120000F931F93CF93DF930E9458000E946000AB |
:10013000AB9A84E690E00E94490080E09CEC0E942B |
:10014000670082E790E90E94670080E496EA0E94D7 |
:10015000670080E490ED0E94670081E198EC0E94C6 |
:10016000670080E292EC0E94670081E090EC0E94C0 |
:10017000670080E090EB0E94670000E00F2EF0E641 |
:10018000CF2EF0E0DF2EF02DEE24FF246894E4F86B |
:10019000EC0CFD1CAB9A89E390EC0E94670010E028 |
:1001A0008AEA0E947C001F5F1330D1F78DE20E9423 |
:1001B0007C0084ED0E947C00E60110E088810E94B2 |
:1001C0007C008991180FCE15DF05C1F7812F0E94A1 |
:1001D0007C008AEA0E947C008AEA0E947C0081E01E |
:1001E00090EC0E946700AB9884EF91E00E94490078 |
:1001F0000F5F802F64E60E941201805D80936D0086 |
:10020000802F0E941201292F892F6AE00E9412017B |
:10021000805D80936E00822F0E941201905D90930A |
:100220006F00B8CF991B79E004C0991F961708F0AA |
:0E023000961B881F7A95C9F780950895FFCF19 |
:10023E000A0D41546D65676131360A0D202D2D2D45 |
:02024E000000AE |
:00000001FF |