-
Notifications
You must be signed in to change notification settings - Fork 37
Fix bug that sets pin 10 to INPUT on WiFi boards #22
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
Conversation
netConnectionState being initialized to NetworkConnectionState::DISCONNECTED caused the WiFiNINA library's SpiDrv::end() to be called before SpiDrv::begin(). Since SLAVESELECT is initialized to 10, and only assigned SPIWIFI_SS in SpiDrv::begin(), this causes pin 10 to be set to INPUT. Since pin 10 is MISO on the MKR boards, and often used as CS on the Nano 33 IoT, and WiFiConnectionHandler::update() is typically called from loop(), after SPI has already been configured, this breaks communication on SPI.
I've successfully tested with a @ubidefeo I don't have anything with SD-Card at hand, can you please test this fix if it resolves your issue? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test with MKR WiFi 1010
and works ... waiting for @ubidefeo testing with a SD card.
I do, @aentinger |
@ubidefeo Any chance testing this change on your setup? |
testing it today, @aentinger |
Works great |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged
@per1234 @aentinger #include <SD.h>
#include <WiFiNINA.h>
#include <RTCZero.h>
#include "thingProperties.h"
#define CHIP_SEL 4
File logFile;
unsigned long lastTickTime;
#define TICK_INTERVAL 1000
RTCZero realTimeClock;
void setup()
{
// put your setup code here, to run once:
Serial.begin(19200);
delay(3000);
// Connect to Arduino IoT Cloud
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(4);
ArduinoCloud.printDebugInfo();
if(SD.begin(CHIP_SEL)){
Serial.println("SD OK");
}else{
Serial.println("Failed to init SD Card");
}
lastTickTime = millis();
}
void loop()
{
// put your main code here, to run repeatedly:
unsigned long msNow = millis();
ArduinoCloud.update();
if (msNow - lastTickTime >= TICK_INTERVAL)
{
lastTickTime = msNow;
updateCloudData();
writeLogFile();
listFiles();
}
}
void updateCloudData()
{
char fileName[13];
secondCounter++;
if (secondCounter >= 3600)
{
secondCounter = 0;
hourCounter++;
}
uint32_t rtcEpoch = realTimeClock.getEpoch();
Serial.println(realTimeClock.getYear());
Serial.println(realTimeClock.getMonth());
Serial.println(realTimeClock.getDay());
Serial.print("EPOCH: ");
Serial.println(rtcEpoch);
Serial.println(fileName);
}
void writeLogFile()
{
static int counterItem = 0;
counterItem++;
char bfr[12];
sprintf(bfr, "file%d.log", counterItem);
logFile = SD.open("file.log", FILE_WRITE);
if(logFile){
Serial.println("File created");
logFile.close();
}else{
Serial.println("Could not create file");
}
}
void onSecondCounterChange()
{
Serial.print("seconds updated: ");
Serial.println(secondCounter);
}
void onHourCounterChange()
{
Serial.print("hour updated: ");
Serial.println(hourCounter);
}
void updateLogFile()
{
char fileName[13];
sprintf(fileName, "20%d%02d%02d.log", realTimeClock.getYear(), realTimeClock.getMonth(), realTimeClock.getDay());
Serial.println(fileName);
File logFile = SD.open("datafile.log");
logFile.print("hello");
logFile.close();
return;
if (!logFile)
{
Serial.print("FAILED to open log file ");
Serial.println(fileName);
Serial.println("attempt at creating it");
logFile = SD.open("datafile.log");
if (!logFile)
{
Serial.println("UTTER FAILURE TO CREATE FILE datafile.log");
}
}
if (logFile)
{
char dataSet[96];
uint32_t timeStamp = realTimeClock.getEpoch();
uint32_t freeMem = 0; //freeMemory();
sprintf(dataSet, "%lu,%lu", timeStamp, freeMem);
logFile.println(dataSet);
logFile.close();
}
}
void listFiles()
{
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
File root = SD.open("/");
printDirectory(root, 2);
}
void printDirectory(File dir, int numTabs) {
Serial.println("*** Directory ***");
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
Serial.println("*** Directory ***");
} |
Using the same hardware as you and Arduino_ConnectionHandler @ f2a1b11 (the commit before this PR was merged) the output of the sketch is:
Using Arduino_ConnectionHandler @ a498cd0 (the commit after this PR was merged) the output of the sketch is:
Are you getting different results @ubidefeo? |
Found the culprit! I was using Thank you for hunting this down. |
netConnectionState
being initialized toNetworkConnectionState::DISCONNECTED
caused the WiFiNINA library'sSpiDrv::end()
to be called beforeSpiDrv::begin()
. SinceSLAVESELECT
is initialized to 10, and only assignedSPIWIFI_SS
inSpiDrv::begin()
, this causes pin 10 to be set toINPUT
. Since pin 10 is MISO on the MKR boards, and often used as CS on the Nano 33 IoT, andWiFiConnectionHandler::update()
is typically called fromloop()
, after SPI has already been configured, this breaks communication on SPI.Demonstration sketch:
Bug reported at: