Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 507 → Rev 506

/C-OSD/trunk/spi.c
24,10 → 24,10
#include "main.h"
 
volatile uint16_t icnt = 0;
volatile uint8_t request_count = 0;
volatile unsigned char * iptr;
volatile unsigned char spi_cmd_buffer[8];
volatile uint8_t spi_ready = 1;
volatile union SPI_buffer_t SPI_buffer;
int16_t ampere = 0, max_ampere = 0, s_volt;
int16_t ampere = 0, max_ampere = 0;
int32_t ampere_wasted = 0;
 
#define INT0_HIGH PORTD |= (1 << PD2);
53,13 → 53,9
* SPI interrupt handler
*/
ISR(SPI_STC_vect) {
if (request_count == 0) {
SPI_buffer.buffer.chk = SPDR; // firs char received is check byte from last transfer
} else {
SPI_buffer.buffer.c[request_count - 1] = SPDR; // safe received byte to buffer
}
request_count++;
if (--icnt) {
*iptr++ = SPDR; // safe received byte to buffer
icnt--; // dec length
if (icnt) {
//SPDR = *iptr; // send next byte
spi_ready = 1; // we _should_ send later because the slave needs more time
} else {
76,24 → 72,15
}
 
/**
* start a new transfer with length <len>
* start a new transfer of <data> with length <len>
*/
void StartTransfer(uint16_t len) {
void StartTransfer(unsigned char *data, uint16_t len) {
INT0_LOW // /SS LOW ^= SS HIGH ^= slave should listen
 
// this is a new request
request_count = 0;
 
// set up pointer and length for interrupt handler
iptr = data;
icnt = len;
 
SPCR |= _BV(SPIE); // enable spi interrupt
SPDR = 'A'; // start transfer by first command char
SPDR = *iptr; // start transfer by first bye
}
 
/**
* send next command through spi
*/
void spi_send_next() {
SPDR = 'A' + request_count;
}