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:
Und hier meine "Übersetzung" in AVRco:
Offensichtlich wird hier 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
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
' # 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.
{ $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;
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