2014-09-22 05:38 AM
Hi all!
I am running a 3 MCU solution were all MCU:s are communicating 21MHz full duplex SPI to eachother. As: MCU1 SPI3 Master <-> MCU2 SPI3 Slave MCU1 SPI2 Master <-> MCU3 SPI2 Slave MCU2 SPI2 Master <-> MCU3 SPI1 Slave. The SPI data transfers are with DMA and most of the time it works very well. Communication between MCU1 <-> MCU2 and MCU1 <-> MCU3 starts almost at the same time, and MCU2 <-> MCU3 starts when half the MCU1 <-> MCU2 traffic is finished (half buffer interrupt) and the data between MCU2 <-> MCU3 is approx. half the size so all traffic will end approx. at the same time. The traffic cycle repeats every 5 ms. But at random occations, a peak pulse about half a bittime (or half CLK period) is emerging on the SPI3 MISO on the MCU1 <-> MCU2 SPI. This pulse is in phase with the CLK signal on the MCU1 <-> MCU3 SPI. The amplitude is the same as a normal signal. It's like the CLK signal from SPI2 is fed out on SPI3 MISO pin for a very short time but I cannot see that PC11 signals or PB13 can be cross connected somehow. The upper signal in the attached photo is the SPI3 MISO signal, and the lower wave is the SPI2 CLK signal. The error peak is second from the end in the upper wave. It differs compared to the other pulses in the upper wave. The last pulse in the upper wave is the last bits of SPI3 MISO transaction. The SPI2 (CLK signal on lower wave) ends a couple of bytes later... How is this possible? The similarities between the error pulse in the upper MISO wave and the lower CLK wave, when it comes to amplitude and phase, are so big that I almost can exclude other disturbance sources on the board. Do anyone know any sensitive parts in code to take into notice, as when clearing ISR flags or something? Kind regards #stm32f407-spi-dma2014-09-22 07:02 AM
Stop searching a software issue, you have a serious electrical problem. No SPI clock or data shall looks like in your picture.
At 21MHz, it is easy to get MUC to communicate when they are on the same PCB. In your case, I guess that you use separate PCB, with long wires, probably not very well grounded, connectors etc ... no wonder that it does not work well. Tell us more about your test conditions. Is this possible to run a test at lowaer speed ? Say 2Mbit max.2014-09-23 12:18 AM
Suddently I realized that yuor HW problem is possibly that you *over-zoomed* into your scope trace, leaving so few acquired points to draw the trace that the scope interpolated into those stranges pseudo-sinusoidal curves.
In such a case, try to get a trace using delayed trigger, or anything else. Then we can draw conclusion about what's wrong, HW or SW.2014-09-23 02:37 AM
Hi and thank you for the answers.
First, the headline is wrong. It shall say SPI3 not SPI8 =). Yea sorry for the poor trace. I shall try get an other one. I just manage to trig an error and I can now see that this time the error pulse emerged after the SPI2 CLK has ended! So it seams as the error pulse has less to do with the CLK signal on the other SPI interface. It is very strange though, that even if most of the bytes are 0x00 (buffer size 1500 Bytes) except in the beginning, in the middle and in the end of the buffer, the error emerges inside or close to the shunks of data. I have not seen the error while just sending zeros. The MCUs are located ~40mm from eachother in a line, with MCU1 in the middle and MCU2 below MCU1. All on the same PCB. I have tested to run at 10 MHz and I have not seen this problems at that speed. BR2014-09-24 12:28 AM
I have a 100us timer TMR2 that generates interrupts periodically. Its interrupt priority is the lowest among all other IRQ:s. The ISR does some simple variable tick-up and ofcource clears the IRQ flag for the timer.
Further tests shows that disabeling the TMR2 IRQ on MCU2 makes the error pulse disappear. I have not yet done an overnight test, but so far it runs without hickups. How can TMR2 IRQ influence the SPI3 MISO signal? No register settings are done in the IRQ except clearing the IRQ flag ofcource. BR2014-09-24 12:48 AM
It is really hard to give any useful answer without seeing any proper signal trace or code.
Generally speaking, having a fast source of interrupt, increase chances to space consecutive statements. Normally this shall increase occurrence of bugs, in particular for (quasi-)atomic operations that requires to perform several tasks in a short time frame. I your case this is the opposite, for sure there is an explanation, but we are not aware of enough details to answer precisely.2014-09-24 04:18 AM
I have attached a new scope image taken with 20ns/div. I.e. not much zoom. The error pulse is the first positive pulse in the image.
I did not get eny more errors when disabeling the TMR2 IRQ. I also tried enable the IRQ again and remove all code, except clearing flag, from the ISR. Then the error came back. My current test is to switch timer from TMR2 to TMR10 instead, and keep all code as is. Just a timer change. I selected TMR10 because is uses a different clock source compared to SPI3. I will let it go over night and see the progress tomorrow. So far it looks good, to be continued... All the above information is related to MCU2 only. ________________ Attachments : IMAG0194.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0WF&d=%2Fa%2F0X0000000bdH%2FPMrLJeWrh5.g4CgoNarkTyKcSVM61R0J8echmxJpZZo&asPdf=false2014-09-24 05:26 AM
The good news is that I misread your test with timer, and now it appears more clear that your handling of SPI is wrong. When a fast interrupt increases the occurrences of this half bit, it means that you managed something with the assumption that 2, 3 or more operation are done very quickly in a row. When the interrupt inserts itself into this flow, the bug appears.
Having half a bit can be caused by a lot of thing. This could be an electrical conflict between master and slave. This could be a stop operation that effectively stop a bit too late. Etc...2014-09-24 12:29 PM
2014-09-24 10:00 PM