@@ -193,28 +193,34 @@ void SPIClass::setClockDivider(uint32_t div)
193
193
194
194
void SPIClass::transfer (const void *tx_buf, void *rx_buf, size_t count)
195
195
{
196
- nrfx_spim_xfer_desc_t xfer_desc =
196
+ const uint8_t * tx_buf8 = (const uint8_t *) tx_buf;
197
+ uint8_t * rx_buf8 = (uint8_t *) rx_buf;
198
+
199
+ while (count)
197
200
{
198
- .p_tx_buffer = (uint8_t *) tx_buf,
199
- .tx_length = tx_buf ? count : 0 ,
200
- .p_rx_buffer = (uint8_t *) rx_buf,
201
- .rx_length = rx_buf ? count : 0 ,
202
- };
201
+ // each transfer can only up to 64KB (16-bit) bytes
202
+ const size_t xfer_len = min (count, UINT16_MAX);
203
+
204
+ nrfx_spim_xfer_desc_t xfer_desc =
205
+ {
206
+ .p_tx_buffer = tx_buf8,
207
+ .tx_length = tx_buf8 ? xfer_len : 0 ,
208
+
209
+ .p_rx_buffer = rx_buf8,
210
+ .rx_length = rx_buf8 ? xfer_len : 0 ,
211
+ };
203
212
204
- nrfx_spim_xfer (&_spim, &xfer_desc, 0 );
213
+ nrfx_spim_xfer (&_spim, &xfer_desc, 0 );
214
+
215
+ count -= xfer_len;
216
+ if (tx_buf8) tx_buf8 += xfer_len;
217
+ if (rx_buf8) rx_buf8 += xfer_len;
218
+ }
205
219
}
206
220
207
221
void SPIClass::transfer (void *buf, size_t count)
208
222
{
209
- nrfx_spim_xfer_desc_t xfer_desc =
210
- {
211
- .p_tx_buffer = (uint8_t *) buf,
212
- .tx_length = count,
213
- .p_rx_buffer = (uint8_t *) buf,
214
- .rx_length = count,
215
- };
216
-
217
- nrfx_spim_xfer (&_spim, &xfer_desc, 0 );
223
+ transfer (buf, buf, count);
218
224
}
219
225
220
226
byte SPIClass::transfer (uint8_t data)
0 commit comments