EmbDev.net

Forum: µC & Digital Electronics RFM02 - not receiving nIRQ interrupt signal


von DarkSavior (Guest)


Rate this post
useful
not useful
Hi, im using an ATmega32 with RF02 at 868MHz. I think i made a mistake 
in programming or something. Because i am not receiving any signal from 
RFM nIRQ pin. Pin nIRQ should oscillate at a frequency right? On my 
scoop i can see it doesnt do anything at all. Help is really 
appreciated. This is my code:
1
#include <avr/io.h>
2
#include <stdlib.h>
3
#include <avr/interrupt.h>
4
#define F_CPU 10000000UL
5
#include <util/delay.h>
6
7
8
#define RF_PORT  PORTB
9
#define RF_DDR  DDRB
10
#define RF_PIN  PINB
11
12
#define DDR_IN      0
13
#define DDR_OUT    1
14
15
#define PORT_SEL  PORTB
16
#define PIN_SEL    PINB
17
#define DDR_SEL    DDRB
18
19
#define  PORT_SDI  PORTB
20
#define PIN_SDI    PINB
21
#define DDR_SDI    DDRB
22
23
#define PORT_SCK  PORTB
24
#define PIN_SCK    PINB
25
#define DDR_SCK    DDRB
26
27
#define PORT_NIRQ  PORTB
28
#define PIN_NIRQ  PINB
29
#define DDR_NIRQ  DDRB
30
31
#define SCK    7  // SCK,  -> RF02
32
#define NIRQ    6  // nIRQ, -> RF02
33
#define SDI    5  // SDI,  -> RF02
34
#define SEL    4  // nSEL, -> RF02
35
#define DATA   3  // FSK,  -> RF02
36
37
38
#define SEL_OUTPUT()   DDR_SEL  |= (1<<SEL)
39
#define HI_SEL()    PORT_SEL |= (1<<SEL)
40
#define LOW_SEL()    PORT_SEL &=~(1<<SEL)
41
42
#define SDI_OUTPUT()  DDR_SDI  |= (1<<SDI)
43
#define HI_SDI()    PORT_SDI |= (1<<SDI)
44
#define LOW_SDI()    PORT_SDI &=~(1<<SDI)
45
46
#define NIRQ_INPUT()  DDR_NIRQ  &=~(1<<NIRQ)
47
#define NIRQ_HI()    PIN_NIRQ&(1<<NIRQ)
48
49
#define SCK_OUTPUT()  DDR_SCK  |=(1<<SCK)
50
#define HI_SCK()    PORT_SCK |=(1<<SCK)
51
#define LOW_SCK()    PORT_SCK &=~(1<<SCK)
52
53
54
unsigned int RFXX_WRT_CMD( unsigned int aCmd) {  // to send commands
55
56
  unsigned char i;
57
  unsigned int temp;
58
59
  LOW_SCK();  // reset bit SCK
60
  LOW_SEL();    // reset bit SEL
61
  for(i=0;i<16;i++)
62
    {
63
    temp<<=1;  // temp=temp<<1;
64
    if(NIRQ_HI()) {  
65
    temp|=0x0001; // temp is a 16-bit integer
66
    }
67
  LOW_SCK();  // reset bit SCK
68
    if(aCmd&0x8000) {  // if((aCmd&0x8000)==0x8000)
69
    HI_SDI();  // set bit SDI
70
    }
71
    else {
72
      LOW_SDI();// reset bit SDI
73
    }
74
      HI_SCK();  // set bit SCK to shift data from SDI pin to RFM
75
      aCmd<<=1; // aCmd=aCmd<<1
76
  }
77
  LOW_SCK();  // reset bit SCK
78
  HI_SEL();    // set bit SEL
79
  return(temp);
80
}
81
82
83
void RF02B_SEND(unsigned char aByte) {  // send a byte
84
85
  unsigned char i;
86
87
  for(i=0;i<8;i++)
88
    {
89
  while(NIRQ_HI());  // polling nIRQ
90
  while(!(NIRQ_HI()));
91
  if(aByte&0x80)
92
    {
93
      PORTB|=(1<<DATA);  // set bit(FSK): request data input
94
    }
95
    else {
96
    PORTB&=~(1<<DATA);  // reset bit(FSK): request data input
97
      }
98
    aByte<<=1;  // aByte=aByte<<1
99
  }
100
}
101
102
103
void RFXX_PORT_INIT(void) { // initialise all neccesary ports
104
  HI_SEL();    // set bit SEL
105
  HI_SDI();    // set bit SDI
106
  LOW_SCK();  // reset bit SCK
107
  SEL_OUTPUT();  // set port SEL as output
108
  SDI_OUTPUT(); // set port SDI as output
109
  NIRQ_INPUT();  // set port SDO as input
110
  SCK_OUTPUT(); // set port SCK as output
111
}
112
113
114
void Send (unsigned int byte) {
115
116
  unsigned int i, j, ChkSum;
117
118
  ChkSum=0;
119
  RF02B_SEND(0xAA); // PREAMBLE
120
  RF02B_SEND(0xAA); // PREAMBLE
121
  RF02B_SEND(0xAA); // PREAMBLE
122
  RF02B_SEND(0x54); // Sync byte
123
  RF02B_SEND(byte);  // Data0
124
  ChkSum+=byte;
125
  RF02B_SEND(byte);  // Data1
126
  ChkSum+=byte;
127
  RF02B_SEND(byte);  // Data2
128
  ChkSum+=byte;
129
  RF02B_SEND(byte);  // Data3
130
  ChkSum+=byte;
131
  RF02B_SEND(byte);  // Data4
132
  ChkSum+=byte;
133
  RF02B_SEND(byte);  // Data5
134
  ChkSum+=byte;
135
  RF02B_SEND(byte);  // Data6
136
  ChkSum+=byte;
137
  RF02B_SEND(byte);  // Data7
138
  ChkSum+=byte;
139
  RF02B_SEND(ChkSum);// Data8
140
  RF02B_SEND(0xAA);  // dummy byte
141
142
  RFXX_WRT_CMD(0xC401);  // (8) TX off
143
144
  for(i=0;i<5000;i++)
145
  for(j=0;j<123;j++);
146
}
147
148
void main(void) {
149
150
  RFXX_PORT_INIT();  // initialise all neccesary ports
151
152
  RFXX_WRT_CMD(0xCC00); // read internal status register content
153
154
  RFXX_WRT_CMD(0x9731); // (2) 
155
            // b1=1,d1=1,d0=1,x1=1,x0=1,m0=1
156
            // CLK freq 10MHz
157
            // Band 868MHz 
158
            // 10pF
159
            // 60kHz deviation
160
161
  RFXX_WRT_CMD(0xC031); // (3) 
162
               // ex=1,es=1,dc=1
163
              // enable crystal oscillator
164
            // enable synthesizer
165
            // disable CLK pin
166
            // POWER AMPLIFY aanzetten?
167
168
  RFXX_WRT_CMD(0xA640); // (4) 868MHz ( 860MHz + 6MHz )
169
170
  RFXX_WRT_CMD(0xC823); // (5) 4.8kbps 0xC823 << nog delen door 2 (0xD040)
171
              // r6=1,r2=1,r1=1,r0=1
172
173
  RFXX_WRT_CMD(0xB000); // (6) no relative power output
174
175
  RFXX_WRT_CMD(0xC220); // (7) ebs=1
176
               // enable TX sync
177
    
178
  RFXX_WRT_CMD(0xC464); // (8) TX off after 10us (0xC464)
179
180
  PORTB|=(1<<DATA);    // set bit FSK
181
  DDRB|=(1<DATA);    // set port FSK as output
182
183
184
while(1) {
185
  for( int i=0;i<=50;i++)
186
  Send(0x0F);
187
  for( int i=0;i<=50;i++)
188
  Send(0xF0);
189
  }
190
}

