Browse Source

Serial problems solved.

Setting the DDR of the serial pins before initializing the serial
hardware caused some logic '1' spikes on the tx line.
Thomas Buck 12 years ago
parent
commit
216d49726b
4 changed files with 39 additions and 14 deletions
  1. 1
    0
      CubeFirmware/cube.c
  2. 36
    13
      CubeFirmware/main.c
  3. 1
    1
      CubeFirmware/serial.c
  4. 1
    0
      CubeFirmware/time.c

+ 1
- 0
CubeFirmware/cube.c View File

20
  * You should have received a copy of the GNU General Public License
20
  * You should have received a copy of the GNU General Public License
21
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
21
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22
  */
22
  */
23
+// Uses Timer 1!
23
 #include <avr/io.h>
24
 #include <avr/io.h>
24
 #include <avr/interrupt.h>
25
 #include <avr/interrupt.h>
25
 #include <stdlib.h>
26
 #include <stdlib.h>

+ 36
- 13
CubeFirmware/main.c View File

28
 #define OK 0x42
28
 #define OK 0x42
29
 #define ERROR 0x23
29
 #define ERROR 0x23
30
 
30
 
31
+#define VERSION "8^3 LED-Cube v1\n"
32
+
33
+#define DEBUG
34
+
31
 #include <avr/io.h>
35
 #include <avr/io.h>
32
 #include <util/delay.h>
36
 #include <util/delay.h>
33
 #include <avr/interrupt.h>
37
 #include <avr/interrupt.h>
51
 void visualizeAudioData(uint8_t *audioData, uint8_t **imageData);
55
 void visualizeAudioData(uint8_t *audioData, uint8_t **imageData);
52
 
56
 
53
 uint8_t refreshAnimationCount = 1;
57
 uint8_t refreshAnimationCount = 1;
54
-uint8_t lastButtonState = 1;
58
+uint8_t lastButtonState = 0;
59
+char buffer[11];
55
 
60
 
