-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_acktest.c
141 lines (111 loc) · 4.7 KB
/
main_acktest.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
/*
* This file is licensed under BSD. It is originally copyright Texas Instruments,
* but has been adapted by Lars Kristian Roland
*/
/*
* Put an LED between P1.4 and GND (or VCC). Press the button on the other board,
* and your LED should turn on and off. This demo implements an ACK packet that
* goes back to the recipient. (Both devices use the same address).
*/
#define interrupt(x) void __attribute__((interrupt (x)))
#include "include.h"
#include "uart.h"
#include "utils.h"
extern char paTable[];
extern char paTableLen;
char txBuffer[12];
char rxBuffer[12];
unsigned int i = 0;
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
// 5ms delay to compensate for time to startup between MSP430 and CC1100/2500
__delay_cycles(5000);
uartInit();
TI_CC_SPISetup(); // Initialize SPI port
TI_CC_PowerupResetCCxxxx(); // Reset CCxxxx
writeRFSettings(); // Write RF settings to config reg
TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE
// Configure ports -- switch inputs, LEDs, GDO0 to RX packet info from CCxxxx
TI_CC_SW_PxREN |= TI_CC_SW1; // Enable Pull up resistor
TI_CC_SW_PxOUT |= TI_CC_SW1; // Enable pull up resistor
TI_CC_SW_PxIES |= TI_CC_SW1; // Int on falling edge
TI_CC_SW_PxIFG &= ~(TI_CC_SW1); // Clr flags
TI_CC_SW_PxIE |= TI_CC_SW1; // Activate interrupt enables
TI_CC_LED_PxOUT &= ~(TI_CC_LED1); // Outputs = 0
TI_CC_LED_PxDIR |= TI_CC_LED1;// LED Direction to Outputs
TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN; // Int on falling edge (end of pkt)
TI_CC_GDO0_PxIFG &= ~TI_CC_GDO0_PIN; // Clear flag
TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN; // Enable int on end of packet
TI_CC_SPIStrobe(TI_CCxxx0_SRX); // Initialize CCxxxx in RX mode.
// When a pkt is received, it will
// signal on GDO0 and wake CPU
//__bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
}
// The ISR assumes the interrupt came from a pressed button
interrupt(PORT1_VECTOR) PORT1_ISR()
{
// If Switch was pressed
if(TI_CC_SW_PxIFG & TI_CC_SW1)
{
// Build packet
txBuffer[0] = 11; // Packet length
txBuffer[1] = 0x01; // Packet address
txBuffer[2] = TI_CC_LED1;
txBuffer[3] = 0x32;
txBuffer[4] = 0x33;
txBuffer[5] = 0x34;
txBuffer[6] = 0x35;
txBuffer[7] = 0x36;
txBuffer[8] = 0x37;
txBuffer[9] = 0x38;
txBuffer[10] = 0x39;
txBuffer[11] = 0x40;
// Using printf isn't very efficient, although if you configure your compiler,
// http://www.43oh.com/forum/viewtopic.php?f=10&t=1732&hilit=tiny+printf
uart_printf("TX PKT:%i\r\n", txBuffer[3]);// An example of what we want to show on serial
RFSendPacket(txBuffer, 12); // Send value over RF
__delay_cycles(5000); // Switch debounce
}
TI_CC_SW_PxIFG &= ~(TI_CC_SW1); // Clr flag that caused int
}
// The ISR assumes the interrupt came from GDO0. GDO0 fires indicating that
// CCxxxx received a packet
interrupt(PORT2_VECTOR) PORT2_ISR()
{
// if GDO fired
if(TI_CC_GDO0_PxIFG & TI_CC_GDO0_PIN)
{
char len=11; // Len of pkt to be RXed (only addr
// plus data; size byte not incl b/c
// stripped away within RX function)
if (RFReceivePacket(rxBuffer,&len))
{
// Fetch packet from CCxxxx
TI_CC_LED_PxOUT ^= rxBuffer[1]; // Toggle LEDs according to pkt data
if (rxBuffer[1] == 0xFF)
{
uart_printf("RX ACK\r\n");
}
else
{
__delay_cycles(100000);
__delay_cycles(100000);
__delay_cycles(100000);
__delay_cycles(100000);
__delay_cycles(100000);
// Send ACK
// Build packet
txBuffer[0] = 3; // Packet length
txBuffer[1] = 0x01; // Packet address
txBuffer[2] = 0xFF;
txBuffer[3] = 0x00;
RFSendPacket(txBuffer, 4); // Send value over RF
uart_printf("RX PKT:%i\r\n", rxBuffer[2]);// An example of what we want to show on serial
uart_printf("TX ACK\r\n"); // Similar to printf, but printf probably takes longer
}
}
}
TI_CC_GDO0_PxIFG &= ~TI_CC_GDO0_PIN; // After pkt RX, this flag is set.
}