Subversion Repositories Code-Repo

Rev

Rev 158 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 158 Rev 192
Line 115... Line 115...
115
    }
115
    }
116
    SPI_SLAVE_SELECT_LAT = 1;
116
    SPI_SLAVE_SELECT_LAT = 1;
117
#endif
117
#endif
118
}
118
}
119
 
119
 
-
 
120
void SPI2_DMA_Init(void) {
-
 
121
    DMACON1bits.SSCON0 = 0;
-
 
122
    DMACON1bits.SSCON1 = 0; // DYLINTEN is software programmable
-
 
123
 
-
 
124
    DMACON1bits.TXINC = 1; // TXADDR is automatically incremented
-
 
125
    DMACON1bits.RXINC = 0; // RXADDR is not automatically incremented
-
 
126
 
-
 
127
    DMACON1bits.DUPLEX0 = 1;
-
 
128
    DMACON1bits.DUPLEX1 = 0; // Half-duplex mode, transmission only
-
 
129
 
-
 
130
    DMACON1bits.DLYINTEN = 0; // Interrupt is disabled
-
 
131
 
-
 
132
    DMACON2bits.DLYCYC = 0b0000; // Delay time of 1 cycle between bytes
-
 
133
    DMACON2bits.INTLVL = 0b0000; // Interrupt on transfer complete
-
 
134
}
-
 
135
 
-
 
136
void SPI2_DMA_Start(unsigned int length, void* TXADDR, void* RXADDR) {
-
 
137
    // Set length of message to transmit
-
 
138
    DMABCH = (char)(length-1 >> 8);
-
 
139
    DMABCL = (char)(length-1);
-
 
140
 
-
 
141
    // Set sourcing address
-
 
142
    TXADDRH = (char)((int)TXADDR >> 8);
-
 
143
    TXADDRL = (char)((int)TXADDR);
-
 
144
 
-
 
145
    // Set receiving address
-
 
146
    RXADDRH = (char)((int)RXADDR >> 8);
-
 
147
    RXADDRL = (char)((int)RXADDR);
-
 
148
 
-
 
149
    DMACON1bits.DMAEN = 1; // Start transmission
-
 
150
}
-
 
151
 
120
#ifndef SPI2_WRITE_ONLY
152
#ifndef SPI2_WRITE_ONLY
121
void SPI2_Recv_Interrupt_Handler() {
153
void SPI2_Recv_Interrupt_Handler() {
122
    char c;
154
    char c;
123
 
155
 
124
    if (SSP2STATbits.BF) { // Check if data receive flag is set
156
    if (SSP2STATbits.BF) { // Check if data receive flag is set