RFM12

  • 1
  • 2
  • Page 1 of 2
E.Faber
 
Avatar
 
Subject:

RFM12

 · 
Posted: 14.09.2010 - 10:46  ·  #1
Hallo,

ich versuche gerade das o.g. Funkmodul zum laufen zu bekommen.
Um meine Hardware zu testen habe ich einen funktionierenden Bascom Code
compiliert und aufgespielt - die Module funktionieren. Nun habe ich den Code
auf den AVRco umgeschrieben - und es klappt leider nicht. Vielleicht entdeckt
ja hier jemand meinen Fehler:

Code
' ########################################################################
' # RF12-Test Bascom
' # by Holli
' # Pollin Funk-AVR Board - RFM12 on board
' # FIFO Read using RFM "Status Read Command" - h0000
' # NIRQ or FFIT Polling
' ########################################################################

$regfile = "m16def.dat"
$hwstack = 32
$swstack = 10
$framesize = 40
$crystal = 16000000
$baud = 19200
Baud = 19200

Config Portd.2 = Input
Nirq Alias Pind.2

Config Portd.3 = Input
Ffit Alias Pind.3

Led Alias Portd.5
Config Portd.5 = Output                                     'LED zur Kontrolle

Dim X As Byte
Dim Y As Byte
Dim Count As Byte
Dim Temp As Byte
Dim Rx(32) As Byte
Dim Cmd(2) As Byte
Dim Fifo(4) As Byte

Declare Sub Rf_cmd(byval Wert As Word)

Config Lcdpin = Pin , Db4 = Porta.0 , Db5 = Porta.1 , Db6 = Porta.2 , Db7 = Porta.3 , E = Porta.4 , Rs = Porta.5
Config Lcd = 16 * 2

Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 64 , Noss = 0 , Spiin = &HB0

'init the spi
Spiinit

Waitms 100

Toggle Led

Call Rf_cmd(&H0000)                                         'read status
Call Rf_cmd(&Hc0e0)                                         'low battery, clock 10 MHz
Call Rf_cmd(&H80d7)                                         'Configuration: 433MHzband, 12pf, enable FIFO
Call Rf_cmd(&H82d8)                                         'power management: enable receiver, enable clock output
Call Rf_cmd(&Hc2ac)                                         'data filter command
Call Rf_cmd(&Ha620)                                         'Frequency: 433,92MHz
Call Rf_cmd(&Hc691)                                         'Datarate: 2,4 kbit
Call Rf_cmd(&H94a1)                                         'receiver setting: 134kHz, -97dbm
Call Rf_cmd(&Hc2ac)                                         'data filter:
Call Rf_cmd(&Hc483)                                         'AFC:
Call Rf_cmd(&H9850)                                         'TX control
Call Rf_cmd(&He000)                                         'wake-up
Call Rf_cmd(&Hc800)                                         'low duty-cycle
Call Rf_cmd(&Hca81)                                         'Reset FIFO
Call Rf_cmd(&Hca83)                                         'enable FIFO
Call Rf_cmd(&H0000)                                         'read status


Cls

Do

Toggle Led

For Count = 1 To 32

   Bitwait Nirq , Reset                                     'NIRQ or FFIT
   Spiin Fifo(1) , 2
   Rx(count) = Fifo(2)

Next

Call Rf_cmd(&H0000)                                         'read status
Call Rf_cmd(&Hca81)                                         'Reset FIFO
Call Rf_cmd(&Hca83)                                         'enable FIFO


For Count = 1 To 32
  If Count <= 16 Then
    X = Count
    Y = 1
  Else
    X = Count - 16
    Y = 2
  End If
  Locate Y , X
  Lcd Chr(rx(count))
Next Count


Loop

End


Sub Rf_cmd(byval Wert As Word)
   Cmd(2) = Wert And 255
   Shift Wert , Right , 8
   Cmd(1) = Wert
   Spiout Cmd(1) , 2
End Sub


Und hier meine "Übersetzung" in AVRco:

Code
program RFM12_Empfang;

{ $WG}                     {global Warnings off}

Device = mega16, VCC=5;
{ $BOOTRST $01C00}         {Reset Jump to $01C00}

Import SysTick, LCDport, SPIdriver;

From System Import ;


Define
  ProcClock      = 16000000;       {Hertz}
  SysTick        = 10;             {msec}
  StackSize      = $0032, iData;
  FrameSize      = $0032, iData;
  SPIpresc       = 2;
  SPIOrder       = MSB;
  SPICPOL        = 0;
  SPICPHA        = 0;
  SPI_SS         = true;
  LCDport        = PortA;
  LCDtype        = 44780;
  LCDrows        = 2;              {rows}
  LCDcolumns     = 16;             {columns per line}

Define_Usr
  defSnap_S_Address = 001;
  defSnap_D_Address = 002;

Implementation

{$IDATA}
{$I C:E-lab_IncludeSnapProt.pas}

{--------------------------------------------------------------}
{ Type Declarations }

type


{--------------------------------------------------------------}
{ Const Declarations }

