' ########################################################################################################################################## ' ### RFM 12 Tranceiver ' ### Programmed in CuBasic (cubloc.com) ' ### by MajorTwip (@twipnet.ch) ' ### 29.02.2012 --> Base ### ' ########################################################################################################################################## ' ### ### ' ### RFM12 Master ### ' ### --------------- ### ' ########################################################################################################################################## Const Device = CT1720 Const SS = 4 ' Define Ports for SPI (RFM) / nSel Const MOSI = 5 ' SDI Const MISO = 6 ' SDO Const SCK = 7 ' SCK Const Power = 3 ' VDD Output Power ' Set Pin directions (SS & Power high (5V)) High Power Output SS High SS Output MOSI Input MISO Output SCK Dim Temp As Integer Set Spi SCK, MOSI, MISO, 1 ' Set SPI Wait 2000 InitRF Temp = SPItrans(&hCA81) Temp = SPItrans(&hCA83) Temp = SPItrans(&h0000) Do Do Loop While In(MISO)=0 Low SS Print Hex6 Spi(0,24) High SS Temp= SPItrans(&h0000) Temp = SPItrans(&hca81) Temp = SPItrans(&hca83) Loop Sub RecvRF() Print "Recv" Debug Hex2 ReadFIFO() Temp = SPItrans(&hCA80) Temp = SPItrans(&hCA83) Temp = SPItrans(&h0000) End Sub Function ReadFIFO() As Byte Low SCK Low MOSI Low SS Temp= Spi(0,16) ReadFIFO = Spi(0,8) High SS End Function Sub PrintBit(Wert As Integer) 'Print Bitwise Debug Dec Wert.Bit15 Debug Dec Wert.Bit14 Debug Dec Wert.Bit13 Debug Dec Wert.Bit12 Debug " ",Dec Wert.Bit11 Debug Dec Wert.Bit10 Debug Dec Wert.Bit9 Debug Dec Wert.Bit8 Debug " ", Dec Wert.Bit7 Debug Dec Wert.Bit6 Debug Dec Wert.Bit5 Debug Dec Wert.Bit4 Debug " ", Dec Wert.Bit3 Debug Dec Wert.Bit2 Debug Dec Wert.Bit1 Debug Dec Wert.Bit0 Debug " ", Hex4 Wert, Cr End Sub Function SPItrans(SendData As Integer) As Integer Low SS SPItrans = Spi(SendData, 16) High SS End Function Sub InitRF() 'Dim Temp As Integer 'Debug "Setting Reg 8",Cr Temp = &b1000000000000000 Temp = Temp + 128 'Enable TX register Temp = Temp + 64 'Enable RX FIFO buffer 'Temp = Temp + 32 '00 = 315Mhz, 01 = 433, 10=868, 11 = 915 Temp = Temp + 16 '00 = 315Mhz, 01 = 433, 10=868, 11 = 915 Temp = Temp + 8 '0000=8.5pF, 1111=16pF 'Temp = Temp + 4 ' 'Temp = Temp + 2 ' 'Temp = Temp + 1 ' PrintBit Temp Temp =SPItrans(Temp) 'Debug "Power Management Reg 10",Cr Temp = &b1000001000000000 Temp = Temp + 128 'Enable receiver Temp = Temp + 64 'Enable base band block 'Temp = Temp + 32 'Enable transmitter Temp = Temp + 16 'Enable synthesizer Temp = Temp + 8 'Enable crystal oscilator 'Temp = Temp + 4 'Enable low battery detector 'Temp = Temp + 2 'Enable wake up timer 'Temp = Temp + 1 'Disable Clock of CLKpin PrintBit Temp Temp =SPItrans(Temp) 'Debug "Frequency Reg AX",Cr Temp = &b1010000000000000 Temp = Temp + &h640 '315band: Fc=310+F*0.0025 MHz '433 '433band: Fc=430+F*0.0025 MHz '868band: Fc=860+F*0.0050 MHz '915band: Fc=900+F*0.0075 MHz PrintBit Temp Temp =SPItrans(Temp) 'Debug "Baudrate Reg",Cr Temp = &b1100011000000000 Temp = Temp + &h47 'BR=10000000/29/iR+1j/i1+cs*7j ' 4k8 PrintBit Temp Temp =SPItrans(Temp) 'Debug "Receiver Reg",Cr Temp = &b1001000000000000 Temp = Temp + 1024 '1=Pin20 VDI, 0=External Interrupt 'Temp = Temp + 512 'VDI response 'Temp = Temp + 256 '00=fast,01=med, 10=slow, 11=always on Temp = Temp + 128 'Baseband bandwith 'Temp = Temp + 64 '001=400kHz --> 110=67kHz Temp = Temp + 32 '001=400kHz --> 110=67kHz 'Temp = Temp + 16 'LNA gain 'Temp = Temp + 8 '00=0dBm --> 11=20dBm 'Temp = Temp + 4 'DRSSI threshold 'Temp = Temp + 2 '000=103dBm --> 101= -61dBm 'Temp = Temp + 1 '000=103dBm --> 101= -61dBm PrintBit Temp Temp =SPItrans(Temp) 'Debug "Data Filter Reg",Cr Temp = &b1100001000101000 Temp = Temp + 128 'Enable clock recovery auto-lock 'Temp = Temp + 64 'Enable clock recovery fast mode 'Temp = Temp + 16 '0=digital filter, 1=Analog RC filter Temp = Temp + 4 'DQD threshold 'Temp = Temp + 2 '000=103dBm --> 101= -61dBm 'Temp = Temp + 1 '000=103dBm --> 101= -61dBm PrintBit Temp Temp =SPItrans(Temp) 'Debug "Output & FIFO mode command",Cr Temp = &b1100101000000000 Temp = Temp + 128 'FIFO interupt level 'Temp = Temp + 64 ' 'Temp = Temp + 32 ' 'Temp = Temp + 16 ' Temp = Temp + 4 '0= Syncword, 1=Always 'Temp = Temp + 2 'Enable FIFO 'Temp = Temp + 1 'Disable HiSens reset mode PrintBit Temp Temp =SPItrans(Temp) 'Debug "Output & FIFO mode command 2",Cr Temp = &b1100101000000000 Temp = Temp + 128 'FIFO interupt level 'Temp = Temp + 64 ' 'Temp = Temp + 32 ' 'Temp = Temp + 16 ' 'Temp = Temp + 4 '0= Syncword, 1=Always Temp = Temp + 2 'Enable FIFO Temp = Temp + 1 'Disable HiSens reset mode PrintBit Temp Temp =SPItrans(Temp) 'Debug "AFC Command C4",Cr Temp = &b1100010000000000 Temp = Temp + 128 'AFC auto.mode 00=MCU, 01=once on power-on 'Temp = Temp + 64 '10=Keep offset if VDI high, 11=independence from VDI 'Temp = Temp + 32 'range limit 00=no restriction 'Temp = Temp + 16 '01=+15-16, 10=+7-8, 11=+3-4 'Temp = Temp + 8 'will store offset to output reg 'Temp = Temp + 4 'AFC high accuracy mode Temp = Temp + 2 'AFC output reg Temp = Temp + 1 'AFC function PrintBit Temp Temp =SPItrans(Temp) 'Debug "AFC Command 98",Cr Temp = &b1001100000000000 'Temp = Temp + 256 'modulation polarity 'Temp = Temp + 128 'frequency deviation Temp = Temp + 64 ' 'Temp = Temp + 32 ' Temp = Temp + 16 ' 'Temp = Temp + 4 'Output power 000=0 'Temp = Temp + 2 ' 'Temp = Temp + 1 '101=-21 PrintBit Temp Temp =SPItrans(Temp) 'Debug "WakeupTimer",Cr Temp = &b1110000000000000 'Temp = Temp + 256 'time PrintBit Temp Temp =SPItrans(Temp) 'Debug "Low Duty-Cycle",Cr Temp = &b1100100000000000 'Temp = Temp + &hE 'time PrintBit Temp Temp =SPItrans(Temp) 'Debug "Low Battery, CLK divider",Cr Temp = &b1100000000000000 Temp = Temp + 128 'frequency Temp = Temp + 64 ' 'Temp = Temp + 32 ' PrintBit Temp Temp =SPItrans(Temp) End Sub