@@ -46,7 +46,7 @@ static volatile uint8_t twi_inRepStart; // in the middle of a repeated start
46
46
static void (* twi_onSlaveTransmit )(void );
47
47
static void (* twi_onSlaveReceive )(uint8_t * , int );
48
48
49
- static uint8_t twi_masterBuffer [ TWI1_BUFFER_SIZE ] ;
49
+ static uint8_t * twi_masterBuffer ;
50
50
static volatile uint8_t twi_masterBufferIndex ;
51
51
static volatile uint8_t twi_masterBufferLength ;
52
52
@@ -146,8 +146,6 @@ void twi_setFrequency1(uint32_t frequency)
146
146
*/
147
147
uint8_t twi_readFrom1 (uint8_t address , uint8_t * data , uint8_t length , uint8_t sendStop )
148
148
{
149
- uint8_t i ;
150
-
151
149
// ensure data will fit into buffer
152
150
if (TWI1_BUFFER_SIZE < length ){
153
151
return 0 ;
@@ -163,6 +161,7 @@ uint8_t twi_readFrom1(uint8_t address, uint8_t* data, uint8_t length, uint8_t se
163
161
twi_error = 0xFF ;
164
162
165
163
// initialize buffer iteration vars
164
+ twi_masterBuffer = data ;
166
165
twi_masterBufferIndex = 0 ;
167
166
twi_masterBufferLength = length - 1 ; // This is not intuitive, read on...
168
167
// On receive, the previously configured ACK/NACK setting is transmitted in
@@ -200,11 +199,6 @@ uint8_t twi_readFrom1(uint8_t address, uint8_t* data, uint8_t length, uint8_t se
200
199
if (twi_masterBufferIndex < length )
201
200
length = twi_masterBufferIndex ;
202
201
203
- // copy twi buffer to data
204
- for (i = 0 ; i < length ; ++ i ){
205
- data [i ] = twi_masterBuffer [i ];
206
- }
207
-
208
202
return length ;
209
203
}
210
204
@@ -225,8 +219,6 @@ uint8_t twi_readFrom1(uint8_t address, uint8_t* data, uint8_t length, uint8_t se
225
219
*/
226
220
uint8_t twi_writeTo1 (uint8_t address , uint8_t * data , uint8_t length , uint8_t wait , uint8_t sendStop )
227
221
{
228
- uint8_t i ;
229
-
230
222
// ensure data will fit into buffer
231
223
if (TWI1_BUFFER_SIZE < length ){
232
224
return 1 ;
@@ -242,14 +234,10 @@ uint8_t twi_writeTo1(uint8_t address, uint8_t* data, uint8_t length, uint8_t wai
242
234
twi_error = 0xFF ;
243
235
244
236
// initialize buffer iteration vars
237
+ twi_masterBuffer = data ;
245
238
twi_masterBufferIndex = 0 ;
246
239
twi_masterBufferLength = length ;
247
240
248
- // copy data to twi buffer
249
- for (i = 0 ; i < length ; ++ i ){
250
- twi_masterBuffer [i ] = data [i ];
251
- }
252
-
253
241
// build sla+w, slave device address + w bit
254
242
twi_slarw = TW_WRITE ;
255
243
twi_slarw |= address << 1 ;
0 commit comments