{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
Var
  i,j : Byte;
  Rx  : Array[1..32] Of Byte;
  Cmd : Array[1..2] Of Byte;

  Nirq[@PinD, 2] : Bit; // Alias Pind.2

  Led[@PortD, 5] : Bit; //  Alias Portd.5


{--------------------------------------------------------------}
{ functions }

procedure InitPorts;
begin
  DDRD:=  %00100000;
end InitPorts;


Procedure Rf_cmd(Tmp : Word);
Begin
  Cmd[2] := Hi(Tmp);
  Cmd[1] := Lo(Tmp);
  SpioutByte(Cmd[1]);
  SpioutByte(Cmd[2]);
End Rf_cmd;

{--------------------------------------------------------------}
{ Main Program }
{$IDATA}

begin
  InitPorts;
  
  mDelay(500);

  Toggle(Led);
  
  Rf_cmd($0000);  // read status
  Rf_cmd($c0e0);  // low battery, clock 10 MHz
  Rf_cmd($80d7);  // Configuration: 433MHz Band, 12pf, enable FIFO
  Rf_cmd($82d8);  // power management: enable er, ebb, es, ex
  Rf_cmd($c2ac);  // data filter command
  Rf_cmd($a620);  // Frequency: 433,92MHz
  Rf_cmd($c691);  // Datarate: 2,4 kbit
  Rf_cmd($94a1);  // receiver setting: 134kHz, -97dbm
  Rf_cmd($c2ac);  // data filter:
  Rf_cmd($c483);  // AFC:
  Rf_cmd($9850);  // TX control
  Rf_cmd($e000);  // wake-up
  Rf_cmd($c800);  // low duty-cycle
  Rf_cmd($ca81);  // Reset FIFO
  Rf_cmd($ca83);  // enable FIFO
  Rf_cmd($0000);  // read status

  LCDClr;
  write(LCDOut, '...');
  LCDXY(0,0);
  loop
    Toggle(Led);
    
    For i := 1 To 32 Do
      While Bit(Nirq)=True Do EndWhile;
      Rx[i] := SpiinpByte;
    EndFor;

    Rf_cmd($0000);       // read status
    Rf_cmd($ca81);       // Reset FIFO
    Rf_cmd($ca83);       // enable FIFO

    For i := 1 To 32 Do
      If i <= 16 Then
        LCDXY(i-1,0);
      Else
        LCDXY(i-17,1);
      EndIf;
      write(LCDOut, Char(Rx[i]));
    EndFor;
    
  endloop;
end RFM12_Empfang.


Offensichtlich wird hier
Code
While Bit(Nirq)=True Do EndWhile;
NIRQ nie True.
Da der Bascom-Code funktioniert vermute ich mal einen Fehler meinerseits bei der
Initialisierung der SPI Schnittstelle.
Kann mir hier vielleicht jemand auf die Sprünge helfen?

Viele Grüße

Elmar
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

Re: RFM12

 · 
Posted: 16.09.2010 - 09:49  ·  #2
Code
Spiin Fifo(1) , 2
Rx(count) = Fifo(2)

This Reads 2 bytes, and stores 2nd byte to Rx(count). This is not what you do. In your code you read 1 byte and then wait for Nirq to reset.
E.Faber
 
Avatar
 
Subject:

Re: RFM12

 · 
Posted: 16.09.2010 - 11:11  ·  #3
Oh, thanks that's right, but I have found another error.
If I use the Hard SPI driver I have to set the ss to false.
The frm12 transmitter reads the commands when the ss go
to logical high.

This code works:
Code
...
  SPICPHA        = 0;
  SPI_SS         = false;
...
...
Var
  nSEL[@PortB, 4] : Bit;

Procedure Rf_cmd(Tmp : Word);
Begin
  Cmd[1] := Hi(Tmp);
  Cmd[2] := Lo(Tmp);
  nSel := 0;
  SpiOutByte(Cmd[1]);
  SpiOutByte(Cmd[2]);
  nSel := 1;
End Rf_cmd;


The problem is now to find how the requestet data are so bad.

Thanks for your help
uli
 
Avatar
 
Subject:

RFM12

 · 
Posted: 13.02.2011 - 10:33  ·  #4
Hi Elmar,

did you ever get this module to work properly?

Uli
E.Faber
 
Avatar
 
Subject:

Re: RFM12

 · 
Posted: 14.02.2011 - 14:17  ·  #5
Hi Uli,

yes it works fine.

Elmar
Jony09
 
Avatar
 
Subject:

Re: RFM12

 · 
Posted: 14.02.2011 - 14:28  ·  #6
Würden Sie die Funktionen zur Verfügung stellen?

Gruß Johannes
E.Faber
 
Avatar
 
Subject:

Re: RFM12

 · 
Posted: 14.02.2011 - 16:06  ·  #7
Hallo Johannes,

ja klar, allerdings müßte ich erst ein paar grundlegende Informationen für die
Routinen heraussuchen, damit man etwas damit anfangen kann - war so ein
Projekt, was wo alles ging, von mir nie verwendet wurde und ich mir für die Doku
nur wenig Zeit genommen habe...
Es ist auch keine Unit, da ich nur mit der Demo bzw. Atmega8 Version arbeite.

Viele Grüße

Elmar
Jony09
 
Avatar
 
Subject:

Re: RFM12

 · 
Posted: 14.02.2011 - 16:11  ·  #8
Hallo Elmar,

das ist super. Eine Unit könnte ich selbst daraus machen, habe die Profiversion. Ich bin halt auf der suche nach einer Preiswerten Funkverbindung für ein paar Daten.

Kannst du mir ja per PN oder auch per e-mail Schicken johannes@jp-elektronik.de

Danke nochmals Johannes
  • 1
  • 2
  • Page 1 of 2
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   130   144 · Page-Gen-Time: 0.022046s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI