Parcourir la 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 il y a 12 ans
Parent
révision
216d49726b
4 fichiers modifiés avec 39 ajouts et 14 suppressions
  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 Voir le fichier

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

+ 36
- 13
CubeFirmware/main.c Voir le fichier

@@ -28,6 +28,10 @@
28 28
 #define OK 0x42
29 29
 #define ERROR 0x23
30 30
 
31
+#define VERSION "8^3 LED-Cube v1\n"
32
+
33
+#define DEBUG
34
+
31 35
 #include <avr/io.h>
32 36
 #include <util/delay.h>
33 37
 #include <avr/interrupt.h>
@@ -51,7 +55,8 @@ void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t **buf);
51 55
 void visualizeAudioData(uint8_t *audioData, uint8_t **imageData);
52 56
 
53 57
 uint8_t refreshAnimationCount = 1;
54
-uint8_t lastButtonState = 1;
58
+uint8_t lastButtonState = 0;
59
+char buffer[11];
55 60
 
56 61
 int main(void) {
57 62
 	uint8_t *audioData;
@@ -61,7 +66,7 @@ int main(void) {
61 66
 	uint8_t audioMode;
62 67
 	uint16_t count;
63 68
 
64
-	DDRD = 0xFF; // Mosfets as Output
69
+	DDRD = 0xFC; // Mosfets as Output
65 70
 	DDRB = 0xFE;
66 71
 	DDRC = 0xFF; // Latch Enable
67 72
 	DDRA = 0xFF; // Latch Data
@@ -77,13 +82,19 @@ int main(void) {
77 82
 
78 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 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 99
 	while (1) {
89 100
 		if(audioMode) {
@@ -105,6 +116,7 @@ int main(void) {
105 116
 			}
106 117
 
107 118
 			if (refreshAnimationCount) {
119
+				// Get animation count stored in FRAM via TWI, if needed
108 120
 				count = getAnimationCount();
109 121
 				refreshAnimationCount = 0;
110 122
 			}
@@ -146,8 +158,14 @@ void serialHandler(char c) {
146 158
 			recieveAnimations();
147 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 169
 			break;
152 170
 
153 171
 		default:
@@ -301,14 +319,16 @@ void transmitAnimations() {
301 319
 // Blocks 10ms or more
302 320
 uint8_t audioModeSelected(void) {
303 321
 	// Pushbutton: PB0, Low active
304
-	uint64_t startTime = getSystemTime();
305 322
 	uint8_t startState = PINB & (1 << PB0);
306 323
 
307
-	while((getSystemTime() - startTime) < 10); // Wait 10ms
324
+	_delay_ms(10);
308 325
 
309 326
 	if ((PINB & (1 << PB0)) != startState) {
310 327
 		// State changed
311 328
 		// We can assume we have to toggle the state
329
+#ifdef DEBUG
330
+		serialWriteString("New State!");
331
+#endif
312 332
 		if (lastButtonState == 0) {
313 333
 			lastButtonState = 1;
314 334
 		} else {
@@ -316,8 +336,11 @@ uint8_t audioModeSelected(void) {
316 336
 		}
317 337
 		return lastButtonState;
318 338
 	} else {
319
-		if (startState) {
339
+		if (!startState) {
320 340
 			// Stayed the same, is pushed!
341
+#ifdef DEBUG
342
+			serialWriteString("New State!");
343
+#endif
321 344
 			if (lastButtonState == 0) {
322 345
 				lastButtonState = 1;
323 346
 			} else {

+ 1
- 1
CubeFirmware/serial.c Voir le fichier

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

+ 1
- 0
CubeFirmware/time.c Voir le fichier

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

Chargement…
Annuler
Enregistrer