Subversion Repositories Projects

Rev

Rev 728 | Rev 800 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 728 Rev 761
Line 48... Line 48...
48
    IOReg = SPSR; // clear SPIF bit in SPSR
48
    IOReg = SPSR; // clear SPIF bit in SPSR
49
    IOReg = SPDR;
49
    IOReg = SPDR;
50
    //sei(); // we do it later
50
    //sei(); // we do it later
51
}
51
}
52
 
52
 
53
 
-
 
54
/**
53
/**
55
 * SPI interrupt handler
54
 * SPI interrupt handler
56
 */
55
 */
57
ISR(SPI_STC_vect) {
56
ISR(SPI_STC_vect) {
58
        if (request_count == 0) {
57
    if (request_count == 0) {
59
                SPI_buffer.buffer.chk = SPDR; // firs char received is check byte from last transfer
58
        SPI_buffer.buffer.chk = SPDR; // firs char received is check byte from last transfer
60
        } else {
59
    } else {
61
                SPI_buffer.buffer.c[request_count - 1] = SPDR; // safe received byte to buffer
60
        SPI_buffer.buffer.c[request_count - 1] = SPDR; // safe received byte to buffer
62
        }
61
    }
63
        request_count++;
62
    request_count++;
64
    if (--icnt) {
63
    if (--icnt) {
65
        //SPDR = *iptr; // send next byte
64
        //SPDR = *iptr; // send next byte
66
        spi_ready = 1; // we _should_ send later because the slave needs more time
65
        spi_ready = 1; // we _should_ send later because the slave needs more time
67
    } else {
66
    } else {
68
        SPCR &= ~_BV(SPIE); // deactivate interrupt
67
        SPCR &= ~_BV(SPIE); // deactivate interrupt
Line 81... Line 80...
81
 * start a new transfer with length <len>
80
 * start a new transfer with length <len>
82
 */
81
 */
83
void StartTransfer(uint16_t len) {
82
void StartTransfer(uint16_t len) {
84
    INT0_LOW // /SS LOW ^= SS HIGH ^= slave should listen
83
    INT0_LOW // /SS LOW ^= SS HIGH ^= slave should listen
85
 
84
 
86
        // this is a new request
85
    // this is a new request
87
        request_count = 0;
86
    request_count = 0;
88
 
87
 
89
    // set up pointer and length for interrupt handler
88
    // set up pointer and length for interrupt handler
90
    icnt = len;
89
    icnt = len;
91
 
90
 
92
    SPCR |= _BV(SPIE); // enable spi interrupt
91
    SPCR |= _BV(SPIE); // enable spi interrupt
93
        SPDR = 'A'; // start transfer by first command char
92
    SPDR = 'A'; // start transfer by first command char
94
}
93
}
95
 
94
 
96
/**
95
/**
97
 * send next command through spi
96
 * send next command through spi
98
 */
97
 */
99
void spi_send_next() {
98
void spi_send_next() {
100
        SPDR = 'A' + request_count;
99
    SPDR = 'A' + request_count;
101
}
100
}
102
 
101
 
103
#endif
102
#endif