Rev 502 | Rev 514 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 502 | Rev 507 | ||
---|---|---|---|
Line 158... | Line 158... | ||
158 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
158 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
159 | /* ########################################################################## |
159 | /* ########################################################################## |
160 | * timer stuff |
160 | * timer stuff |
161 | * ##########################################################################*/ |
161 | * ##########################################################################*/ |
Line -... | Line 162... | ||
- | 162 | ||
- | 163 | static uint8_t delay_spi = 0; |
|
162 | 164 | ||
163 | /** |
165 | /** |
164 | * timer kicks in every 1000uS ^= 1ms |
166 | * timer kicks in every 1000uS ^= 1ms |
165 | */ |
167 | */ |
166 | ISR(TIMER0_COMP_vect) { |
168 | ISR(TIMER0_COMP_vect) { |
167 | if (!timer--) { |
169 | if (!timer--) { |
168 | uptime++; |
170 | uptime++; |
169 | timer = 999; |
171 | timer = 999; |
170 | seconds_since_last_data++; |
172 | seconds_since_last_data++; |
171 | } |
173 | } |
- | 174 | // in case there is still some spi data to send do it now |
|
172 | // in case there is still some spi data to send do it now |
175 | // delay to give the slave some time to compute values |
- | 176 | if (spi_ready && icnt) { |
|
173 | if (spi_ready && icnt) { |
177 | if (!delay_spi--) { |
- | 178 | delay_spi = 8; |
|
- | 179 | spi_send_next(); |
|
174 | SPDR = *iptr; |
180 | } |
175 | } |
181 | } |
176 | } |
182 | } |
Line 177... | Line 183... | ||
177 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
183 | #endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1))#endif // ends !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
Line 317... | Line 323... | ||
317 | 323 | ||
318 | while (1) { |
324 | while (1) { |
319 | // in case SPI is ready and there is nothing to send right now |
325 | // in case SPI is ready and there is nothing to send right now |
320 | if (!icnt && spi_ready) { |
326 | if (!icnt && spi_ready) { |
321 | // correct transfer ends with d (done) |
327 | // correct transfer ends with d (done) |
322 | if (spi_cmd_buffer[0] == 'd') { |
- | |
323 | ampere = spi_cmd_buffer[1] << 8; |
- | |
324 | ampere |= spi_cmd_buffer[2]; |
- | |
325 | ampere_wasted = spi_cmd_buffer[3]; |
- | |
326 | ampere_wasted = ampere_wasted << 8; |
- | |
327 | ampere_wasted |= spi_cmd_buffer[4]; |
328 | if (SPI_buffer.buffer.chk == 'd') { |
328 | ampere_wasted = ampere_wasted << 8; |
329 | ampere = SPI_buffer.data.ampere; |
329 | ampere_wasted |= spi_cmd_buffer[5]; |
- | |
330 | ampere_wasted = ampere_wasted << 8; |
330 | ampere_wasted = SPI_buffer.data.mah; |
331 | ampere_wasted |= spi_cmd_buffer[6]; |
- | |
332 | //ampere = *((int16_t *) spi_cmd_buffer + 1); |
- | |
- | 331 | s_volt = SPI_buffer.data.volt; |
|
333 | //ampere_wasted = *((int32_t *) &spi_cmd_buffer + 3); |
332 | |
334 | // if this is the first receival we should print the small A |
333 | // if this is the first receival we should print the small A |
335 | if (!(COSD_FLAGS2 & COSD_FLAG_STROMREC)) { |
334 | if (!(COSD_FLAGS2 & COSD_FLAG_STROMREC)) { |
336 | clear(); |
335 | clear(); |
337 | COSD_FLAGS2 &= ~COSD_ICONS_WRITTEN; |
336 | COSD_FLAGS2 &= ~COSD_ICONS_WRITTEN; |
338 | // update this flag |
337 | // update this flag |
339 | COSD_FLAGS2 |= COSD_FLAG_STROMREC; |
338 | COSD_FLAGS2 |= COSD_FLAG_STROMREC; |
340 | } |
- | |
341 | //write_ascii_char(8+4*30, 'v'); // valid |
339 | } |
342 | } else { |
340 | } else { |
343 | // update flags |
341 | // update flags |
344 | COSD_FLAGS2 &= ~COSD_FLAG_STROMREC; |
- | |
345 | //write_ascii_char(8+4*30, 'i'); // invalid |
342 | COSD_FLAGS2 &= ~COSD_FLAG_STROMREC; |
346 | } |
- | |
347 | spi_cmd_buffer[0] = 'A'; |
- | |
348 | spi_cmd_buffer[1] = 'B'; |
- | |
349 | spi_cmd_buffer[2] = 'C'; |
343 | } |
350 | spi_cmd_buffer[3] = 'D'; |
- | |
351 | spi_cmd_buffer[4] = 'E'; |
- | |
352 | spi_cmd_buffer[5] = 'F'; |
- | |
353 | spi_cmd_buffer[6] = 'G'; |
- | |
354 | StartTransfer((unsigned char*) spi_cmd_buffer, 7); |
344 | StartTransfer(9); |
355 | } |
345 | } |
356 | if (rxd_buffer_locked) { |
346 | if (rxd_buffer_locked) { |
357 | #if FCONLY |
347 | #if FCONLY |
358 | if (rxd_buffer[2] == 'D') { // FC Data |
348 | if (rxd_buffer[2] == 'D') { // FC Data |