|
|
View previous topic :: View next topic |
Author |
Message |
Jody
Joined: 08 Sep 2006 Posts: 182
|
RFM12B nIRQ pin |
Posted: Thu Sep 16, 2010 1:52 am |
|
|
Hello,
Right now I have communications between two PIC's using both a RFM12B RF module. So far so good.
But at this moment I can receive data only when I ongoing check for data.
At that moment the received data is correct and the same as I send.
But there is a nIRQ pin on the RFM12B module, which I want to use to notify me that there is data waiting for me, but whatever I do I can't get it react on the incoming data. So I can't put the responsible in a ISR function.
Is there somebody who has done this before???
Regards,
Jody |
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
|
Jody
Joined: 08 Sep 2006 Posts: 182
|
|
Posted: Thu Sep 16, 2010 12:30 pm |
|
|
Yep I did see this way.
And that's exact what I want.
I poll the nIRQ line but never is goes low.
Regards,
Jody |
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
|
Jody
Joined: 08 Sep 2006 Posts: 182
|
|
Posted: Fri Sep 17, 2010 3:02 am |
|
|
Well if you want I can send you the code I use at the transmitter and the receiver.
It works... accept the nIRQ pin.
Maybe you can find the 'mistake'. |
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
Posted: Fri Sep 17, 2010 1:44 pm |
|
|
i can take a look. either post it here or pm me |
|
|
exjra
Joined: 25 Sep 2010 Posts: 3
|
|
Posted: Sat Sep 25, 2010 9:59 am |
|
|
hi
I use this modules too, but i can't receive any data.
I can't debug during at working this modules, but I think transmitter is working. But receiver module dont work. I noticed nIRQ pin of receiver is never be low.
If you able to work this modules (transmitter and receiver) can you help me and can you send me microcontroller codes for PIC16F73 at C language?
e-mail: exjra@hotmail.com |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sat Sep 25, 2010 2:36 pm |
|
|
Are you sending the correct sync pattern?.
The IRQ on the receiver, line doesn't drop, till the receiver is synced, and data is received.
Best Wishes |
|
|
exjra
Joined: 25 Sep 2010 Posts: 3
|
|
Posted: Mon Sep 27, 2010 6:44 am |
|
|
My issue still unresolved. As you see I'm managed to make transmitter/receiver work with those source code you sent. The data receiver received are being sent to the PC by USART. I'm sending those data PC received to you. I could not understand where is the problem. can you help me?
TRANSMITTER CODE:
Code: |
#include <16F73.h>
#device adc=8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NOBROWNOUT
#use delay(clock=10000000)
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/// ///
/// #### ##### # # # ## #### ///
/// # # # ## ## ## # # # # ///
/// #### #### # ## # # # # #### ///
/// # # # # # # # # # ///
/// # # # # # # # # # ///
/// # # # # # # #### #### ///
/// ///
/// RFM12B Driver ///
/// ///
/////////////////////////////////////////////////////////
/// ///
/// Functions: ///
/// ///
/// RFM12B_INIT(int type) ///
/// RFM12B_SEND(int buffer, int size) ///
/// RFM12B_RECEIVE(int buffer, int size) ///
/// ///
/////////////////////////////////////////////////////////
/// ///
/// Updates: ///
/// ///
/// 09.01.2010 New Driver ///
/// ///
/////////////////////////////////////////////////////////
/// ///
/// Code was written by Severin Birrer ///
/// More informations at www.blucorazon.ch ///
/// ///
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/// ///
/// PIN settings ///
/// ///
/////////////////////////////////////////////////////////
#define MOSI PIN_C4 //cikis
#define MISO PIN_C5
#define nSEL PIN_C2
#define SCK PIN_C3
#define IRQ PIN_B0
#define LED PIN_A0
#define LED3 PIN_B2
#define LED4 PIN_B3
/////////////////////////////////////////////////////////
/// ///
/// Definitions ///
/// ///
/////////////////////////////////////////////////////////
#define MOSI_hi() output_high(MOSI)
#define MOSI_lo() output_low(MOSI)
#define nSEL_hi() output_high(nSEL)
#define nSEL_lo() output_low(nSEL)
#define SCK_hi() output_high(SCK)
#define SCK_lo() output_low(SCK)
#define in_MISO() input(MISO)
#define in_IRQ() input(IRQ)
#define TX 1
#define RX 0
int16 RFM12B_READ_STATUS(void);
void RFM12B_FIFO_RESET(void);
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_PORT_INIT ///
/// Function: Initalise ports to defined states ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_PORT_INIT(void)
{
nSEL_hi();
SCK_lo();
MOSI_lo();
delay_ms(100);
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_CMD ///
/// Function: Sends command and receives data ///
/// ///
/////////////////////////////////////////////////////////
int16 RFM12B_CMD(int16 cmd)
{
int i;
int16 temp=0;
SCK_lo();
nSEL_lo();
for(i=0;i<16;i++)
{
if(cmd&0x8000)
{
MOSI_hi();
}
else
{
MOSI_lo();
}
delay_us(5);
SCK_hi();
delay_us(5);
temp<<=1;
if(in_MISO())
{
temp|=0x0001;
}
SCK_lo();
cmd<<=1;
}
nSEL_hi();
return(temp);
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_WAIT_READY ///
/// Function: Wait for RFM12B to be ready (FFIT) ///
/// ///
/////////////////////////////////////////////////////////
int16 RFM12B_WAIT_READY(void)
{
unsigned int16 data;
nSEL_lo();//test
while(!in_MISO())
;//test
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_READ ///
/// Function: Wait and read a byte from FIFO ///
/// ///
/////////////////////////////////////////////////////////
int16 RFM12B_READ(void)
{
int16 data;
// RFM12B_WAIT_READY();
data = RFM12B_CMD(0xB000); // Read Data
return (data&0x00FF);
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_WRITE ///
/// Function: Write a byte ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_WRITE(int abyte)
{
RFM12B_WAIT_READY();
RFM12B_CMD(0xB800 + abyte); // Write Data
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_INIT ///
/// Function: Initalise as a sender or a receiver ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_INIT(int type)
{
RFM12B_PORT_INIT();
delay_ms(200);
if (type)
{
// Init Sender
RFM12B_CMD(0x80A8); // Configuration Command 868MHz 12,pF Enable Tx Register
}
else
{
// Init Receive
RFM12B_CMD(0x8068); // Configuration Command 868MHz 12,5pF Enable Rx FIFO buffer
}
// General Init
RFM12B_CMD(0x82D8); // Power Management Command Enable Crystal Osc.
RFM12B_CMD(0xA640); // Frequency Command Center Frequency 868.3200 MHz
RFM12B_CMD(0xC647); // Datarate Command Data Rate 4.789kbps
RFM12B_CMD(0x94A5); // Receiver Control Command VDI, Fast, 134kHz, Max, -73dBm
RFM12B_CMD(0xC2EC); // Datafilter Command Auto, Slow, Digital, 4
RFM12B_CMD(0xCA8B); // FIFO / Reset Mode Command 8, 1 bytes, Synchrone, Low, FIFO Fill Enabled
RFM12B_CMD(0xCED4); // Synchron Pattern Command Synchron byte(LSB) D4
RFM12B_CMD(0xC483); // AFC Command
RFM12B_CMD(0x9827); // TX Configuration Command
RFM12B_CMD(0xCC77); // PLL Command
RFM12B_CMD(0xE000); // Wake-Up Timer Command
RFM12B_CMD(0xC800); // Low Duty-Cycle Command
RFM12B_CMD(0xC000); // LB Det./Clock Div. Command 2.2V, 1.66MHz
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_SEND ///
/// Function: Send multiple bytes ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_SEND(int *ptr, int16 size)
{
int16 i;
RFM12B_CMD(0x8238); // Enable Sender
RFM12B_WRITE(0xAA); // Preamble
RFM12B_WRITE(0xAA); // Preamble
RFM12B_WRITE(0xAA); // Preamble
RFM12B_WRITE(0xCE); // Sync HighByte
RFM12B_WRITE(0xD4); // Sync LowByte
for (i=0;i<size;i++)
{
RFM12B_WRITE(*ptr); // DATA Byte
ptr++;
}
RFM12B_WRITE(0xAA); // Dummy Byte
RFM12B_WRITE(0xAA); // Dummy Byte
RFM12B_WRITE(0xAA); // Dummy Byte
RFM12B_WAIT_READY();
RFM12B_CMD(0x8208); // Disable Sender
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_RECEIVE ///
/// Function: Receive multiple bytes ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_RECEIVE(int *ptr, int16 size)
{
int16 i;
//RFM12B_CMD(0x82C8); // Init Receiver//test
RFM12B_CMD(0x82D8); // Init Receiver//Candy
//RFM12B_CMD(0xCA81); // Enable FIFO//test
//RFM12B_CMD(0xCA83); // Clear FIFO//test
for (i=0;i<size;i++)
{
*ptr = RFM12B_READ(); // Send Data
ptr++;
}
//RFM12B_CMD(0x8208); // Disable Receiver test of we hem wel aan laten staan
//RFM12B_CMD(0xCA83); // Clear FIFO//test
//RFM12B_FIFO_RESET();
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_FIFO_RESET ///
/// Function: Reset the FIFO ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_FIFO_RESET(void)
{
RFM12B_CMD(0xCA81);
RFM12B_CMD(0xCA83);
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_READ_STATUS ///
/// Function: Wait and read a byte from FIFO ///
/// ///
/////////////////////////////////////////////////////////
int16 RFM12B_READ_STATUS(void)
{
int16 data;
data = RFM12B_CMD(0x0000); // Read Data//test
return (data);
}
///////////////////////////////////////////////////////////////////////////////
void main()
{
int buffi[16] ={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
set_tris_a(0x00);
delay_ms(250);
RFM12B_INIT(1);
while(1)
{
RFM12B_SEND(buffi, 16);
output_high(LED);
delay_ms(250);
delay_ms(250);
output_low(LED);
delay_ms(250);
delay_ms(250);
}
}
|
RECEIVER CODE:
Code: | #include <16F73.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#use delay(clock=10000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=mypcconn)
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/// ///
/// #### ##### # # # ## #### ///
/// # # # ## ## ## # # # # ///
/// #### #### # ## # # # # #### ///
/// # # # # # # # # # ///
/// # # # # # # # # # ///
/// # # # # # # #### #### ///
/// ///
/// RFM12B Driver ///
/// ///
/////////////////////////////////////////////////////////
/// ///
/// Functions: ///
/// ///
/// RFM12B_INIT(int type) ///
/// RFM12B_SEND(int buffer, int size) ///
/// RFM12B_RECEIVE(int buffer, int size) ///
/// ///
/////////////////////////////////////////////////////////
/// ///
/// Updates: ///
/// ///
/// 09.01.2010 New Driver ///
/// ///
/////////////////////////////////////////////////////////
/// ///
/// Code was written by Severin Birrer ///
/// More informations at www.blucorazon.ch ///
/// ///
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/// ///
/// PIN settings ///
/// ///
/////////////////////////////////////////////////////////
#define MOSI PIN_C4 //cikis
#define MISO PIN_C5
#define nSEL PIN_C2
#define SCK PIN_C3
#define IRQ PIN_B0
#define LED PIN_A0
#define LED3 PIN_B2
#define LED4 PIN_B3
/////////////////////////////////////////////////////////
/// ///
/// Definitions ///
/// ///
/////////////////////////////////////////////////////////
#define MOSI_hi() output_high(MOSI)
#define MOSI_lo() output_low(MOSI)
#define nSEL_hi() output_high(nSEL)
#define nSEL_lo() output_low(nSEL)
#define SCK_hi() output_high(SCK)
#define SCK_lo() output_low(SCK)
#define in_MISO() input(MISO)
#define in_IRQ() input(IRQ)
#define TX 1
#define RX 0
int16 RFM12B_READ_STATUS(void);
void RFM12B_FIFO_RESET(void);
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_PORT_INIT ///
/// Function: Initalise ports to defined states ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_PORT_INIT(void)
{
nSEL_hi();
SCK_lo();
MOSI_lo();
delay_ms(100);
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_CMD ///
/// Function: Sends command and receives data ///
/// ///
/////////////////////////////////////////////////////////
int16 RFM12B_CMD(int16 cmd)
{
int i;
int16 temp=0;
SCK_lo();
nSEL_lo();
for(i=0;i<16;i++)
{
if(cmd&0x8000)
{
MOSI_hi();
}
else
{
MOSI_lo();
}
delay_us(5);
SCK_hi();
delay_us(5);
temp<<=1;
if(in_MISO())
{
temp|=0x0001;
}
SCK_lo();
cmd<<=1;
}
nSEL_hi();
return(temp);
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_WAIT_READY ///
/// Function: Wait for RFM12B to be ready (FFIT) ///
/// ///
/////////////////////////////////////////////////////////
int16 RFM12B_WAIT_READY(void)
{
unsigned int16 data;
nSEL_lo();//test
while(!in_MISO())
;//test
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_READ ///
/// Function: Wait and read a byte from FIFO ///
/// ///
/////////////////////////////////////////////////////////
int16 RFM12B_READ(void)
{
int16 data;
//RFM12B_WAIT_READY();
data = RFM12B_CMD(0xB000); // Read Data
return (data&0x00FF);
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_WRITE ///
/// Function: Write a byte ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_WRITE(int abyte)
{
RFM12B_WAIT_READY();
RFM12B_CMD(0xB800 + abyte); // Write Data
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_INIT ///
/// Function: Initalise as a sender or a receiver ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_INIT(int type)
{
RFM12B_PORT_INIT();
delay_ms(200);
if (type)
{
// Init Sender
RFM12B_CMD(0x80A8); // Configuration Command 868MHz 12,pF Enable Tx Register
}
else
{
// Init Receive
RFM12B_CMD(0x8068); // Configuration Command 868MHz 12,5pF Enable Rx FIFO buffer
}
// General Init
RFM12B_CMD(0x82D8); // Power Management Command Enable Crystal Osc.
RFM12B_CMD(0xA640); // Frequency Command Center Frequency 868.3200 MHz
RFM12B_CMD(0xC647); // Datarate Command Data Rate 4.789kbps
RFM12B_CMD(0x94A5); // Receiver Control Command VDI, Fast, 134kHz, Max, -73dBm
RFM12B_CMD(0xC2EC); // Datafilter Command Auto, Slow, Digital, 4
RFM12B_CMD(0xCA8B); // FIFO / Reset Mode Command 8, 1 bytes, Synchrone, Low, FIFO Fill Enabled
RFM12B_CMD(0xCED4); // Synchron Pattern Command Synchron byte(LSB) D4
RFM12B_CMD(0xC483); // AFC Command
RFM12B_CMD(0x9827); // TX Configuration Command
RFM12B_CMD(0xCC77); // PLL Command
RFM12B_CMD(0xE000); // Wake-Up Timer Command
RFM12B_CMD(0xC800); // Low Duty-Cycle Command
RFM12B_CMD(0xC000); // LB Det./Clock Div. Command 2.2V, 1.66MHz
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_SEND ///
/// Function: Send multiple bytes ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_SEND(int *ptr, int16 size)
{
int16 i;
RFM12B_CMD(0x8238); // Enable Sender
RFM12B_WRITE(0xAA); // Preamble
RFM12B_WRITE(0xAA); // Preamble
RFM12B_WRITE(0xAA); // Preamble
RFM12B_WRITE(0xCE); // Sync HighByte
RFM12B_WRITE(0xD4); // Sync LowByte
for (i=0;i<size;i++)
{
RFM12B_WRITE(*ptr); // DATA Byte
ptr++;
}
RFM12B_WRITE(0xAA); // Dummy Byte
RFM12B_WRITE(0xAA); // Dummy Byte
RFM12B_WRITE(0xAA); // Dummy Byte
RFM12B_WAIT_READY();
RFM12B_CMD(0x8208); // Disable Sender
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_RECEIVE ///
/// Function: Receive multiple bytes ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_RECEIVE(int *ptr, int16 size)
{
int16 i;
//RFM12B_CMD(0x82C8); // Init Receiver//test
RFM12B_CMD(0x82D8); // Init Receiver//Candy
//RFM12B_CMD(0xCA81); // Enable FIFO//test
//RFM12B_CMD(0xCA83); // Clear FIFO//test
for (i=0;i<size;i++)
{
*ptr = RFM12B_READ(); // Send Data
ptr++;
}
//RFM12B_CMD(0x8208); // Disable Receiver test of we hem wel aan laten staan
//RFM12B_CMD(0xCA83); // Clear FIFO//test
//RFM12B_FIFO_RESET();
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_FIFO_RESET ///
/// Function: Reset the FIFO ///
/// ///
/////////////////////////////////////////////////////////
void RFM12B_FIFO_RESET(void)
{
RFM12B_CMD(0xCA81);
RFM12B_CMD(0xCA83);
}
/////////////////////////////////////////////////////////
/// ///
/// RFM12B_READ_STATUS ///
/// Function: Wait and read a byte from FIFO ///
/// ///
/////////////////////////////////////////////////////////
int16 RFM12B_READ_STATUS(void)
{
int16 data;
data = RFM12B_CMD(0x0000); // Read Data//test
return (data);
}
///////////////////////////////////////////////////////////////////////////////
void main()
{
int buffi[16];
int g = 0;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
set_tris_a(0x00);
set_tris_c(get_tris_c()&(0b10111111));
delay_ms(250);
RFM12B_INIT(0);
while(1)
{
RFM12B_RECEIVE(buffi, 16); //data receive
for(g = 0; g < 16; g++) //send to pc (USART) received data
{
putc(buffi[g]);
}
}
}
|
PC RECEIVED DATA:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
255
255
255
0
0
0
0
0
0
0
0
255
255
255
255
255
255
255
255
0
0
0
0
0
255
255
255
255
255
255
255
255
255
255
255
0
192
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
255
252
0
0
0
255
255
255
255
255
255
255
255
0
0
0
0
0
0
0
0
255
240
0
0
0
0
0 |
|
|
jimbobanderson
Joined: 29 Sep 2010 Posts: 1
|
Verify SPI interface |
Posted: Wed Sep 29, 2010 9:37 pm |
|
|
Jody - I am new to RFM12b and am struggling with the communication between my MCU (TI MSP430F2013) and the RFM module. Can you please tell me how you confirmed that your SPI communication was working between the two devices?
I have been through ALL of the related websites/blogs/technical documents.
Thanks,
Jimbobanderson |
|
|
exjra
Joined: 25 Sep 2010 Posts: 3
|
|
Posted: Thu Sep 30, 2010 12:26 am |
|
|
Hello
I am trying to data transmitting for 5 days but can't succeed yet. I sent the circuit diagram and source codes of transmit and receive program. I can't find the mistake. Please help me.
http://hotfile.com/dl/72714041/f3e30b8/RFM12B.rar.html |
|
|
davidd
Joined: 30 Sep 2010 Posts: 38
|
|
Posted: Thu Sep 30, 2010 3:11 am |
|
|
exjra,
In your posted code:
RFM12B_WRITE(0xCE); // Sync HighByte
RFM12B_WRITE(0xD4); // Sync LowByte
should be:
RFM12B_WRITE(0x2D); // Sync HighByte
RFM12B_WRITE(0xD4); // Sync LowByte
0xCE is the command code to set the 2nd Sync byte. (0xCED4) |
|
|
davidd
Joined: 30 Sep 2010 Posts: 38
|
|
Posted: Thu Sep 30, 2010 3:27 am |
|
|
Jimbob,
I too have been struggling with the SPI interface and the RFM12b.
( for over a month now)
I have not seen anyone having the Hardware SPI working with this unit.
What I can tell you is the only way I have been able to get the transmitter to work is with the aid of a 10k pullup on the RFM12 SDO pin.
Verify you are sending clock pulses and the data stream.
from the strobotics site...
When nSEL signal is logic high, the SDO output is in a high impedance state.
The receiver is a different story. I too have tried several software revisions with no success.
I am abandoning the Hardware SPI for now and try the software spi implementation... |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
RFM communications problems |
Posted: Fri Mar 04, 2011 3:14 pm |
|
|
Resurrecting this thread....
Hoping that all of you from 2010 got this going and can help me out
I am using a PIC18F452 and an RFM12BS @ 915MHz freq
Two boards, one is set for TX, the other RX
I can tell that my SPI is working because I disable the CLK (pin 5 on the RFM) in the Power Management Command (bit 0 = 1)
Then I look with scope and it is dead, when previously (bit 0 =1) there is a clock frequency. Also- I monitor SPI CLK signal (pin 13 on RFM), which is present.
What state is the nIRQ pin in at power up with no code in the PIC (erased)? Mine (on both boards) is LOW. Shouldn't it be HIGH unless it's doing something?
So I will start with TX for this post. I don't know how to know that I am transmitting (transmitted), unless I just look at the nIRQ pin, which is always LOW. Should there be something on the SDO pin (pin1 on RFM)?
I am using the suggested SPI pins on the PIC, so does this mean I am using hardware SPI?
So I'll post my code in pieces. Here are my configuration parameters- thought my notes might be useful to someone else as well.
Code: |
//**************************************************
#include <18F452.h>
#fuses HS, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock = 20000000)
#include <stdlib.h>
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
//========================================
void main()
{
int i;
output_high(PIN_C0); // chip select
delay_us(500);
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64);
output_low(PIN_C0); // chip select, ready to rock and roll
//1. Configuration settting. Enable TX register, select 915 band, crystal load capacitor 8.5pF
// The crystal load capacitor is used to fine tune the onboard crystal and is best left to the default of binary ‘1000’ (which I didn't do)
spi_write(0b10000000); // cmd byte
spi_write(0b10110000); // parameter byte
delay_us(100);
output_high(PIN_C0); // chip select high
delay_us(500);
output_low(PIN_C0); // chip select
//2. Power management. Enable base band block, transmitter,synthesizer, low batt detect, disable crystal output
spi_write(0b10000010); // cmd byte
spi_write(0b00100001); // parameter byte
delay_us(100);
output_high(PIN_C0); // chip select high
delay_us(500);
output_low(PIN_C0);
//3. Frequency setting. 915-900/ 0.0075 = 2000 = 0b0111 11010000
spi_write(0b10100111); // cmd byte
spi_write(0b11010000); // parameter byte
delay_us(100);
output_high(PIN_C0);
output_low(PIN_C0);
//4. Data Rate. 9600 Baud rate to start with. TX and RX must be setup to same Baud Rate!
// R[6:0] where BR = 10Mhz / 29 / (R + 1) / (1 + bit7*7)
// For 9600 baud rate BR = 10Mhz / 29 / (R + 1) / (1 + 0*7) = 10000000 / 29 / (35 + 1) = 9578.5 ~ 9600
spi_write(0b11000110); // cmd byte
spi_write(0b00100011); // parameter byte
delay_us(100);
output_high(PIN_C0); // chip select off
output_high(Pin_A5); // LED output say hello
delay_ms(1000);
output_low(Pin_A5);
delay_ms(1000);
// all other parameters left to default
// LNA is low noise amplifier, BB is upper end of signal, -103 dBm is super sensitive
|
Last edited by Nora on Fri Mar 04, 2011 3:40 pm; edited 1 time in total |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Fri Mar 04, 2011 3:22 pm |
|
|
So here is pseudo code that the vendor RF Solutions in the UK sent to me
To transmit using FIFO you would:-
Initialize the module
Enable TX
Load a byte of data into the FIFO register
Check if nIRQ is high
If so load next byte
Check if nIRQ is high
If so load next byte and so on until packet is sent
Disable TX
And then Stephen at strobotics said this for transmission
Write preamble 2x
Turn on TX
Send out each byte in the packet // how? via spi_write()?
Write preamble 2x
Turn off TX
When the transmission of the byte completed, the nIRQ pin goes low.
The nIRQ pulse shows that the first 8 bits (the first byte, by default ) has transmitted. There are still 8 bits in the transmit register.
Code: |
output_low(PIN_C0); // chip select
spi_write(0b10101010); // preamble
spi_write(0b10101010); // preamble
spi_write(0x2D); // Synchron pattern from power on reset FIFO and Reset Mode command
spi_write(0xD4); // Synchron pattern from power on reset FIFO and Reset Mode command |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|