Move SPI example into its own folder. Make it generic so it will run on ATmega328

This commit is contained in:
PaulZC
2021-06-28 14:37:17 +01:00
parent e280f22005
commit e4dbf7ae3a
@@ -1,5 +1,5 @@
/*
Reading lat and long via UBX binary commands over SPI (ESP32 specific example)
Reading lat and long via UBX binary commands over SPI
By: Andrew Berridge
Date: 27th June 2021
License: MIT. See license file for more information but you can
@@ -19,7 +19,8 @@
Buy a board from SparkFun!
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
NEO-M8P RTK: https://www.sparkfun.com/products/15005
SAM-M8Q: https://www.sparkfun.com/products/15106
NEO-M8U: https://www.sparkfun.com/products/16329
NEO-M9N: https://www.sparkfun.com/products/17285
Hardware Connections:
You need to connect the SPI pins from your microcontroller to the specific pins on your SparkFun product.
@@ -28,7 +29,7 @@
Most new boards now use the terms:
CS - Chip Select
COP - Controller Out, Peripheral In
COPI - Controller Out, Peripheral In
CIPO - Controller in, Peripheral Out
SCK - Serial Clock
@@ -36,10 +37,12 @@
(see here for the standard Arduino one: https://www.arduino.cc/en/reference/SPI) or the microcontroller. The
ESP32 has two standard, selectable SPI ports, for example.
IMPORTANT: there have been reports that some ublox devices do not respond to the UBX protocol over SPI
To enable SPI communication, you will need to solder the DSEL/SPI jumper closed on your u-blox board.
IMPORTANT: there have been reports that some u-blox devices do not respond to the UBX protocol over SPI
with the factory settings. You may find you need to connect to the device via USB and u-center and set
the incoming protocol to UBX only. Make sure you disable all other protocols as inputs if you can't
get things to work! Hopefully this is just a bug in the ublox firmware that will be fixed soon ;-)
get things to work! Hopefully this is just a bug in the u-blox firmware that will be fixed soon ;-)
*/
@@ -48,10 +51,20 @@
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GNSS myGNSS;
// #########################################
// Instantiate an instance of the SPI class.
// This is the default ESP32 SPI interface. Your configuration may be different, depending on the microcontroller you are using!
SPIClass spiPort (HSPI);
const uint8_t csPin = 15; // Change this to suit your own connection for the chip select pin
// Your configuration may be different, depending on the microcontroller you are using!
#define spiPort SPI // This is the SPI port on standard Ardino boards. Comment this line if you want to use a different port.
//SPIClass spiPort (HSPI); // This is the default SPI interface on some ESP32 boards. Uncomment this line if you are using ESP32.
// #########################################
const uint8_t csPin = 10; // On ATmega328 boards, SPI Chip Select is usually pin 10. Change this to match your board.
// #########################################
long lastTime = 0; //Simple local timer. Limits amount of SPI traffic to u-blox module.
@@ -59,24 +72,21 @@ void setup()
{
Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
Serial.println("SparkFun u-blox Example");
Serial.println(F("SparkFun u-blox Example"));
spiPort.begin();
spiPort.begin(); // begin the SPI port
myGNSS.setFileBufferSize(100); // set the file buffer size
//myGNSS.enableDebugging(); // Uncomment this line to see helpful debug messages on Serial
// Connect to the u-blox module using SPI port, csPin and speed setting
// ublox devices generally work up to 5Mhz. We'll use 4Mhz for this example:
// ublox devices generally work up to 5MHz. We'll use 4MHz for this example:
if (myGNSS.begin(spiPort, csPin, 4000000) == false)
{
Serial.println(F("u-blox GNSS not detected on SPI bus. Please check wiring. Freezing."));
while (1);
}
myGNSS.disableMessage(UBX_CLASS_HNR, UBX_HNR_PVT, 0x04);
myGNSS.disableMessage(UBX_CLASS_HNR, UBX_HNR_ATT, 0x04);
myGNSS.disableMessage(UBX_CLASS_HNR, UBX_HNR_INS, 0x04);
myGNSS.setAutoPVT(false); //Tell the GNSS to "send" each solution
myGNSS.setPortInput(COM_PORT_SPI, COM_TYPE_UBX); //Set the SPI port to output UBX only (turn off NMEA noise)
myGNSS.setPortOutput(COM_PORT_SPI, COM_TYPE_UBX); //Set the SPI port to output UBX only (turn off NMEA noise)
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
}