Hallo,
ich suche schon seit Wochen alle Deutschen und Englischen Foren durch nach einer Lösung meinen RFM12BS zum laufen zu bekommen.Alles was ich gefunden haben waren Projektvorstellungen (mit fertigen komplizierten Codes) ,scheinbar simple codes (die es aber nicht sind,weil oft Parameter verlangt werden von denen ich nicht weis woher ich die herbekommen soll) und Codes die eine andere Hardware erfordern und ich in der Header-Datei nirgends die Pinbelegung finde die ich meiner Hardware anpassen kann.
Ich such einfach einen Code wo gezeigt wird wie man das Modul Initialisiert, ein Bit-Packet sendet (z.B. für Funksteckdose 0x000000000FFF ) und Bits Empfängt und über Serial-Monitor ausgibt.Und das in Arduino und nicht in C , weil ich keinen Programmer habe und nur über den Bootloader Brenne.
Ich habe von Julian Portik einen Code gefunden (den ich zum größten Teil verstanden habe),der war leider in C und ich habe mich versucht ihn in Arduino umzuschreiben. Leider kann ich keine C sondern nur Java und lerne Arduino und so kam es wie es kommen sollte, dass es nicht funktioniert.
Also versuch ich jetzt jemanden um hilfe zu bitten,da ich schon verzweifelt bin und mir schon andere Module bestellt habe die nicht über SPI arbeiten.
/*
* RFM12.c
*
* Created: 07.02.2013 15:34:00
* Author: Julian Portik
*/
#include <io.h>
const int RFM12_SEL_Pin = 18; // SEL Pin
const int RFM12_SDI_Pin = 51 ; // SDI Pin
const int RFM12_SDO_Pin = 35 ; // SDO Pin
const int RFM12_SCK_Pin = 52 ; // SCK Pin
const int RFM12_IRQ_Pin = 34 ; // IRQ Pin
#define RFM12_SEL_on() digitalWrite(RFM12_SEL_Pin, LOW)
#define RFM12_SEL_off() digitalWrite(RFM12_SEL_Pin, HIGH)
#define RFM12_SDI_on() digitalWrite(RFM12_SDI_Pin, HIGH)
#define RFM12_SDI_off() digitalWrite(RFM12_SDI_Pin, LOW)
#define RFM12_SCK_on() digitalWrite(RFM12_SCK_Pin, HIGH)
#define RFM12_SCK_off() digitalWrite(RFM12_SCK_Pin, LOW)
#define RFM12_command_CONF 0b1000000000000000 // Configuration Setting Command
#define RFM12_command_PWR 0b1000001000000000 // Power Management Command
#define RFM12_command_FREQ 0b1010000000000000 // Frequency Setting Command
#define RFM12_command_DTRT 0b1100011000000000 // Data Rate Command
#define RFM12_command_RXCT 0b1001000000000000 // Receiver Control Command
#define RFM12_command_DFLT 0b1100001000000000 // Data Filter Command
#define RFM12_command_FFRM 0b1100101000000000 // FIFO Reset Mode Command
#define RFM12_command_RXFR 0b1011000000000000 // Receiver FIFO Read Command
#define RFM12_command_AFC 0b1100010000000000 // AFC Command
#define RFM12_command_TXCC 0b1001100000000000 // TX Configuration Control Command
#define RFM12_command_TXRW 0b1011100000000000 // Transmitter Register Write Command
#define RFM12_command_WAKE 0b1110000000000000 // Wake-Up Timer Command
#define RFM12_command_LDC 0b1100100000000000 // Low Duty-Cycle Command
#define RFM12_command_BDCD 0b1100000000000000 // Low Battery Detector / Clock Divider Command
#define RFM12_command_STAT 0b0000000000000000 // Status Read Command
#define Steckdose_A_1_on 0x000000000FFF
#define Steckdose_A_1_off 0x000000000FF0
#define RFM12_PWR_off RFM12_command (RFM12_command_PWR | 0b00000001);
#define RFM12_TX_on RFM12_command (RFM12_command_PWR | 0b00111001);
#define RFM12_TX_off RFM12_command (RFM12_command_PWR | 0b00000001);
#define RFM12_RX_on RFM12_command (RFM12_command_PWR | 0b11011001);
#define RFM12_RX_off RFM12_command (RFM12_command_PWR | 0b00011001);
#define RFM12_FIFO_on RFM12_command (RFM12_command_FFRM | 0b10000011);
#define RFM12_FIFO_off RFM12_command (RFM12_command_FFRM | 0b10000001);
#define RFM12_AFC_on RFM12_command (RFM12_command_AFC | 0b01000011);
#define RFM12_AFC_off RFM12_command (RFM12_command_AFC | 0b01000010);
void setup() {
pinMode(RFM12_SEL_Pin, OUTPUT); // SEL = Output
pinMode(RFM12_SDI_Pin, OUTPUT); // SDI = Output
pinMode(RFM12_SDO_Pin, INPUT); // SDO = Input
pinMode(RFM12_SCK_Pin, OUTPUT); // SCK = Output
pinMode(RFM12_IRQ_Pin, INPUT); // IRQ = Input
RFM12_init();
}
void loop() {
delay(250);
while (3)
{
RFM12_command (RFM12_command_STAT);
RFM12_TX_on;
RFM12_send (0xAA);
RFM12_send (0xAA);
RFM12_send (0xAA);
RFM12_send (0x2D);
RFM12_send (0xD4);
RFM12_send (Steckdose_A_1_on);
delay(10);
RFM12_TX_off;
delay(1000);
RFM12_TX_on;
RFM12_send (0xAA);
RFM12_send (0xAA);
RFM12_send (0xAA);
RFM12_send (0x2D);
RFM12_send (0xD4);
RFM12_send (Steckdose_A_1_off);
delay(10);
RFM12_TX_off;
}
}
void RFM12_init ()
{
RFM12_SEL_off() ;
RFM12_SDI_on() ;
RFM12_SCK_off() ;
RFM12_PWR_off;
RFM12_command (RFM12_command_FREQ | 1200); // Frequenz
RFM12_command (RFM12_command_DTRT | 36); // Datenrate 9600 kbps
RFM12_command (RFM12_command_CONF | 0b11010111); // Enable
RFM12_command (RFM12_command_RXCT | 0b10010100000); // Receiver Control Command
RFM12_command (RFM12_command_DFLT | 0b10101100); // Data Filter
RFM12_command (RFM12_command_TXCC | 0b001010000); // TX Config
RFM12_command (RFM12_command_PWR | 0b11111000);
RFM12_FIFO_on;
RFM12_AFC_on;
RFM12_command (RFM12_command_STAT);
}
int RFM12_command (int command)
{
int serial_data = 0;
RFM12_SEL_on ();
char i;
for (i = 0; i < 16; i++)
{
if (command & 0x8000) RFM12_SDI_on (); else RFM12_SDI_off ();
command <<= 1;
RFM12_SCK_on ();
serial_data <<= 1;
if (bit(RFM12_SDO_Pin)) serial_data |= 0x0001;
delay(1);
RFM12_SCK_off ();
}
RFM12_SEL_off ();
return serial_data;
}
void RFM12_send (unsigned char senden)
{
delay(1);
RFM12_command (RFM12_command_TXRW | senden);
}
unsigned char RFM12_receive ()
{
delay(1);
RFM12_command (RFM12_command_STAT);
return RFM12_command (RFM12_command_RXFR) & 0x00FF;
}