@@ -505,6 +505,19 @@ uint8_t SFE_UBLOX_GNSS::getI2CTransactionSize(void)
505
505
return (i2cTransactionSize);
506
506
}
507
507
508
+ // Sets the global size for the SPI buffer/transactions.
509
+ // Call this before begin()!
510
+ // Note: if the buffer size is too small, incoming characters may be lost if the message sent
511
+ // is larger than this buffer. If too big, you may run out of SRAM on constrained architectures!
512
+ void SFE_UBLOX_GNSS::setSpiTransactionSize (uint8_t transactionSize)
513
+ {
514
+ spiTransactionSize = transactionSize;
515
+ }
516
+ uint8_t SFE_UBLOX_GNSS::getSpiTransactionSize (void )
517
+ {
518
+ return (spiTransactionSize);
519
+ }
520
+
508
521
// Returns true if I2C device ack's
509
522
boolean SFE_UBLOX_GNSS::isConnected (uint16_t maxWait)
510
523
{
@@ -2784,7 +2797,7 @@ void SFE_UBLOX_GNSS::sendSerialCommand(ubxPacket *outgoingUBX)
2784
2797
void SFE_UBLOX_GNSS::spiTransfer (uint8_t byteToTransfer)
2785
2798
{
2786
2799
uint8_t returnedByte = _spiPort->transfer (byteToTransfer);
2787
- if (returnedByte != 0xFF || currentSentence != NONE)
2800
+ if ((spiBufferIndex < getSpiTransactionSize ()) && ( returnedByte != 0xFF || currentSentence != NONE) )
2788
2801
{
2789
2802
spiBuffer[spiBufferIndex] = returnedByte;
2790
2803
spiBufferIndex++;
@@ -2796,13 +2809,13 @@ void SFE_UBLOX_GNSS::sendSpiCommand(ubxPacket *outgoingUBX)
2796
2809
{
2797
2810
if (spiBuffer == NULL ) // Memory has not yet been allocated - so use new
2798
2811
{
2799
- spiBuffer = new uint8_t [SPI_BUFFER_SIZE ];
2812
+ spiBuffer = new uint8_t [getSpiTransactionSize () ];
2800
2813
}
2801
2814
2802
2815
if (spiBuffer == NULL ) {
2803
2816
if ((_printDebug == true ) || (_printLimitedDebug == true )) // This is important. Print this if doing limited debugging
2804
2817
{
2805
- _debugSerial->print (F (" process : memory allocation failed for SPI Buffer!" ));
2818
+ _debugSerial->print (F (" sendSpiCommand : memory allocation failed for SPI Buffer!" ));
2806
2819
}
2807
2820
}
2808
2821
0 commit comments