Beruflich Dokumente
Kultur Dokumente
19, Innovation First Road • Science Park • Hsin-Chu • Taiwan 300 • R.O.C.
http://www.sunplusmcu.com http://mcu.sunplus.com
RF Communication
Important Notice
SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information
provided by SUNPLUS TECHNOLOGY CO. is believed to be accurate and reliable. However, SUNPLUS
TECHNOLOGY CO. makes no warranty for any errors which may appear in this document. Contact SUNPLUS
TECHNOLOGY CO. to obtain the latest version of device specifications before placing your order. No
responsibility is assumed by SUNPLUS TECHNOLOGY CO. for any infringement of patent or other rights of third
parties which may result from its use. In addition, SUNPLUS products are not authorized for use as critical
components in life support systems or aviation systems, where a malfunction or failure of the product may
reasonably be expected to result in significant injury to the user, without the express written approval of Sunplus.
Revision History
Translated Page
Revision Date Remark
By Number(s)
Table of Content
PAGE
2 RF System Principle........................................................................................................................... 7
2.1 Function......................................................................................................................................... 7
2.2 Principle......................................................................................................................................... 7
2.3 Communication Protocol ............................................................................................................... 8
3 Software Description........................................................................................................................ 10
4.1 F_Main......................................................................................................................................... 19
4.2 Initialization in Main ..................................................................................................................... 20
4.3 F_Key .......................................................................................................................................... 20
4.4 F_Light......................................................................................................................................... 21
4.5 F_Send_Init ................................................................................................................................. 21
4.6 F_Lock ......................................................................................................................................... 22
4.7 F_Send_Data_Head.................................................................................................................... 23
4.8 F_Send_Data_Start ..................................................................................................................... 24
4.9 Interrupt Service Routine............................................................................................................. 25
4.10 F_Send ...................................................................................................................................... 26
4.11 Byte Transmission ..................................................................................................................... 27
4.12 F_Receive_Init........................................................................................................................... 28
4.13 F_Receive ................................................................................................................................. 29
4.14 F_DataCorrect ........................................................................................................................... 30
This document is intended to guide you how to communicate with RF (Radio Frequency)
device via GPIO on SUNPLUS SPMC65x series. Here, we take SPMC65P2404A*28P as
an example for demonstration purpose.
4 RF Module
1
SPMC65P2404A Key Scan
*28p
7
LED Showing
2 16MHz
2 RF System Principle
2.1 Function
2.2 Principle
When no key is pressed, the system runs in the receiving mode, and it intends to receive
signals with recognizable communication format. Once a matched signal is received, it
will be shown via the LED. When a key is pressed, the system will switch to the
transmission mode immediately and then transmit the key value (0~F) with the defined
format.
PortA is assigned to connect a key and a 7-segment LED. PB2~PB5 are connected to
the lines of T/R, PAEN, Data in, and Data out respectively in RF module. The logic high
voltage to the RF module is 3V, so a voltage conversion is required between RF module
and SPMC652 when interfacing with IO ports. PB2, PB3 and PB4 are configured as the
output control lines, therefore, they are respectively connected to the RF module through a
2K and a 3K resistor to divide the voltage. PB5 is configured as the input line, which is
connected to Data Out line in RF module via two transistors for voltage conversion.
Since CHS0, CHS1, CHS2 are tied to VSS directly, according to initial setting, the channel
0 is used to transmit/receive data in RF module.
The 7-segment LED is initialized to show ‘0’ and it will increase 1 as soon as a key-press
occurs. Momentarily, the display value is transmitted to a receiving system.
ANT1
ANTENNA
SPMC65P2404A*28P XI XO
1 28 VDD SPRF2716
a dp 2 PA7 VDD 27 VSS 20p 16MHz 20p
VSS
ANT
g 3 PA6 VSS 26 XI DataIn VSS
f g b f PA5 XI 25 Data In
4 XO
e 5 PA4 XO 24 RESET VSS CHS0
e c PA3 RESET 23
d . d 6 CHS1 L1
c 7 PA2 PD0 22 PEAN CHS2 3.3uh VDD
b PA1 PD1 21 PAEN RF1 +5V
com
8 VSS
a 9 PA0 PD2 20 T/R PD
10 PB7 PC0 19 DataOut T/R VSS
PB5 11 PB6 PC1 18 VCC Data Out
PB4 12 PB5 PC2 17 VCC
PB3 13 PB4 PC3 16 VSS SPEAKER
PB2 14 PB3 PB0 15 VSS
PB2 PB1
+5V
+5V
PB2 PB3 PB4
4.7K
5.1K RESET
2K 2K 2K
5.1K PB5
510 T/R PEAN DataIn
104
510 8050
DataOut 3K 3K 3K
8050
The communication protocol is designed for discrete multiple devices communication, that
is, it takes master and slave in the system to be equal. In general, if no key is pressed,
the hardware system is under the receiving mode. When a key-press occurs, a frame of
data can be transmitted. The data format is shown as Figure 2-2.
80ms 3.76ms
1 0 1 0 1 0 1 0 0 0 0 0 0 0 0
550us 3.29+0.47ms
A full frame of data includes: preamble, start bit, ID number, and data1, 2, 3, and 4.
In this application, the ID number is $AA; data1 is the key value; data2, the
base-minus-one’s complement of data1; data3, the base-minus-one’s complement of
data2; data4, the base-minus-one’s complement of data3. That is, data1 and data3
present the key value; data2 and data4 are the base-minus-one’s complement of the key
value. Encoding by this format ensures that any two data errors can be checked and the
true value is still remained. Figure 2-3 shows the coding format.
470x3us 470us
For this coding format, the logic ‘1’ and the logic ‘0’ are read by periodic calculation. By
this means, the code can obtain a higher capability of anti-jamming, but it adds the
complexity of data decoding. In the program, the period calculation is performed by the
capture function.
3 Software Description
3.2 Subroutines
V_Reset
Content Memo
Input None
Output None
The initial address that PC points to after
Description
Power-On-Reset
Caller main.asm
F_Main
Content Memo
Input None
Output None
Delay time for 4ms, and then perform the key scan, key
Description processing, key value display and data
transmission/receiving.
Caller Main.asm
V_INT
Content Memo
Input None
Output GB_T1_OverFlow
Content Memo
F_RF_Init
Content Memo
Input None
Output None
Description Clear variables; Configure IO ports and 4ms interrupt.
Caller RF.asm
F_Key
Content Memo
Input None
Output GB_KeyDownFlag, IB_ShowBuf
Description Key scan
Caller RF.asm
F_Light
Content Memo
F_Send_Init
Content Memo
Input None
Output GB_Send_Flag
Description Initialization for the data transmission
Caller RF.asm
F_Lock
Content Memo
Input GB_Send_Flag
Output GB_Send_Flag
Description Lock-up time before transmission About 80ms
Caller RF.asm
F_Send_Data_Head
Content Memo
Input GB_Send_Flag
Output GB_Send_Flag
Description Transmit the preamble, start timer3 for 470us timing
Caller RF.asm
F_Send_Data_Start
Content Memo
Input GB_Send_Flag
Output GB_Send_Flag
Description Transmit start bit
Caller RF.asm
F_Send_Data
Content Memo
F_Send
Content Memo
Content Memo
F_Receive_Init
Content Memo
F_Receive
Content Memo
F_DataCorrect
Content Memo
Input G_RF_data
Output G_RF_data
Description Check and correct the data in 4-byte variable G_RF_data.
Caller RF.asm
3.3 Variables
GB_KeyDownFlag
Content Memo
Content Memo
Default 0
Symbol None
Value 0~1
IB_KeyupFlag
Content Memo
Key up flag:
Description 0 – the key is released
1 – the key is not released after being pressed
Size 1 byte
Default 0
Symbol None
Value 0~1
IB_CmpTimers
Content Memo
IB_ShowBuf
Content Memo
Description Buffer for the to-be-showed data, the lower four bits are
significant.
Size 1 byte
Default 0
Symbol None
Value $00~$FF
GB_Lock_Num
Content Memo
GB_Sending_Flag
Content Memo
GB_Send_Flag
Content Memo
Content Memo
IB_Bit_number
Content Memo
GB_DataBuf
Content Memo
IB_470us_Count
Content Memo
Set a 470us timer (start bit, ID number, the time base for
Description
transmission data1-data4)
Size 1 byte
Content Memo
Default 0
Symbol None
Value 0~7
GB_Receive_Flag
Content Memo
Data receiving
Bit4-1: Receiving is over
0: Receiving is not over
Bit3-1: Enable to receive ID number and data1-data4
0: Disable to receive ID number and data1-data4
Bit4~bit0 are
Description Bit2-1: Enable to receive start bit
significant
0: Disable to receive start bit
Bit1-1: Enable to receive initialization
0: Disable to receive initialization
Bit0-1: Enable receiving
0: Disable receiving
Size 1 byte
Default 0
Symbol None
Value $0~$1f
G_RF_Time
Content Memo
G_RF_data
Content Memo
Content Memo
G_RF_Number
Content Memo
4 Flow Chart
4.1 F_Main
Start
Initialization (F_RF_Init)
N
Is 4ms expired?
Lock delay(F_Lock)
N
Key-press?
F_RF_Init
IO port initialization
Variables initialization
Return
4.3 F_Key
(F_Key)
N Y
Key up flag = 0?
N N
PA7=1? PA7=0?
Y Y
Equal time increase 1 Equal time increase 1
(IB_CmpTimers+1) (IB_CmpTimers+1)
N N
IB_CmpTimers=6? IB_CmpTimers=6?
Y Y
key value increase 1,set
Key is released, set
GB_KeyDownFlag=1and
IB_KeyupFlag=0
IB_KeyupFlag=1
Return
4.4 F_Light
F_Light
N
Received new data?
Return
4.5 F_Send_Init
F_Send_Init
Return
4.6 F_Lock
F_Lock
Enable N
transmitting?
Y
Enable lock-up N
time?
Y
N
Cycle time=10?
Return
4.7 F_Send_Data_Head
F_Send_Data_Head
N
Enable transmitting?
N
Enable transmit preamble?
Transmit preamble
Return
4.8 F_Send_Data_Start
F_Send_Data_Start
N
Transmit start bit?
Y
470us counter=7?
Return
V_INT
N
Capture int?
Receive data(F_Receive)
clear the capture int flag
N
Timer3 int?
N
Transmit?
Transmit data
(F_Send_Data)
Return
4.10 F_Send
F_Send_Data
Y
Transmit ID number?
Y Transmit ID number,then
Transmit data1? transmit data1(F_Send)
Transmit data1,then Y
Transmit data2?
transmit data2(F_Send)
N
Y Transmit data2,then
Transmit data3? transmit data3(F_Send)
N
Transmit data3,then Transmit data4?
transmit data4(F_Send)
Y
Is transmit Y
data over?
N
Set GB_Sending_Flag to
stop transmitting
Return
F_Send
N
Bit = 0 ?
Y
Transmit ‘0’ Transmit ‘1’
Set GB_Sending_Flag
F_Send
4.12 F_Receive_Init
F_Receive_Init
Y
Transmit mode?
N
Y
Receive mode?
Disable capture int
N
N
Receive initializatiom?
Return
4.13 F_Receive
F_Receive
Y
Transmit mode?
N
N
Receive mode?
Y
Clear receive flag
Disable capture int Calculate captured value
Y
Receive start bit?
N
Receive ID number? N
Received start bit?
Y
Y
Judge the receiving data is ‘0’or
‘1’by captured value Disable receive start bit
Enable receive ID number
Y
Received bits =8?
N Y
Return
4.14 F_DataCorrect
F_DataCorrect
Y
data1=data3?
Complement data2, Y
data2=data4?
load it to data1
N
Y
data1+data2=$FF?
Y
data1+data4=$FF?
Y
Load data3 to data1 data3+data2=$FF?
N
N
data3+data4=$FF?
Return
5 SPRF2716B Introduction
(1) A single chip transceiver RF IC, offers a 27MHz FM/FSK half-duplex transceiver
(7) When communicating in 27MHz, the match between the antenna type and the distance
is shown below:
Data In
PAEN
CHS0
CHS1
CHS2
GND
RV
PD
Open is forbidden
CHS1 I CHS2. (Ditto) 3.0V or VSS
CHS0 I CHS2. (Ditto) 3.0V or VSS
Data In I Modulation input. Input resistance > 30k, Digital input
SPEAKER O 16Ohm speaker input 16Ohm
ANT - Antenna 50Ohm load
ANTENNA ANTENNA
3.3uH 3.3uH
ANT
ANT
GND
GND
GND GND
Data In Data In
CHS0 CHS0
Microcontroller CHS1 CHS1 Microcontroller
CHS2 CHS2
PAEN PAEN
PD
T/R
A B PD
T/R
Data Out Data Out
VDD VDD
SPEAKER SPEAKER
GND GND 3V
3V
27MHz RF Module 27MHz RF Module
1. Control timing
T/R
PAEN
Data in
PLL Lock-up
time
B
T/R
PAEN
Data out
Random noise
The data transmission and receiving should be performed in one channel. Connect
PAEN and T/R to make the amplifier work immediately when the transmission or receiving
is enabled. PLL lock-up time depends on bandwidth of loop filter.
2. Transmission protocol
For higher dependability, the RF data are always transmitted as frame or packet.
Preamble is commonly coded as ‘10101010’ for the purpose of leading the data slicer
in the receiving end to a stable state.
CRC: Error check. Simply, DataContent can be checked by the Check Sum.
Do not code the content with a serial ‘1’ or a serial ‘0’ to avoid leading the data slicer to
an unstable state and disturbing data decoding.
You can design any format to encode the data in SPRF2716, the following two formats are
recommended:
‘Start Bit’ is a start sign for a group of data. The format of logic ‘0’ and ‘1’ are shown as
above. Manchester Coding format is shown below.
Preamble Start bit ID NO. Data1 Data2 Data3 Data4 Preamble Start bit
0 1 0 0 0 1 1 0 1
Transmit a preamble to enable the T/R control and to start the data frame. The ID
number is the user-defined address for its receiving device which is usually adopted in the
multi-device broadcast communication. The slave will detect each ID number
broadcasted by master. If the ID number that slave receives is matched, the slave will set
up connection with the master at once, or else it will give up the message and receive the
next one. Data2 may be the complementary of data1; data4 may be the complementary
of data3 or the check sum of data1 and data2.
It is critical to check the start bit to filter the disturbance of random noise when receiving
data via wireless.
Note: Because of latency effect, it is necessary to reserve some time for T/R switching.
Bit 1 Bit 0
200us 200us
600us 200us
On the merit of this coding format that ‘1’ and ‘0’ are differentiated by the length of period,
the data is provided with a higher anti-jamming capability, but accordingly the complexity of
decoding increases. The preamble and the start bit follow the Manchester Coding format.
11 metres wavelength. To achieve the best efficiency of radiating and receiving, the
wavelength should be 1/4 wavelength according to the theoretic value for the antenna
size, that is, 2.7 metres. It is impossible, however, to fix such an unwieldy antenna in
a product, even if the shorter the antenna is, the worse the connection quality will be.
In the metal circumstances the electrical signal will fade, e.g. Putting a 27MHz wireless
mouse on a metal table will reduce its communication range to 50cm.
The interference coming from other electrical appliances up to 27MHz frequency will
reduce the receiving sensitivity and shorten the connection distance. Techniques
recommended below enable you to avoid interference to some degree.
Use high quality IF-filter to minimize the interference generated by a neighbour channel
GND
+ +
J1 47u 47u
VCC
2
1 Data_Out 10.24M
2 T/R R2 15K X1
3 PD R3 47K
4 PAEN C3 C4 C5 C6
5 CHS2 L1 C8
J2
6 CHS1 R5 10K VDD EXT R4 R1 220n 104 22p 30p
7 CHS0 1 0
8 Data_In C9 102 C10 2 15K
9 3 MIC 1 uH 15p 22n C7
10 RV 104 CON3
11 VCC
C11 47u
CON11 PD T/R MIC1
+ PAEN RV
CHS2 Data_Out MICROPHONE
R7 10 CHS1
48
47
46
45
44
43
42
41
40
39
38
37
CHS0 U2
1
VSS
XO
CPPO
PAEN
OSC1
OSC2
PD
XI
RV
VCT
VDD
CHS2
T/R
2
C14 L2 C16 3 CHS1 R6 3K
1
2
1u 4 CHS0 36
104 5 MICO NC 35
6 MODI NC 34 C12 C13 104
J3 L3 470n C18 10uH 7 VDDH DO 33 104
8 VCC MICEN 32
1 9 PA MICI 31 C17
2 82p C20 10 VEE VREF 30
C21 C22 11 LNAI SPRF2716B CF 29 C19
CON2 5p 12 NC DEMO 28 102
NC OPI
3
200p 100p 27
AVDD3
AVDD2
AVSS3
OPO
SPKO
26 1u R8
RSSI
MXO
LMTI
IF1O
AVSS2
IF1I
25 C23 R9 10K C24
NC
NC
CP
QUAD 2 5K
J4
13
14
15
16
17
18
19
20
21
22
23
24
Antenna Port 470p 1u
1 VCC
1
R10 10
2
L4
R12
F1 455K F2 455K C27 C28 47K TOKO 8128
1 3 1 3 +
1 3 1 3
2
104
47u
2
CON2
ANTENNA
3.3uH
ANT
GND
GND
Data In 3V DC
CHS0
CHS1
CHS2
PAEN
PD
T/R
Data Out Push to Talk
VDD
SPEAKER
GND
Loudspaeaker
27MHz RF Module
Please press the transmission key before you speak; once you release the key, the system
will enter the receiving mode. It is recommended to drive a 16Ohm speaker.