1 | #include <msp430.h>
|
2 | #include "CC2500\cc2500.h"
|
3 | #include "UART\uart.h"
|
4 |
|
5 |
|
6 | const int THRESHOLD = -75;
|
7 |
|
8 | //#define DEBUG
|
9 |
|
10 |
|
11 | void t_itoa(int z, unsigned char* Buffer);
|
12 |
|
13 | unsigned char RSSI_A[10] = { 0 };
|
14 | unsigned char Channel[10] = { 0 };
|
15 |
|
16 |
|
17 |
|
18 | /*
|
19 | * main.c
|
20 | *
|
21 | */
|
22 | void main(void) {
|
23 |
|
24 | volatile int rssi_value = 0;
|
25 | volatile unsigned char state = 0;
|
26 | volatile unsigned int i = 0;
|
27 | volatile int rssi_array[500] = {0};
|
28 |
|
29 | WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
|
30 |
|
31 | UART_INIT();
|
32 | SPI_INIT();
|
33 | cc2500_sendCmdStrobe(SRES);
|
34 | cc2500_init();
|
35 | P1DIR |= 0x01;
|
36 |
|
37 |
|
38 |
|
39 | P1OUT = 0x01;
|
40 |
|
41 | cc2500_sendCmdStrobe(CC2500_RX);
|
42 |
|
43 | for(;;)
|
44 | {
|
45 |
|
46 | for(i = 0; i <= 250; i++)
|
47 | {
|
48 | state = cc2500_readReg(MARCSTATE);
|
49 | while((cc2500_readReg(MARCSTATE) & 0x1F) != 0x0D);
|
50 | state = cc2500_readReg(MARCSTATE);
|
51 | rssi_value = cc2500_readRssi();
|
52 | cc2500_sendCmdStrobe(CC2500_IDLE);
|
53 | cc2500_writeReg(CHANNR, i);
|
54 | cc2500_sendCmdStrobe(CC2500_RX);
|
55 |
|
56 | rssi_array[i] = rssi_value;
|
57 | }
|
58 |
|
59 | cc2500_sendCmdStrobe(CC2500_IDLE);
|
60 |
|
61 | cc2500_writeReg(FREQ2, 0x5D);
|
62 | cc2500_writeReg(FREQ1, 0xF0);
|
63 | cc2500_writeReg(FREQ0, 0x10);
|
64 |
|
65 | cc2500_sendCmdStrobe(CC2500_RX);
|
66 |
|
67 | for(i = 0; i <= 247; i++)
|
68 | {
|
69 | while((cc2500_readReg(MARCSTATE) & 0x1F) != 0x0D);
|
70 | rssi_value = cc2500_readRssi();
|
71 | cc2500_sendCmdStrobe(CC2500_IDLE);
|
72 | cc2500_writeReg(CHANNR, i);
|
73 | cc2500_sendCmdStrobe(CC2500_RX);
|
74 |
|
75 | rssi_array[i + 251] = rssi_value;
|
76 | }
|
77 |
|
78 |
|
79 | cc2500_sendCmdStrobe(CC2500_IDLE);
|
80 | cc2500_writeReg(FREQ2, 0x5C);
|
81 | cc2500_writeReg(FREQ1, 0x4F);
|
82 | cc2500_writeReg(FREQ0, 0xBB);
|
83 | cc2500_sendCmdStrobe(CC2500_RX);
|
84 |
|
85 | for(i = 0; i <= 499; i++)
|
86 | {
|
87 | if(rssi_array[i] >= (-75))
|
88 | {
|
89 | t_itoa(i,&Channel[0]); //funktioniert
|
90 | t_itoa(rssi_array[i],RSSI_A); //funktioniert
|
91 | uart_puts(&Channel[0]); //funktioniert überschreibt aber RSSI_A teilweise
|
92 | uart_putc(':');
|
93 | uart_puts(&RSSI_A[0]);
|
94 | uart_putc('\n');
|
95 | }
|
96 | }
|
97 | }
|
98 | }
|
99 |
|
100 | void t_itoa(int z, unsigned char* Buffer)
|
101 | {
|
102 | int i = 0;
|
103 | int j;
|
104 | char tmp;
|
105 | unsigned int u;
|
106 |
|
107 | //zahl negativ?
|
108 | if( z < 0 ) {
|
109 | Buffer[0] = '-';
|
110 | Buffer++;
|
111 | u = ( (unsigned int)(-(z+1))) + 1;
|
112 | }
|
113 | else {
|
114 | u = (unsigned int)z;
|
115 | }
|
116 |
|
117 | //Stellen berechnen
|
118 | do {
|
119 | Buffer[i++] = '0' + u % 10;
|
120 | u /= 10;
|
121 | } while( u > 0 );
|
122 |
|
123 |
|
124 | //spiegeln
|
125 | for( j = 0; j < i / 2; j++ )
|
126 | {
|
127 | tmp = Buffer[j];
|
128 | Buffer[j] = Buffer[i-j-1];
|
129 | Buffer[i-j-1] = tmp;
|
130 | }
|
131 |
|
132 | //Stringende einfügen
|
133 | Buffer[i] = '\0';
|
134 | }
|
135 |
|
136 | /////in uart.h definiert
|
137 | void uart_putc(unsigned char data)
|
138 | {
|
139 |
|
140 | while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
|
141 | UCA0TXBUF = data; // write TX buffer
|
142 | }
|
143 |
|
144 | void uart_puts(unsigned char *data)
|
145 | {
|
146 | volatile unsigned int i = 0;
|
147 |
|
148 | do
|
149 | {
|
150 | while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
|
151 | UCA0TXBUF = *(data + i++); // write TX buffer
|
152 | }
|
153 | while(*(data + i) != '\0');
|
154 |
|
155 | }
|