Sunday, February 17, 2013
SPI experiments - RFM12B
http://www.blogger.com/blogger.g?blogID=1840459474737789074#editor/target=post;postID=3843453428734176142
Now I am reading my old blog posts to refresh my memory of the RFM12B, very first SPI device I played, about three and half years ago.
.END
Wireless Transceiver 433MHz RFM12B Experiments 1 - 2009年11月6日
http://blog.yahoo.com/_ZGD2MIDSBMSKHSUJW23LXRS2EQ/articles/8583/category/My+Arduino+RFM12B
RFM12B Preliminary Test 2009/07
http://space.taobao.com/12d9ec1e98a6515fa89aa39751189943/show_blog-24340125.htm
Like what I did to test the RF module some two months ago, I usually did a 2 step preliminary self diagnostic test to make sure that the module is more or less working.
1. Use a scope to display pin 8 of the module. This pin should display the defualt external mcu use frequency of 1.000 MHz.
2. Use an Arduino program to change the ext mcu frequency to 2.000 MHz. This makes sure the following.
a. the module can be initialized.
b. the module can accept commands from Arduino.
c. the module can decode and exectue commands.
So I did the test and it took a few minutes for me to debug the 2MHz test program (I forgot to bypass the default disable ext clock init command.
So far so good. I guess I will repeat the other test functions and add them into the function library.
// *****************************************************************************
// RFM12B01.pde v0.01a - Example for RFM12B library functions 2009jul07hkt1529
// Created by TL Fong, 2009jul04
// Released into the public domain for learning. No commercial.
// *****************************************************************************
#include
#define SCK_PIN 13
#define SDO_PIN 11
#define SDI_PIN 12
#define CS_PIN 10
#define NIRQ_PIN 2
void setup()
{
}
void loop()
{
RFM12B01 rfm1(SCK_PIN, SDO_PIN, SDI_PIN, CS_PIN, NIRQ_PIN);
rfm1.testSetupClock2Mhz();
while(true)
{
}
}
// *****************************************************************************
// RFM12B01.h v0.02a - RFM12B library functions 2009jul07hkt523
// Created by TL Fong, 2009jul04
// Released into the public domain for learning. No commercial.
// *****************************************************************************
#ifndef RFM12B01_h
#define RFM12B01_h
#include "WProgram.h"
# define wkupOn 0x820E // turn on wake up timer (also xtl, lvd)
# define wkupOff 0x820C // turn off wake up timer (xtl, lvd still on)
# define wkup2ms 0XE002 // wake up every 2mS
# define config01 0x80D7
# define power01 0x8239
# define freq01 0xA640
# define drate01 0xC647
# define rxctrl01 0x94A0
# define fifors01 0xCA81
# define syncpt01 0xCED4
# define afc01 0xC483
# define txctrl01 0x9850
# define pll01 0xCC77
# define wkup01 0xE000
# define ldc01 0xC800
# define lbdclk01 0xC400
# define lvdOn 0x820C // turn on low voltage detection (also xtal, mcu clk)
# define lvd27 0xC064 // set low voltage threshold 2.7V (2.2 + 0.1 * 4) 2MHz,
# define status 0x0000 // read status to execute command and clear interrupt
# define clkMhz01 0xC004 // 01MHz, 2.7V (2.2 + 0.1 * 4)
# define clkMhz02 0xC064 // 02MHz, 2.7V (2.2 + 0.1 * 4)
# define clkMhz05 0xC0C4 // 05MHz, 2.7V (2.2 + 0.1 * 4)
# define clkMhz10 0xC0E4 // 10MHz, 2.7V (2.2 + 0.1 * 4)
class RFM12B01
{
public:
RFM12B01(int sckPin, int sdoPin, int sdiPin, int csPin, int nirqPin);
void putWord(unsigned int xWord);
void setupArduinoPins();
void setupRfm12b();
void sendChar(unsigned char data);
void sendFrame();
void testSetupClock2Mhz();
private:
int _sckPin;
int _sdoPin;
int _sdiPin;
int _csPin;
int _nirqPin;
};
#endif
// *****************************************************************************
// RFM12B01.cpp RFM12B01 Library v0.01a 2009jul07hkt1528 TL Fong
// Hope RFM12B v2.0, Seeeduino v1.1, Arduino 15
// Released into the public domain for learning. No commercial.
// *****************************************************************************
#include "WProgram.h"
#include "RFM12B01.h"
RFM12B01::RFM12B01(int sckPin, int sdoPin, int sdiPin, int csPin, int nirqPin)
{
_sckPin = sckPin;
_sdoPin = sdoPin;
_sdiPin = sdiPin;
_csPin = csPin;
_nirqPin = nirqPin;
setupArduinoPins();
setupRfm12b();
}
void RFM12B01::setupArduinoPins()
{
digitalWrite(_sckPin, LOW);
digitalWrite(_sdoPin, LOW);
digitalWrite(_csPin, LOW);
pinMode(_sckPin, OUTPUT);
pinMode(_sdoPin, OUTPUT);
pinMode(_csPin, OUTPUT);
pinMode(_sdiPin, INPUT);
pinMode(_nirqPin, INPUT);
}
void RFM12B01::putWord(unsigned int xWord)
{
int i;
digitalWrite(_csPin, LOW);
digitalWrite(_sckPin, LOW);
for(i = 0; i < 16; i++)
{
if (xWord & 0x8000)
digitalWrite(_sdoPin, HIGH); // if MSB (most significant bit) is 1 then prepare to output HIGH
else
digitalWrite(_sdoPin, LOW); // else output LOW
digitalWrite(_sckPin, HIGH); // clock high to output bit
digitalWrite(_sckPin, LOW); // clock low to get ready for next bit
xWord <<= 1; // shift next bit to MSB position
}
digitalWrite(_csPin, HIGH); // execute command
}
void RFM12B01::setupRfm12b()
{
putWord(0x80D7); //enable tx, rx fifo, 433MHz, 12.0pF
// putWord(0x8239); //enable xmitt, syn, xtal, disable clk
putWord(0xA640); //operation frequency ???
putWord(0xC647); //data rate 4.8kbps
putWord(0x94A0); //VDI,FAST,134kHz,0dBm,-103dBm
putWord(0xC2AC); //clk rec auto, digi fltr,DQD4
putWord(0xCA81); //fifo8,sync 1, sync, no fifo fill
putWord(0xCED4); //sync pattern d4
putWord(0xC483); //offset VDI hi, no restrict, afc, afc out
putWord(0x9850); //90kHz, max o/p pwr (odBm)
putWord(0xCC17); //10MHz, 620uA, disable pll dit, 256kbps
putWord(0xE000); //wake up timer not used
putWord(0xC800); //low duty cycle not used
putWord(0xC040); //1.66MHz,2.2V low battery
}
void RFM12B01::testSetupClock2Mhz()
{
putWord(0xC064);
}
.END
Wireless Transceiver 433MHz RFM12B Experiments 2 - 2009年11月6日
http://blog.yahoo.com/_ZGD2MIDSBMSKHSUJW23LXRS2EQ/articles/8584/category/My+Arduino+RFM12B
I have made a new version of the 6 pin SPI connector between Seeeduino and RFM12B.
http://space.taobao.com/blog/12d9ec1e98a6515fa89aa39751189943/myindex/show_blog-24338968.htm
.END
No comments:
Post a Comment