SPI data via DMA corrupt

Thanks for the test. The current signal is just a test to see if the SPI buffer is being transmitted ok. Your scope confirms my findings on the breadboard so that part is good.

Something must be really really wrong with my PCB. I'll try a 3rd PCB and see if that improves things.

Edit, Well now I tested all PCB's and they all have the same issue.
 
Last edited:
There is one other thing thing. If I change the SPI to SPI1.transfer(buffer, sizeof(buffer)); (and remove if(_spiDone)) the code only loops once and crashes after that.
We should probably investigate this. If it's at least reproduceable then the fault can be traced.
 
On “There is one other thing thing. If I change the SPI to SPI1.transfer(buffer, sizeof(buffer)); (and remove if(_spiDone)) the code only loops once and crashes after that.” - as mentioned above, echos on the Teensy SPI clock output AND INPUT pin result in your SPI shift registers clocking in and out way more bits then what you think. The DMA may then dump more than just 2 bytes into your rxBuffer. So it may overwrite memory locations beyond those two bytes - causing a crash.

The PaulStoffregen scope will not show the problem because a) scope input bandwidth is set to just 20 MHz and b) to see the ringing on SCK pin, the time scale should be set to see ~20-50 ns ish periods while signals ring. And of course c) Paul does not connect to JustAUser’s PCBs…
 
Changing the function call to the non-async version of SPI.transfer() removes all usage of DMA, so it's not that.
 
I could run the test again with my scope's fully bandwidth, if anyone wants to see a lot of ringing. But it's probably not a useful test. There's always a lot of ringing on high bandwidth measurements when I use the longer ground clips and breadboard length wires, as you can see in the photo.

Something must be really really wrong with my PCB.

If the design it's a secret, might be worthwhile to show us pictures or screenshot of the layout. Might be a long shot, but maybe we'll see something you missed.

If the traces a long, the 2 things you can do to improve noise are keeping ground as close as possible to the signal traces (an unbroken ground plane right below the traces on a 4 layer board is best) and using 100 ohm resistors close to Teensy for the MOSI and SCK signals, and a 100 ohm resistor close to each device's MISO pin.
 
In post 15 I did share the connector part (that is currently all there is connected to the pins). Today I am going to remove all the protection circuits as well and see if that brings any improvement.

Since I didn't make the PCB design myself I'm also trying to get some more information on the routing. When "ordering" I did specify that these where all higher frequency signals but I'm not convinced that was taken into account correctly.
 
Ok, So I just trashed the zener diodes and fuses (those are now shorts) that where attached to the connector and tested it again.
1773217502784.png


Somehow it now works without issues.

@sicco, Assuming you are on the correct path. Somehow the capacitance of the zener diodes (3V3) causes the SPI to go crazy?!
 
Maybe capacitance from the zener diodes. Note that the zeners are 3.3V and the logic high voltage level is also 3.3V, so already in normal operation these zeners start zenering already - with parasitic capacitance going sky-high.
But you mentioned you also cut out the fuses. With that you maybe isolated the long wire that plugs into connector CN17, and with that you disconnected the echoing transmission line that you had on SCK before?
 
Currently there isn't anything connected to the board. My scope is the only thing connected to CN17, nothing else.
So how long is the SCK wire (PCB track) from Teensy pin to zener? And how long a copper track is GND-Teensy to same zener?
 
So how long is the SCK wire (PCB track) from Teensy pin to zener? And how long a copper track is GND-Teensy to same zener?
About 12 cm. To be honest I don't know since I can't really trace the copper that well. But if I take just a ruler I get that distance.
 
Then you probably have a resonating LC circuit on the SCK line. So not so much an echoing transmission line. Just LC that's ringing.
100pF...
12cm wires = 24 cm wire length = about 1 uH
f0 = just a couple of MHz...
1773224068472.png
 
Back
Top