Skip to content

Commit cb24b64

Browse files
committed
Added spi transaction size :-) It still defaults to 128... please adjust downwards if you feel necessary.
1 parent b7e90c6 commit cb24b64

3 files changed

+24
-3
lines changed

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ end KEYWORD2
5555
setI2CpollingWait KEYWORD2
5656
setI2CTransactionSize KEYWORD2
5757
getI2CTransactionSize KEYWORD2
58+
setSpiTransactionSize KEYWORD2
59+
getSpiTransactionSize KEYWORD2
5860
isConnected KEYWORD2
5961
enableDebugging KEYWORD2
6062
disableDebugging KEYWORD2

src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,19 @@ uint8_t SFE_UBLOX_GNSS::getI2CTransactionSize(void)
505505
return (i2cTransactionSize);
506506
}
507507

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+
508521
//Returns true if I2C device ack's
509522
boolean SFE_UBLOX_GNSS::isConnected(uint16_t maxWait)
510523
{
@@ -2851,7 +2864,7 @@ void SFE_UBLOX_GNSS::sendSerialCommand(ubxPacket *outgoingUBX)
28512864
void SFE_UBLOX_GNSS::spiTransfer(uint8_t byteToTransfer)
28522865
{
28532866
uint8_t returnedByte = _spiPort->transfer(byteToTransfer);
2854-
if (returnedByte != 0xFF || currentSentence != NONE)
2867+
if ((spiBufferIndex < getSpiTransactionSize()) && (returnedByte != 0xFF || currentSentence != NONE))
28552868
{
28562869
spiBuffer[spiBufferIndex] = returnedByte;
28572870
spiBufferIndex++;
@@ -2863,13 +2876,13 @@ void SFE_UBLOX_GNSS::sendSpiCommand(ubxPacket *outgoingUBX)
28632876
{
28642877
if (spiBuffer == NULL) //Memory has not yet been allocated - so use new
28652878
{
2866-
spiBuffer = new uint8_t[SPI_BUFFER_SIZE];
2879+
spiBuffer = new uint8_t[getSpiTransactionSize()];
28672880
}
28682881

28692882
if (spiBuffer == NULL) {
28702883
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
28712884
{
2872-
_debugSerial->print(F("process: memory allocation failed for SPI Buffer!"));
2885+
_debugSerial->print(F("sendSpiCommand: memory allocation failed for SPI Buffer!"));
28732886
}
28742887
}
28752888

src/SparkFun_u-blox_GNSS_Arduino_Library.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,11 @@ class SFE_UBLOX_GNSS
576576
void setI2CTransactionSize(uint8_t bufferSize);
577577
uint8_t getI2CTransactionSize(void);
578578

579+
//Control the size of the spi buffer. If the buffer isn't big enough, we'll start to lose bytes
580+
//That we receive if the buffer is full!
581+
void setSpiTransactionSize(uint8_t bufferSize);
582+
uint8_t getSpiTransactionSize(void);
583+
579584
//Set the max number of bytes set in a given I2C transaction
580585
uint8_t i2cTransactionSize = 32; //Default to ATmega328 limit
581586

@@ -1310,6 +1315,7 @@ class SFE_UBLOX_GNSS
13101315

13111316
uint8_t *spiBuffer = NULL; // A buffer to store any bytes being recieved back from the device while we are sending via SPI
13121317
uint8_t spiBufferIndex = 0; // Index into the SPI buffer
1318+
uint8_t spiTransactionSize = SPI_BUFFER_SIZE; //Default size of the SPI buffer
13131319

13141320
//Init the packet structures and init them with pointers to the payloadAck, payloadCfg, payloadBuf and payloadAuto arrays
13151321
ubxPacket packetAck = {0, 0, 0, 0, 0, payloadAck, 0, 0, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED};

0 commit comments

Comments
 (0)