von DarkSavior (Guest)


Rate this post
useful
not useful
Nvm, fixed it. Didnt set amplifier enable bit. Now i got problems with 
receiving. :P

von irek (Guest)


Rate this post
useful
not useful
Hey, did you fix it (receiving)?

von matzetronics (Guest)


Rate this post
useful
not useful
DarkSavior wrote:
> Now i got problems with
> receiving. :P

Always keep in mind to reset the receiver (RFM01) before a new packet is 
expected. This is done by flushing the FIFO and disabling and then 
re-enabling the receiver. Here's a small excerpt from one of my DMX 
Receivers, unfortunately in assembler. But i hope you get the idea:
1
main:  ldi  ticker,0xff  ; periodical calls
2
  clr  chksum  
3
  ldi  YH,High(DMXSTART)
4
  ldi  YL,low(DMXSTART)
5
  rcall  w30us
6
; reset the FIFO 
7
  ldi  spihi,0xce
8
  ldi  spilo,0x84
9
  rcall  spiout
10
  nop
11
; restart the FIFO
12
  ldi  spihi,0xce
13
  ldi  spilo,0x87
14
  rcall  spiout
15
  nop
16
main1:
17
  dec  ticker        ; timeouter
18
  rcall  rfmread      ; try to read something from the receiver
