-
Notifications
You must be signed in to change notification settings - Fork 0
/
Blinky.c
589 lines (518 loc) · 22 KB
/
Blinky.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
/*----------------------------------------------------------------------------
*
*----------------------------------------------------------------------------
* Name: BLINKY.C
* Purpose: Bare Metal example program
*----------------------------------------------------------------------------
*
* Copyright (c) 2006-2014 KEIL - An ARM Company. All rights reserved.
*---------------------------------------------------------------------------*/
#include "MKL25Z4.h" // Device header
#include "TIspi.h" //spi.h
#include <math.h>
#define WRITE_BURST 0x40 //write burst
#define READ_SINGLE 0x80 //read single
#define READ_BURST 0xC0 //read burst
#define BYTES_IN_RXFIFO 0x7F //byte number in RXfifo
/**********************************************************************
*********** Macros *************************
***********************************************************************
Aim : Macros are defined here
NOTE :
**********************************************************************/
/*LEDS*/
#define RED_OFF (FPTB->PSOR |= (1<<18))
#define RED_ON (FPTB->PCOR |= (1<<18),FPTB->PSOR |= (1<<19),(FPTD->PSOR = 0x01))
#define GREEN_OFF (FPTB->PSOR |= (1<<19))
#define GREEN_ON (FPTB->PSOR |= (1<<18),FPTB->PCOR |= (1<<19),(FPTD->PSOR = 0x01))
#define YELLOW_OFF (FPTB->PSOR |= (1<<18),FPTB->PSOR |= (1<<19),(FPTD->PSOR = 0x01))
#define YELLOW_ON (FPTB->PCOR |= (1<<18),FPTB->PCOR |= (1<<19),(FPTD->PSOR = 0x01))
#define SpiStart() FPTD->PCOR |= (1UL<<4); // CS=low, SPI start
#define SpiStop() FPTD->PSOR |= (1UL<<4); // CS=high, SPI stop
//#define SpiStart() PTA->PCOR |= (1UL); // CS=low, SPI start
//#define SpiStop() PTA->PSOR |= (1UL); // CS=high, SPI stop
#define wait_CHIP_RDYn while((FPTD->PDIR & 0x80)!= 0) //Wait for CHIP_RDYn signal
//#define wait_CHIP_RDYn while((SPI_Send(0x00) & 0x80) != 0);
/**********************************************************************
*********** Global Values *************************
***********************************************************************
Aim : Global registers are defined here
NOTE :
**********************************************************************/
char test[22];
char C[4];
uint32_t hede;
char config;
char toto[22]="AMK POKUMANI";
char got[22];
/**********************************************************************
*********** Systick *************************
***********************************************************************
Aim : initialize Systick Timer
NOTE : 1 ms Ticks
**********************************************************************/
volatile uint32_t msTicks; /* counts 1ms timeTicks */
void SysTick_Handler(void) {
msTicks++; /* increment counter necessary in Delay() */
}
__INLINE static void Delay (uint32_t dlyTicks) {
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks) < dlyTicks);
}
/**********************************************************************
*********** LED_Init *************************
***********************************************************************
Aim : initialize the leds
NOTE : 18>Red---19>Green---- 18+19>Yellow
**********************************************************************/
void LED_Init(void) {
PORTB->PCR[18] = PORT_PCR_MUX(1); /* Pin PTB18 is GPIO-RED */
PORTB->PCR[19] = PORT_PCR_MUX(1); /* Pin PTB19 is GPIO-GREEN */
PORTD->PCR[1] = PORT_PCR_MUX(1); /* Pin PTD1 is GPIO-BLUE */
FPTB->PDDR |= (1UL<<18) | (1UL<<19); /* enable PTB18/19 as Output */
FPTD->PDDR |= (1UL); // enable PTD1 as output
//Turn off leds
YELLOW_OFF; GREEN_OFF; RED_OFF;
// Turn on leds 1 by 1
YELLOW_ON; Delay(1000); GREEN_ON; Delay(1000); RED_ON; Delay(1000);
//Turn off leds
YELLOW_OFF; GREEN_OFF; RED_OFF;
}
/**********************************************************************
*********** SPI_Init *************************
***********************************************************************
Aim : initialize SPI for Kl25
NOTE :
**********************************************************************/
void spi_init(void){
int dly;
SIM->SCGC4 |= SIM_SCGC4_SPI1_MASK; //Enable SPI1 clock
//manual ss pin
PORTD->PCR[4] |= PORT_PCR_MUX(1); //SS pin gpio
PTD->PDDR |= (1UL<<4); //SS pin output PD4
// PORTA->PCR[1] |= PORT_PCR_MUX(1);
// PTA->PDDR |= (1UL);
PORTD->PCR[2] |= PORT_PCR_MUX(1); //TI_Reset pin gpio
PTD->PDDR |= (1UL<<2); //TI_Reset pin output PD4
//PORTD->PCR[0] = PORT_PCR_MUX(0x2); //Set PTD4 to mux 2 (SS)
PORTD->PCR[5] = PORT_PCR_MUX(0x02); //Set PTD5 to mux 2 (clk)
PORTD->PCR[6] = PORT_PCR_MUX(0x02); //Set PTD6 to mux 2 (Mosi)
PORTD->PCR[7] = PORT_PCR_MUX(0x02); //Set PTD7 to mux 2 (Miso)
SPI1->C1 = SPI_C1_MSTR_MASK; //Set SPI0 to Master
SPI1->C2 = SPI_C2_MODFEN_MASK; //Master SS pin acts as slave select output
// SPI1->BR = (SPI_BR_SPPR(0x111) | SPI_BR_SPR(0x1000)); //Set baud rate prescale divisor to 3 & set baud rate divisor to 32 for baud rate of 15625 hz
// SPI1->BR |= 0x30;
SPI1->BR |= 0x43;
// SPI1->C1 |= (1UL << 3) ; //SPI MOD 3
// SPI1->C1 |= (1UL << 2) ;
dly=1000;
while(dly--);
SPI1->C1 |= 0x40; //SPI1 Enable
PTD->PSOR |= (1UL<<4);
PTD->PSOR |= (1UL<<2);
}
/**********************************************************************
*********** SPI_SEND *************************
***********************************************************************
Aim : send and recieve data via SPI
NOTE :
**********************************************************************/
char SPI_Send(char Data)
{
while(!(SPI_S_SPTEF_MASK & SPI1->S));
SPI1->D = Data; //Write Data
while(!(SPI_S_SPRF_MASK & SPI1->S));
return SPI1->D; //Read Data
}
char testt;
char x;
/**********************************************************************
*********** TI_HW_Reset *************************
***********************************************************************
Aim : Hardware Reset using MCU
NOTE :active low for 200 ns, other times high
**********************************************************************/
void TI_HW_Reset(void)
{
PTD->PCOR |= (1UL<<2);
Delay(0x05);
PTD->PSOR |= (1UL<<2);
}
/**********************************************************************
*********** TI_Init *************************
***********************************************************************
Aim : wait for initialization of CC1120
NOTE :
**********************************************************************/
void TI_Init(void)
{
TI_HW_Reset();
SpiStart(); //Start SPI by CSn Low
wait_CHIP_RDYn; //Wait for TI's christal to be stabilized
// while((SPI_Send(0x00) & 0x80) != 0);
// x= SPI_Send(0x00);
// Delay(0x5000);
SpiStop(); //Stop SPI by CSn High
}
/**********************************************************************
*********** TI_Write *************************
***********************************************************************
Aim : write 1 byte data to chip via SPI
NOTE :[ R/W bit (0)] + [ Burst bit (0)] + [6 bit addres] + 8 bit data
**********************************************************************/
void TI_WriteByte( char addr, char data)
{
//int dly;
SpiStart(); //Start SPI by CSn Low
wait_CHIP_RDYn; //Wait for TI's christal to be stabilized
SPI_Send(addr); // Send 1 byte addr and write command
SPI_Send(data); // Send 1 byte data
SpiStop(); //Stop SPI by CSn High
}
/**********************************************************************
*********** TI_Read *************************
***********************************************************************
Aim : Read 1 byte data from chip via SPI
NOTE :[ R/W bit (1)] + [ Burst bit (0)] + [6 bit addres]
**********************************************************************/
char TI_ReadByte(char addr)
{
char data = 0;
SpiStart(); //Start SPI by CSn Low
wait_CHIP_RDYn; //Wait for TI's christal to be stabilized
SPI_Send( READ_SINGLE | addr); // R/w bit (1) + Burst bit (0)+ 6 bit addres
data = SPI_Send(0x00); // Data read (read 1byte data) via dummy write
SpiStop(); //Stop SPI by CSn High
return data;
}
/**********************************************************************
*********** TI_Write_brst *******************
***********************************************************************
Aim : burst write to TI chip
NOTE :[ R/W bit (0)] + [ Burst bit (1)] + [6 bit addres stars with 0x2F00]
**********************************************************************/
int TI_Write_brst(int addr,char* buf,int len)
{
int i = 0;
SpiStart(); //Start SPI by CSn Low
wait_CHIP_RDYn; //Wait for TI's christal to be stabilized
SPI_Send ( WRITE_BURST | addr ); // Send the adrr
for(i = 0; i < len; i++) // Burst Write the data
{
SPI_Send (buf[i]);
}
SpiStop(); //Stop SPI by CSn High
return len;
}
/**********************************************************************
*********** TI_READ_brst *********************
***********************************************************************
Aim : burst read to TI chip
NOTE :[ R/W bit (1)] + [ Burst bit (1)] + [6 bit addres]
**********************************************************************/
int TI_Read_brst(int addr, char* buf,int len)
{
int i = 0;
SpiStart(); //Start SPI by CSn Low
wait_CHIP_RDYn; //Wait for TI's christal to be stabilized
SPI_Send ( READ_BURST | addr ); // Address byte 1
for(i = 0; i < len; i++) // Write data in loop
{
buf[i] = SPI_Send(0x00); //write data to buffer with size of "len"
}
SpiStop(); //Stop SPI by CSn High
return len;
}
/**********************************************************************
*********** Write TI_Command *****************
***********************************************************************
Aim : command strobe acces
NOTE :[ R/W bit (0)] + [ Burst bit (0)] + [6 bit addres]
No data is expected. Chip_status_Byte is returned from chip
**********************************************************************/
void TI_Command( char command )
{
SpiStart(); //Start SPI by CSn Low
wait_CHIP_RDYn; //Wait for TI's christal to be stabilized
SPI_Send(command); //Send chip command
SpiStop(); //Stop SPI by CSn High
}
char TI_Command_Read(char command)
{
char ret;
SpiStart(); //Start SPI by CSn Low
wait_CHIP_RDYn; //Wait for TI's christal to be stabilized
SPI_Send(command|READ_SINGLE); //Send chip command with READ bit
ret=SPI_Send(0x00); //send dummy byte so read status byte
SpiStop(); //Stop SPI by CSn High
return ret;
}
/**********************************************************************
*********** DelayUs *********************
***********************************************************************
Aim : Blind Delay
NOTE : microsecond delay (To be Calibrated)
**********************************************************************/
char DelayUs(long t)
{
do
{
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
// __NOP();
// __NOP();
// __NOP();
} while(--t);
return 1;
}
/**********************************************************************
*********** Read Temp Sensor *********************
***********************************************************************
Aim : temp sensor digital readout
NOTE : see DN-403 Application note!!!
**********************************************************************/
int8_t getCelcius(void)
{
//Variables
char RegValue = 0;
char marcStatus;
char writeByte;
uint32_t ADCValue_I = 0;
int8_t celsius = 0;
//String to put radio in debug mode
char txBuffer[18] =
{0x0F,0x28,0x02,0x90,0x42,0x1B,0x7E,0x1F,0xFE,0xCD,0x06,0x1B,0x0E,0xA1,0x0E,0xA4,0x00,0x3F};
//Constants for temperature calculation (for 3V input!!!)
float a = -3.3;
float b = 992;
float c = -2629.9;
//temp sensor digital readout
TI_WriteByte(CC112X_DCFILT_CFG,0x40);
TI_WriteByte(CC112X_MDMCFG1 ,0x47);
TI_WriteByte(CC112X_CHAN_BW,0x81);
TI_WriteByte(CC112X_FREQ_IF_CFG,0x00);
config = 0x2A; TI_Write_brst(CC112X_ATEST,&config,1);
config = 0x07; TI_Write_brst(CC112X_ATEST_MODE,&config,1);
config = 0x07; TI_Write_brst(CC112X_GBIAS1,&config,1);
config = 0x01; TI_Write_brst(CC112X_PA_IFAMP_TEST,&config,1);
TI_Command(CC112X_SRX);
Delay(100);
// TI_Command(CC112X_SNOP);
// test[0] = SPI_Send(0x00);
//Read marcstate and wait until chip is in RX
// do {
// TI_Read_brst(CC112X_MARCSTATE, &marcStatus, 1);
// } while (marcStatus != 0x6D);
// NOTE!!!!->set radio to debug mode to turn IFAMP off and read CHFILTreg
// ***** Set radio in debug mode *****
TI_Write_brst(CC112X_BURST_RXFIFO,txBuffer,sizeof(txBuffer)); // Write debug init to tx fifo
writeByte=0x01; TI_Write_brst( CC112X_BIST, &writeByte, 1); // Run code from FIFO
TI_Command(CC112X_SIDLE); // Strobe IDLE
writeByte=0x1F;
TI_WriteByte( CC112X_WOR_EVENT0_LSB, 0x1F); // Set IF AMP in PD
TI_Command(CC112X_SXOFF); // Strobe SXOFF to copy command over
// ***** Set radio in debug mode END *****
//Wait until channel filter data is valid
do {
TI_Read_brst(CC112X_CHFILT_I2, &RegValue, 1);
} while (!RegValue&0x08);
//Read ADC value from CHFILT_I registers
TI_Read_brst(CC112X_CHFILT_I2, &RegValue, 1);
ADCValue_I = ((uint32_t)RegValue) << 16;
TI_Read_brst(CC112X_CHFILT_I1, &RegValue, 1);
ADCValue_I |= (((uint32_t)RegValue) << 8) & 0x0000FF00;
TI_Read_brst(CC112X_CHFILT_I0, &RegValue, 1);
ADCValue_I |= (uint32_t)(RegValue) & 0x000000FF;
celsius = (int) ( (-b+sqrt(pow(b,2)-(4*a*(c-ADCValue_I)) ) ) / (2*a)); //Convert ADV value to celsius
//Return degrees celsius
return celsius;
}
/**********************************************************************
*********** getRegisters *****************
***********************************************************************
Aim : read registers
NOTE : testing the register write
**********************************************************************/
char reg[100];
void getReg_Test(void)
{
reg[0] = TI_ReadByte(CC112X_DCFILT_CFG); //0x40
reg[1] = TI_ReadByte(CC112X_IOCFG2 ); //0x06
reg[2] = TI_ReadByte(CC112X_IOCFG1) ; //, 0xB0);
reg[3] = TI_ReadByte(CC112X_IOCFG0) ;//, 0x40);
reg[4] = TI_ReadByte(CC112X_SYNC_CFG1);//, 0x08);
reg[5] = TI_ReadByte(CC112X_DEVIATION_M);//, 0x48);
reg[6] = TI_ReadByte(CC112X_MODCFG_DEV_E);//, 0x0D);
reg[7] = TI_ReadByte(CC112X_DCFILT_CFG);//, 0x1C);
reg[8] = TI_ReadByte(CC112X_IQIC);//, 0x00);
reg[9] = TI_ReadByte(CC112X_CHAN_BW);//, 0x02);
reg[10] = TI_ReadByte(CC112X_SYMBOL_RATE2);//, 0x73);
reg[11] = TI_ReadByte(CC112X_AGC_REF);//, 0x36);
reg[12] = TI_ReadByte(CC112X_AGC_CS_THR);//, 0x19);
reg[13] = TI_ReadByte(CC112X_AGC_CFG1);//, 0x89);
reg[14] = TI_ReadByte(CC112X_AGC_CFG0);//, 0xCF);
reg[15] = TI_ReadByte(CC112X_FIFO_CFG);//, 0x00);
reg[16] = TI_ReadByte(CC112X_SETTLING_CFG);//, 0x03);
reg[17] = TI_ReadByte(CC112X_FS_CFG);//, 0x12);
reg[18] = TI_ReadByte(CC112X_PKT_CFG0);//, 0x20); //infinite packet length
reg[19] = TI_ReadByte(CC112X_PA_CFG0);//, 0x7B);
reg[20] = TI_ReadByte(CC112X_PKT_LEN);//, 0xFF);
}
/**********************************************************************
*********** setRegisters *****************
***********************************************************************
Aim : Set default registers
NOTE :
**********************************************************************/
void setRegisters(void)
{
TI_WriteByte(CC112X_DCFILT_CFG,0x40);
TI_WriteByte(CC112X_IOCFG2, 0x06);
TI_WriteByte(CC112X_IOCFG1, 0xB0);
TI_WriteByte(CC112X_IOCFG0, 0x40);
getReg_Test();
TI_WriteByte(CC112X_SYNC_CFG1, 0x08);
TI_WriteByte(CC112X_DEVIATION_M, 0x48);
TI_WriteByte(CC112X_MODCFG_DEV_E, 0x0D);
getReg_Test();
TI_WriteByte(CC112X_DCFILT_CFG, 0x1C);
getReg_Test();
TI_WriteByte(CC112X_IQIC, 0x00);
TI_WriteByte(CC112X_CHAN_BW, 0x02);
getReg_Test();
TI_WriteByte(CC112X_SYMBOL_RATE2, 0x73);
TI_WriteByte(CC112X_AGC_REF, 0x36);
TI_WriteByte(CC112X_AGC_CS_THR, 0x19);
TI_WriteByte(CC112X_AGC_CFG1, 0x89);
TI_WriteByte(CC112X_AGC_CFG0, 0xCF);
TI_WriteByte(CC112X_FIFO_CFG, 0x00);
TI_WriteByte(CC112X_SETTLING_CFG, 0x03);
TI_WriteByte(CC112X_FS_CFG, 0x12);
TI_WriteByte(CC112X_PKT_CFG0, 0x20); //infinite packet length
TI_WriteByte(CC112X_PA_CFG0, 0x7B);
TI_WriteByte(CC112X_PKT_LEN, 0xFF);
/******************************************************
extended registers are written here
*********************************************************/
config = 0x00; TI_Write_brst(CC112X_IF_MIX_CFG,&config,1);
config = 0x22; TI_Write_brst(CC112X_FREQOFF_CFG,&config,1);
config = 0x6C; TI_Write_brst(CC112X_FREQ2,&config,1);
config = 0x80; TI_Write_brst(CC112X_FREQ1,&config,1);
config = 0x00; TI_Write_brst(CC112X_FS_DIG1,&config,1);
config = 0x5F; TI_Write_brst(CC112X_FS_DIG0,&config,1);
config = 0x40; TI_Write_brst(CC112X_FS_CAL1,&config,1);
config = 0x0E; TI_Write_brst(CC112X_FS_CAL0,&config,1);
config = 0x03; TI_Write_brst(CC112X_FS_DIVTWO,&config,1);
config = 0x33; TI_Write_brst(CC112X_FS_DSM0,&config,1);
config = 0x17; TI_Write_brst(CC112X_FS_DVC0,&config,1);
config = 0x50; TI_Write_brst(CC112X_FS_PFD,&config,1);
config = 0x6E; TI_Write_brst(CC112X_FS_PRE,&config,1);
config = 0x14; TI_Write_brst(CC112X_FS_REG_DIV_CML,&config,1);
config = 0xAC; TI_Write_brst(CC112X_FS_SPARE,&config,1);
config = 0xB4; TI_Write_brst(CC112X_FS_VCO0,&config,1);
config = 0x03; TI_Write_brst(CC112X_LNA,&config,1);
config = 0x0E; TI_Write_brst(CC112X_XOSC5,&config,1);
config = 0x03; TI_Write_brst(CC112X_XOSC1,&config,1);
config = 0x10; TI_Write_brst(CC112X_PKT_CFG2,&config,1);
}
/**********************************************************************
*********** Main Program ***********************
***********************************************************************
Aim : main program
NOTE :
**********************************************************************/
int main (void)
{
SystemCoreClockUpdate();
// SysTick_Config(10000); //turn SysTick timer on
SysTick_Config(SystemCoreClock/1600); // 1ms SysTicks
Delay(100); //wait for system stabilization
SIM->SCGC5 |= SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTB_MASK; //Port-D-B clock ON
SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK;
Delay(0x500); //delay
LED_Init(); //Initialize the LEDs
spi_init(); // SPI-1 init
Delay(0x100); //delay
hede=PTD->PDIR;
TI_Init();
// TI_HW_Reset();
// Delay(0x3000); //delay for logic analyzer
hede=PTD->PDIR;
// SpiStart();
// SPI_Send(0x10);
// SpiStop();
// test[0]=TI_ReadByte(0x0F);
// test[1]=TI_ReadByte(0x0F);
// test[2]=TI_ReadByte(0x0F);
// test[3]=TI_ReadByte(0x0F);
// test[4]=TI_ReadByte(0x0F);
//
// TI_WriteByte(CC112X_IOCFG3,0x87);
// test[5]=TI_ReadByte(CC112X_IOCFG3);
// TI_Command(CC112X_SRES); //sofware reset
//
// test[6]=TI_ReadByte(CC112X_IOCFG3);
// TI_WriteByte(CC112X_IOCFG3,0x87);
// test[7]=TI_ReadByte(CC112X_IOCFG3);
//
TI_Write_brst(CC112X_BURST_TXFIFO,toto,20);
Delay(100);
TI_Read_brst(CC112X_RSSI1,got,1);
//Delay(100);
//TI_Command(CC112X_SRES); //sofware reset
setRegisters();
getReg_Test();
// TI_WriteByte(CC112X_DCFILT_CFG,0x40);
// TI_WriteByte(CC112X_IOCFG2, 0x06);
// TI_WriteByte(CC112X_IOCFG1, 0xB0);
// TI_WriteByte(CC112X_IOCFG0, 0x40);
test[0] = getCelcius(); //Read temp sensor TEST
// Delay(0x2000);
while(1)
{
// Turn on leds 1 by 1
YELLOW_ON; Delay(1000); GREEN_ON; Delay(1000);
RED_ON; Delay(1000);
//Turn off leds
YELLOW_OFF; GREEN_OFF; RED_OFF;
// SpiStart();
// hede=PTD->PDIR;
// DelayUs(0x1000);
// SPI_Send(0x10);
// x=SPI_Send(0x00);
// x=SPI_Send(0x00);
// SpiStop();
// Delay(0x50);
// SpiStart();
// SPI_Send(0x10);
// x=SPI_Send(0x00);
// SpiStop();
// hede=PTD->PDIR;
//
// SpiStop();
//// YELLOW_ON; Delay(1000); GREEN_ON; Delay(1000); RED_ON; Delay(1000);
//// TI_WriteByte(CC112X_IOCFG3,0x87);
//// test[2]=TI_ReadByte(CC112X_IOCFG3);
//// YELLOW_OFF; GREEN_OFF; RED_OFF;
//
// PTD->PCOR |= (1UL<<4); // CS=0, SPI start
//
// hede=PTD->PDIR;
//// test[0]=SPI_Send(0x10);
// while((PTD->PDIR & 0x80)!= 0); //Wait for CHIP_RDYn signal
//
// SPI_Send(0x8F); //send the adress and get the status byte
// test[2]= SPI_Send(0x00); //read the adress
//// test[1]=SPI_Send(0x00);
//// test[2]=SPI_Send(0x10);
//// test[3]=SPI_Send(0x00);
//// SPI_Send(0x10);
//
// PTD->PSOR |= (1UL<<4); // CS=0, SPI stop
}
}