56
 int main(void) {
61
 int main(void) {
57
 	uint8_t *audioData;
62
 	uint8_t *audioData;
61
 	uint8_t audioMode;
66
 	uint8_t audioMode;
62
 	uint16_t count;
67
 	uint16_t count;
63
 
68
 
64
-	DDRD = 0xFF; // Mosfets as Output
69
+	DDRD = 0xFC; // Mosfets as Output
65
 	DDRB = 0xFE;
70
 	DDRB = 0xFE;
66
 	DDRC = 0xFF; // Latch Enable
71
 	DDRC = 0xFF; // Latch Enable
67
 	DDRA = 0xFF; // Latch Data
72
 	DDRA = 0xFF; // Latch Data
77
 
82
 
78
 	sei(); // Enable Interrupts
83
 	sei(); // Enable Interrupts
79
 
84
 
80
-	for (i = 25; i < 55; i++) {
81
-		serialWrite(0x58); // 'X'
82
-		_delay_ms(1); // Sends garbage if no delay... :(
83
-	}
84
-
85
-	audioMode = audioModeSelected();
86
 	lastTimeChecked = getSystemTime();
85
 	lastTimeChecked = getSystemTime();
86
+	audioMode = audioModeSelected();
87
+
88
+#ifdef DEBUG
89
+#warning NOT TALKING TO FRAM YET!
90
+	refreshAnimationCount = 0; // Don't talk to FRAM yet...
91
+
92
+	serialWriteString("Initialized: ");
93
+	serialWriteString(VERSION);
94
+	serialWriteString("Took ");
95
+	serialWriteString(itoa(getSystemTime(), buffer, 10));
96
+	serialWriteString(" ms!\n");
97
+#endif
87
 
98
 
88
 	while (1) {
99
 	while (1) {
89
 		if(audioMode) {
100
 		if(audioMode) {
105
 			}
116
 			}
106
 
117
 
107
 			if (refreshAnimationCount) {
118
 			if (refreshAnimationCount) {
119
+				// Get animation count stored in FRAM via TWI, if needed
108
 				count = getAnimationCount();
120
 				count = getAnimationCount();
109
 				refreshAnimationCount = 0;
121
 				refreshAnimationCount = 0;
110
 			}
122
 			}
146
 			recieveAnimations();
158
 			recieveAnimations();
147
 			break;
159
 			break;
148
 
160
 
149
-		case 'v':
150
-			serialWriteString("v1");
161
+		case 'v': case 'V':
162
+			serialWriteString(VERSION);
163
+			break;
164
+
165
+		case 't': case 'T':
166
+			serialWriteString("System Time: ");
167
+			serialWriteString(itoa(getSystemTime(), buffer, 10));
168
+			serialWrite('\n');
151
 			break;
169
 			break;
152
 
170
 
153
 		default:
171
 		default:
301
 // Blocks 10ms or more
319
 // Blocks 10ms or more
302
 uint8_t audioModeSelected(void) {
320
 uint8_t audioModeSelected(void) {
303
 	// Pushbutton: PB0, Low active
321
 	// Pushbutton: PB0, Low active
304
-	uint64_t startTime = getSystemTime();
305
 	uint8_t startState = PINB & (1 << PB0);
322
 	uint8_t startState = PINB & (1 << PB0);
306
 
323
 
307
-	while((getSystemTime() - startTime) < 10); // Wait 10ms
324
+	_delay_ms(10);
308
 
325
 
309
 	if ((PINB & (1 << PB0)) != startState) {
326
 	if ((PINB & (1 << PB0)) != startState) {
310
 		// State changed
327
 		// State changed
311
 		// We can assume we have to toggle the state
328
 		// We can assume we have to toggle the state
329
+#ifdef DEBUG
330
+		serialWriteString("New State!");
331
+#endif
312
 		if (lastButtonState == 0) {
332
 		if (lastButtonState == 0) {
313
 			lastButtonState = 1;
333
 			lastButtonState = 1;
314
 		} else {
334
 		} else {
316
 		}
336
 		}
317
 		return lastButtonState;
337
 		return lastButtonState;
318
 	} else {
338
 	} else {
319
-		if (startState) {
339
+		if (!startState) {
320
 			// Stayed the same, is pushed!
340
 			// Stayed the same, is pushed!
341
+#ifdef DEBUG
342
+			serialWriteString("New State!");
343
+#endif
321
 			if (lastButtonState == 0) {
344
 			if (lastButtonState == 0) {
322
 				lastButtonState = 1;
345
 				lastButtonState = 1;
323
 			} else {
346
 			} else {

+ 1
- 1
CubeFirmware/serial.c View File

33
 uint16_t volatile txWrite = 0;
33
 uint16_t volatile txWrite = 0;
34
 uint8_t volatile shouldStartTransmission = 1;
34
 uint8_t volatile shouldStartTransmission = 1;
35
 
35
 
36
-ISR(USART_RX_vect) { // Receive complete
36
+ISR(USART_RXC_vect) { // Receive complete
37
     rxBuffer[rxWrite] = UDR;
37
     rxBuffer[rxWrite] = UDR;
38
 	if (rxWrite < (RX_BUFFER_SIZE - 1)) {
38
 	if (rxWrite < (RX_BUFFER_SIZE - 1)) {
39
 		rxWrite++;
39
 		rxWrite++;

+ 1
- 0
CubeFirmware/time.c View File

20
  * You should have received a copy of the GNU General Public License
20
  * You should have received a copy of the GNU General Public License
21
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
21
  * along with LED-Cube.  If not, see <http://www.gnu.org/licenses/>.
22
  */
22
  */
23
+// Uses Timer 0!
23
 #include <stdlib.h>
24
 #include <stdlib.h>
24
 #include <stdint.h>
25
 #include <stdint.h>
25
 #include <avr/io.h>
26
 #include <avr/io.h>

Loading…
Cancel
Save