19
  sbrs  flags, validbit  ; if theres something valid throw it on the console
20
  rjmp  main1
21
; received something
22
  mov  spihi,temp    ; status 
23
  rcall  usbout
24
  cpi  YL,low(DMXEND)
25
  brcs  main1
26
  sbi  LEDPort,OVLED  ; LED flashes on full buffer 
27
  rcall  w100ms
28
  cbi  LEDPort,OVLED
29
  rjmp  main
30
; read RFM01 status byte into spihi, spilo and the next data byte from the fifo
31
; the read command starts and continues with a 0 
32
; data will be stored at Y
33
rfmread:       ; read command
34
  cbi  RFMPort,RFMOut  ; set to lo for the rest of this run
35
  nop
36
  cbi  RFMPort,RFMCs  ; select rx
37
  ldi  counter,16  ; 16, read in the statusword
38
  nop
39
  sbi  RFMPort,RFMClk  ; strobe in the next bit
40
  nop
41
  clc
42
  sbis  RFMPin,RFMIn  ; read
43
  rjmp  rfmr2    ; no fifo there, skip this receiption
44
  sec
45
  rol  spilo    ; into 16 bit rollers
46
  rol  spihi
47
  dec  counter
48
rfmr1:  nop
49
  sbi  RFMPort,RFMClk  ; strobe in the next bit
50
  nop
51
  clc
52
  sbic  RFMPin,RFMIn  ; read
53
  sec
54
  rol  spilo    ; into 16 bit rollers
55
  rol  spihi
56
  cbi  RFMPort,RFMClk
57
  dec  counter
58
  brne  rfmr1
59
; now get the databyte
60
; read in 8 bits
61
  ldi  counter,8
62
rfmr6:  nop
63
  nop
64
  nop
65
  sbi  RFMPort,RFMClk  ; strobe pulse
66
  clc
67
  nop
68
  nop
69
  sbic  RFMPin, RFMIn  ; is it high ?
70
  sec
71
  rol  temp    ; from carry into lowest
72
rfmr5:  nop
73
  nop
74
  cbi  RFMPort,RFMClk  ; clr the clock
75
  dec  counter
76
  brne  rfmr6
77
  nop  
78
  sbi  RFMPort,RFMCs  ; deselect RFM
79
  st  Y+,temp    ; store in RAM
80
  add  chksum,temp  ; add to the checksum
81
  sbr  flags,valid    ; we have a valid reception
82
  ret
83
rfmr2:  cbr  flags,valid  ; no valid reception detected
84
  cbi  RFMPort, RFMClk    ; unclock
85
  sbi  RFMPort,RFMCs  ; deselect RFM
86
  ret
This assumes a correctly setup prior to the main loop. I'm using 868 Mhz 
modules, YMMD.

von Martin Michael (Guest)


Rate this post
useful
not useful
DarkSavior THX
6 year's old but it helped me cool ahh I mean, LOL

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.