2020-05-12 05:18 AM
Hello,
I know it sounds like a basic and dumb question but I actually didn't find the answer.
I have communication issues between 2 STM32H743 based Nucleos.
On the master I use SPI1.
If I use SPI1 on the Slave it works fine (repeated send/receive communications).
If I use SPI2 on the Slave, I have communication issues: the Slave receives data correctly but the Master receives crap (CRC error).
The settings are:
So my question: when using alternate function for a GPIO, does the pullup/pulldown setting matter ? Same question for output type (push-pull / open drain) ? And what settings should be used for SPI pins ? HAL examples from ST set all SPI pins with pull-down and push-pull. Is it correct ?
2020-05-14 12:14 AM
Sorry but didn't you say exactly the contrary ? "OTYPER push-pull; pulldowns mostly don't matter as the lines are supposed to be hard driven from the respective party whenever needed."
EDIT: I probably misunderstood the sentence, you probably meant: "set the pushpull and pullup/down don't matter"
2020-05-14 12:30 AM
For any port pin, first you need to decide which mode it operates. MODEy could be used for that purpose.
You could choose one of the below modes
Digital input mode
Digital output mode
Alternate function mode
Analog mode
For your exact scenario, you would have to choose Alternate function mode for all the SPI relevant port pins. In that case for each of the SPI pin (MISO, MOSI, CS, CLK) below settings needs to ensured that it is right
PUPDRy, OSPEEDy, OTy & AFRy
Regards,
Bivin
2020-05-14 12:48 AM
I changed the OSPEED setting from "very high" to "high" and it seems to fix the issue. As far as I understood a higher GPIO speed creates more noise so it might explain my behaviour ?
2020-05-28 04:43 AM
Follow-up of this issue. I thought that the issue was only on SPI2 and that the speed of the pin had fixed it. But it happens that I have the same problem whatever speed is set and also on SPI1.
I also reduced the clocks because I noticed that the Nucleos were sometimes not able to switch to VOS1 range. Clock is now 200MHz for sysclk, 50MHz for APB and 12.5 for SPI clock (100MHz for spi_ker_clk and prescaler at 8).
The problem is always during communication from Slave to Master. Sometimes I receive only 0s.
The MISO pin at slave side is setup in push-pull. For the MISO pin at master side, I tried pulldown, pullup or none and I have the same behaviour. Someone suggested to add an extra pullup but I don't have any electronics parts to do so.
I recorded traces with a scope and I am not able to analyse them. I logged both SCK and MISO, once at slave side, once at master side. So the only difference between both traces is around 10cm of wires (obviously I tried several wires).
Output from Slave. You see that MISO (in yellow) is relatively clean and I checked that the bits are correct.
Input at Master side:
Do you understand the differences between the traces ?
Also what is strange is that the Master SPI interpretates this signal as only zeros (I've checked phase and polarity)
I'm really surprised because I have often worked with SPI on Nucleos and usually I didn't have any issue (at least at small frequencies and for short amount of data).
2020-05-28 05:03 AM
> I recorded traces with a scope and I am not able to analyse them. I logged both SCK and MISO, once at slave side, once at master side. So the only difference between both traces is around 10cm of wires (obviously I tried several wires).
The lower one clearly goes into hi-Z mode before SCK is done. If you're expecting the slave to be driving the signal at that time, it's not. Review the datasheet to see why.
This isn't a clock or pullup/down issue. The problem is the slave is not driving the line during the entire communication. Probably because it thinks it isn't supposed to, or is finished sending, or something.
2020-05-28 05:13 AM
But the trace recorded at slave side is showing a clean signal isn't it ? Isn't it strange ?
2020-05-28 05:19 AM
> But the trace recorded at slave side is showing a clean signal isn't it ? Isn't it strange ?
For the trace you recorded, yes. You're not saying these two are the same exact signal recorded simultaneously at different locations on the wire, are you? I would not believe that.
2020-05-28 05:29 AM
Simultaneously no. I hadn't enough probes to do so. However I recorded several times at each location on the wire and I had every time the exact same trace.
2020-05-29 08:10 AM
So I twisted every signal of SPI with a ground signal and it fixed my instabilities on SPI1.
However I still had issues on SPI2. I noticed that in the user manual of Nucleo 144 board , the functions of the pin PC2 that I was using for SPI2_MISO is only ADC, not SPI2_MISO. But in the datasheet of STM32H743ZI SPI2_MISO is indeed an altrenate function of pin PC2.
So I switched to SPI3 and now I don't have the issue anymore. To be honest I'm not sure yet whether it is just luck or if there si a subtelty of Nucleo pin mapping (for me I should be able to use all alternate functions of a pin that is accessible on the Nucleo ?)