Hello!
I've been having a really weird problem with the Portenta H7. I have a project, where the Portenta is supposed to open communicate to a ISO1h812g SPI chip, which then in turn turns on a temperature sensor. The data from that sensor then gets read by one of the Portenta's analog pins. multiply that by 7 since I have 7 sensors and that's it. In theory quite simple, but I ran into a problem: The SPI communication suddenly stops and consequently I can't read out the sensor anymore.
With the help of a logic analyzer I got that it was in fact only the MOSI pin of the Portenta itself going completely silent, no error or anything and the code would still continue running. The SS and SCK pins still were doing their thing so from what I can conclude it's only the MOSI pin. After more testing around I noticed that the issue only occurred after trying to read out sensor 6 of 7 (technically sensor 5 if you start counting from 0). So something has to be happening between reading out Analog Pin 5 and sending the next signal. Here's a minimal example code that this error happens with:
#include <SPI.h>
int i = 0;
uint8_t data = 0;
const uint8_t analogPin[7] = {A0, A1, A2, A3, A4, A5, A6};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
SPI.begin();
analogReadResolution(16);
pinMode(MOSI, OUTPUT);
pinMode(SS, OUTPUT);
digitalWrite(MOSI, LOW);
digitalWrite(SS, HIGH);
}
void loop() {
data = 0;
data = (1 << i);
Serial.print("Stelle: "); Serial.println(data);
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE3));
digitalWrite(SS, LOW);
delayMicroseconds(50);
SPI.transfer(data);
delayMicroseconds(50);
digitalWrite(SS, HIGH);
SPI.endTransaction();
delay(100);
Serial.print("Reading: "); Serial.println(analogRead(analogPin[i]));
delay(1000);
i++;
if(i == 7) {
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE3));
digitalWrite(SS, LOW);
delayMicroseconds(50);
SPI.transfer(0x00); //reset SPI
delayMicroseconds(50);
digitalWrite(SS, HIGH);
SPI.endTransaction();
i = 0;
delay(15000); //15 second delay before next cycle
}
}
Weirdly enough if I add a "if(i == 5); else" in the loop function so that the pin that is causing the trouble gets skipped, the code works perfectly (well except for one sensor getting skipped entirely). After realizing this I tried bit banging the SPI and it works, but I would still like to know if I could use the SPI library normally with the Portenta H7 or not.
Does anyone have a clue as to why this would be? Physical problems should be ruled out.
Thank you in advance.
