2 // Author: Bc. Jiri Kubias <Jiri.kubias@gmail.com>, (C) 2008
4 // Copyright: (c) DCE FEE CTU - Department of Control Engeneering
5 // License: GNU GPL v.2
10 * \mainpage Zigbee radio MC13192 or MC13202
11 * @author Bc. Jiri Kubias , DCE FEL CTU 2008
12 * \section Introduction
13 * This code provides same sample how to use MC13xx2 radio in packet mode.
14 * The basic libraries for testing are writen mostly platform independent.
15 * See the function description. In some function is noted that use some platform
16 * depended parts whis should be modified. Originaly this code was developed for
17 * MC13192 radio, but now we use MC13202 radio which is almost fully compatible.
19 * MC1319x.c - is mostly platform independent, see notes inside. This library
20 * contains basic function which contains funcion for send, recieve, set clko,
21 * read ID, set frequency and do energy detect.
23 * MC1319xdef.h - contains register definions and bit masks for MC13xxx radio
25 * spi.h - platform independent. Contains function prototypes and definition
26 * SPI_SPEED for setting SPI speed in Hz.
28 * spi_LPC.c - platform dependent. Contains inicializing function for SPI channel,
29 * all other used pins and installs ISR.
31 * uart_minibee.h - platform independent. Function prototypes for uart communication
33 * uart_minibee.c - particulary platform dependent. Some part of this code must be ported
36 * Porting to another platform:
37 * For another platform you must implement your own SPI function,
38 * set pins and install ISR. It must support the prototypes functions
39 * which is defined in spi.h. You also must implement your
40 * function for uart communication (see uart_minibee.c).
42 * The last tested platform is LpcEurobot which is ARM7 micproporcesor LPC2119.
43 * It also use eurobot ebb library for UART communication for ARM7. Older platform
44 * was AVR which is no longer supported due to no platform for testing. In this code
45 * is added spi_avr.c which is not fully ported.
48 * 1) IRQ edge sensive - in this code are parts where is ISR at IRQ pins is disabled.
49 * If this code didnt fully acknowledge IRQ in radio the renewed ISR will not recognise
50 * IRQ request. If this occurs the main MCU must be reseted.
52 * a) comment line 73 in spi_LPC.c - in commnent is ***
53 * b) move all code to ISR and never disable ISR on IRQ pin - recomended
58 * @author Bc. Jiri Kubias , DCE FEL CTU 2008
60 * @brief Demo application demonstrating use of MC1319x library.
61 * This file provides simply how-to use MC1319x library.
62 * From main function is called init function of SPI and UART.
63 * After sucessfull inicialize it tries read chip ID and recognize
64 * connected radio. Whan everythig is sucessfull it runs command
65 * processor which allows you to test radio functions.
74 #include <lpc21xx.h> /* LPC21xx definitions */
79 #include "uart_minibee.h"
83 struct Message MsgSnd
; ///< Send buffer
84 struct Message MsgRcv
; ///< Recieve buffer
91 * @param *msg pointer to Message sructure
93 void sendData(struct Message
*msg
)
101 * Reads data from Radio buffer
103 void recieveData(void)
108 MC_RecievePaket(&MsgRcv
);
111 * At first it inicializes serial and SPI line + other pins + ISR (RXTXEN, IRQ....)
112 * then it inicialzes Radio and reads radio ID. Whan everything is sucessfull
113 * runs the serial command processor.
119 volatile uint32_t test
=0;
124 // init SPI line, ISR and oter pins
125 send_rs_str("SPI init.\n");
128 // reset and inicialize radio
129 send_rs_str("\nMC reset\n");
132 send_rs_str("FAIL\n");
136 // Read and test radio ID
137 send_rs_str("Who am i:\n");
139 if((test
== 0x5000) | (test
== 0x5400))
141 send_rs_str("MC13192 Detected\n");
143 else if ((test
== 0x6000) | (test
== 0x6400))
144 send_rs_str("MC13202 Detected\n");
147 send_rs_str("ID FAIL: ");
153 MC_SetPa(0xFF); // nastavi vysilaci vykon
154 MC_SetChannel(ZB_CH802_21
); // nastavi kanal
161 send_rs_str("Entering command processor loop\n");
165 send_rs_str("-----------------------------------\n");
166 send_rs_str("1 Send message\n");
167 send_rs_str("2 Recieve message\n");
168 send_rs_str("3 Get IRQ pin\n");
169 send_rs_str("4 enable ISR\n");
170 send_rs_str("5 Read IRQ\n");
171 send_rs_str("6 Set channel\n");
172 send_rs_str("7 Energy detect\n");
173 send_rs_str("8 Set clock output\n");
174 send_rs_str("-----------------------------------\n");
176 command
= uart_get_char();
177 uart_send_char(command
);
178 uart_send_char('\n');
182 send_rs_str("Sending message\n");
184 MsgSnd
.data
[0] = 0x88;
185 MsgSnd
.data
[1] = 0x41;
186 MsgSnd
.data
[2] = 0x22;
187 MsgSnd
.data
[3] = 0x88;
188 MsgSnd
.data
[4] = 0xFF;
189 MsgSnd
.data
[5] = 0x00;
190 MsgSnd
.data
[6] = 0x01;
191 MsgSnd
.data
[7] = 0xFF;
192 MsgSnd
.data
[8] = 0x06;
193 MsgSnd
.data
[9] = 0x00;
194 MsgSnd
.data
[10] = 0x01;
195 MsgSnd
.data
[11] = 0x00;
196 MsgSnd
.data
[12] = 0x89;
197 MsgSnd
.data
[13] = 0x00;
203 send_rs_str("IRQ register is: ");
204 myvar
= spi_Read(IRQ_STATUS
); // acknowledge power-on IRQ
210 send_rs_str("IRQ pin is: ");
211 if((IO0PIN
& (1<<IRQ
)) == (1<<IRQ
))
212 send_rs_str("true\n");
214 send_rs_str("false\n");
217 case '4': send_rs_str("Enable ISR: OK\n");
221 case '2': send_rs_str("Recieving:\n");
226 if((MsgRcv
.done
== 1))
228 send_rs_str("Recieved Data:\n");
229 send_rs_str("Msg.len: ");
230 send_rs_int(MsgRcv
.len
);
231 send_rs_str("\nMsg.data: \n");
232 for (j
= 0; j
< MsgRcv
.len
; j
++)
234 send_rs_int(MsgRcv
.data
[j
]);
247 send_rs_str("Timed out\n");
249 send_rs_str("Reading done!\n");
253 send_rs_str("Select channel (11~26)\n");
257 if(!((j
== '1')|(j
=='2'))){
258 send_rs_str("Bad value\n");
262 myvar
= (j
- '0')* 10;
266 if(!((j
>= '0')&(j
<='9'))){
267 send_rs_str("Bad value\n");
272 MC_SetChannel(myvar
);
276 send_rs_str("Energy detect: ");
277 send_rs_int(MC_ED());
281 send_rs_str("Enable CLKO? (y/n) ");
286 send_rs_str("CLKO - Switching OFF");
287 MC_SetClko(CLKO_CTL_CLKO_16Km
, CLKO_CTL_CLKO_OFFm
);
292 send_rs_str("\nInvalid command\n");
297 send_rs_str("Select clock\n");
298 send_rs_str("1 16.393kHz\n");
299 send_rs_str("2 32.786kHz\n");
300 send_rs_str("3 62.5kHz\n");
301 send_rs_str("4 1Mhz\n");
302 send_rs_str("5 2Mhz\n");
303 send_rs_str("6 4Mhz\n");
304 send_rs_str("7 8Mhz\n");
305 send_rs_str("8 16Mhz\n");
310 if(('0' < j
) & (j
< '9'))
314 MC_SetClko(CLKO_CTL_CLKO_16Km
, CLKO_CTL_CLKO_ONm
);
317 MC_SetClko(CLKO_CTL_CLKO_32Km
, CLKO_CTL_CLKO_ONm
);
320 MC_SetClko(CLKO_CTL_CLKO_62Km
, CLKO_CTL_CLKO_ONm
);
323 MC_SetClko(CLKO_CTL_CLKO_1Mm
, CLKO_CTL_CLKO_ONm
);
326 MC_SetClko(CLKO_CTL_CLKO_2Mm
, CLKO_CTL_CLKO_ONm
);
329 MC_SetClko(CLKO_CTL_CLKO_4Mm
, CLKO_CTL_CLKO_ONm
);
332 MC_SetClko(CLKO_CTL_CLKO_8Mm
, CLKO_CTL_CLKO_ONm
);
335 MC_SetClko(CLKO_CTL_CLKO_16Mm
, CLKO_CTL_CLKO_ONm
);
344 send_rs_str("Invalid command\n");
350 send_rs_str("Bad command!\n");
357 // test if sessage is sent
358 if ((MsgSnd
.done
== 1))
360 send_rs_str("Message sent!!!!!!!!!!!!!!\n");
362 // add same handle code her
365 // test if some packet is recieved
366 if ((MsgRcv
.done
== 1))
368 // add same handle code here
373 send_rs_str("\nHit key to continue ...");
375 send_rs_str("\n\n\n\n\n\n\n\n\n\n");