Skip to content

Add spi aberridg #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 27, 2021
Merged

Add spi aberridg #43

merged 6 commits into from
Jun 27, 2021

Conversation

aberridg
Copy link
Contributor

Initial add of SPI support to the library.

Copy link
Collaborator

@PaulZC PaulZC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Andrew (@aberridg),
Sincere thanks for this - this is excellent stuff.
I've requested some changes - but I'm happy to discuss any and all of them.
If you add any new public functions (methods) please do add them to keywords.txt too. The separators in that file must be tabs not spaces.
Very best wishes,
Paul

Copy link
Collaborator

@PaulZC PaulZC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Andrew (@aberridg ),
Great stuff - thank you!
I was going to suggest that the spi buffer should be allocated dynamically, but you beat me to it! It's a nice touch - thank you. We have users for whom that permanently-allocated 20 bytes would have been a problem.
Juts one small change to the debug message (see below) and we're ready to merge.
Please add an SPI example when time permits. It doesn't need to be complex, just a copy of one of the simplest PVT examples would be great. Example3 would be perfectly adequate. But please do update the hardware connections comments to match. Users will need to know how many wires to connect (CS, CIPO, COPI, SCK) and that the DSEL jumper needs to be closed. (Please don't use the terms MISO / MOSI even though you will still see those on many of our boards. We are updating to CIPO / COPI on new boards and on any board revisions).
Great to be working with you and thanks again for the time you've devoted to this. We really appreciate it.
Very best wishes,
Paul

Hardware Connections:
Plug a Qwiic cable into the GNSS and a BlackBoard
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 115200 baud to see the output

if (spiBuffer == NULL) {
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
{
_debugSerial->print(F("process: memory allocation failed for SPI Buffer!"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change process to sendSpiCommand.
(In other libraries, I've started using the full class::function name SFE_UBLOX_GNSS::sendSpiCommand just in case you have debug messages turned on in more than one library simultaneously. But no need to do that here.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Paul - done and done :-)

Please also check my other pull request - that one is much more involved and may need (yet more) tweaking! See comments therein.

And my pleasure - I really NEED this lib for my project, so happy to enhance it to meet my needs and to help others.

@PaulZC
Copy link
Collaborator

PaulZC commented Jun 27, 2021

Thank you for the latest commit - it's another nice touch, thank you. I'm going to walk the dogs, will be back in an hour or so. If you're still tweaking and don't want me to merge when I get back, please just say so here.

PS. Just a heads up... Once folks get to know that the library supports SPI, someone will want to pushRawData over SPI too. We will, at some point (not today), need to add SPI here:

if (commType == COMM_TYPE_SERIAL)
{
// Serial: write all the bytes in one go
size_t bytesWritten = _serialPort->write(dataBytes, numDataBytes);
return (bytesWritten == numDataBytes);
}
else
{
// I2C: split the data up into packets of i2cTransactionSize

@aberridg
Copy link
Contributor Author

aberridg commented Jun 27, 2021 via email

@aberridg
Copy link
Contributor Author

aberridg commented Jun 27, 2021 via email

@aberridg
Copy link
Contributor Author

aberridg commented Jun 27, 2021 via email

@PaulZC
Copy link
Collaborator

PaulZC commented Jun 27, 2021

Thanks again Andrew,
I have many u-blox modules here. I will test several and see if the port configuration issue is limited to the NEO (or whether it is true for multiple/all modules). Yes, we do indeed have a contact at u-blox. I'll pass this along to him once we've worked out the scope of this issue.
Merging...!
Paul

@PaulZC PaulZC merged commit 34627a5 into sparkfun:release_candidate Jun 27, 2021
@aberridg
Copy link
Contributor Author

aberridg commented Jun 27, 2021 via email

@PaulZC PaulZC mentioned this pull request Jun 27, 2021
@PaulZC
Copy link
Collaborator

PaulZC commented Jun 28, 2021

Hi Andrew (@aberridg ),

It has been a successful day! You will see from the latest commits on the release_candidate branch that I have made some changes to your code. The only significant ones are:

  • I changed your debug printf's to print's as the ATmega328 does not support printf.
  • I moved the new (memory allocation) for the SPI buffer into .begin. Why? I noticed that you were still initializing the buffer with 0xFF in there. It seemed more logical to create the buffer, fill it with 0xFF, then do the isConnected test.
  • I changed the 0x0A you were using on COPI for SPI 'read' transfers to 0xFF. This made a big difference to the reliability. After doing this, I can start the code reliably on multiple platforms and multiple u-blox modules using the factory default settings. No need to set SPI-in to UBX only. I suspect the line feeds were causing confusion for the module (especially when NMEA-in was still enabled)?
  • I made your example a bit more generic, allowing it to run on the ATmega328 without modification. I also moved it into its own folder within the examples.

The current status is:

  • your code and example work OK on the following modules using factory defaults:
    • NEO-M8U
    • NEO-M9N
    • ZED-F9P
    • and ZOE-M8Q (which I'm really pleased about as that does not have a USB port for 'back door' configuration)
  • your code runs on:
    • ATmega328 RedBoard (== Arduino Uno)
    • ESP32 Thing Plus
    • Artemis ATP (using Apollo3 core v2.1)

I haven't yet got it working on Teensy 3.2. Not sure why. Maybe the faster processor is hammering the SPI bus a bit too hard?

I need to work on other things tomorrow, but over the next few days I will try and rebase the release_candidate_v2.1 branch to include the latest changes, and then give that code a go. I think what I might do is add SPI support in v2.0.8 and then release the modified state management code as v2.1.0 after giving it a good shake.

Thanks again for all the effort you've put into this,
Paul

@aberridg
Copy link
Contributor Author

aberridg commented Jun 30, 2021 via email

@PaulZC
Copy link
Collaborator

PaulZC commented Jun 30, 2021

Hi Andrew,
I have Teensy 3.2 working with the ZOE-M8Q now. I’ll try it with the other modules tomorrow. I made some small code changes this afternoon which seem to have helped, but it is entirely possible it was a simple wiring issue which was causing the earlier problem.
More tomorrow.
Very best wishes,
Paul

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants