How to Capture SPI Data Without Affecting the Bus?

Thread Starter

Embededd

Joined Jun 4, 2025
131
I am working with an SPI communication setup where one device acts as the SPI Master and another acts as the SPI Slave.

I want to use a third microcontroller to passively monitor the SPI communication. The SPI signals (SCLK, MOSI, and MISO) are connected to this third MCU. This microcontroller is not communicating on the SPI bus; it only needs to detect the rising edge of the SPI clock (SCLK) and read the MOSI and MISO pin levels at that moment.

My goal is to capture both outgoing (MOSI) and incoming (MISO) data at SCLK rising edges without affecting the existing master–slave communication

What is the correct way to configure the third microcontroller to monitor the SPI bus only by detecting SCLK rising edges?

Should I use on an external interrupt triggered by the rising edge of SCLK to read the MOSI and MISO pins?

Thanks in advance for your guidance.
 

Thread Starter

Embededd

Joined Jun 4, 2025
131
You can use interrupts to trigger on both edges of SCLK.
You need to capture MOSI and MISO on both SCLK edges because you don't know which of the four SPI modes is being used.
But in my case, the SPI communication is confirmed to be working in Mode 0 (CPOL = 0, CPHA = 0).

So I want to configure the third microcontroller in such a way that whenever it detects a rising edge of the SPI clock (SCLK), an interrupt gets triggered, and inside the ISR I will read the MOSI and MISO pin values. The third microcontroller is only monitoring the bus; it is not participating in SPI communication.
 

Futurist

Joined Apr 8, 2025
721
But in my case, the SPI communication is confirmed to be working in Mode 0 (CPOL = 0, CPHA = 0).

So I want to configure the third microcontroller in such a way that whenever it detects a rising edge of the SPI clock (SCLK), an interrupt gets triggered, and inside the ISR I will read the MOSI and MISO pin values. The third microcontroller is only monitoring the bus; it is not participating in SPI communication.
Yes, that's what he's alluding to, if you do know, then fine, do exactly what you just said. Of course your MCU needs to be fast enough to react promptly, whats the clock frequency?
 
Last edited:

John P

Joined Oct 14, 2008
2,051
There is an additional snag, which you might want to guard against, depending on how robust you want your design to be. If the system misses a pulse on the clock line, or somehow adds an extra one, characters will be out of sync forever, and you can't detect it. You'd need to use the SS line from the master to signal the end of a character, or wait for pauses between characters if you can be sure that the bus will sometimes be inactive.

As Mr Chips said, having a processor with 2 SPI ports is the easy way to do this task. These days, you can get an Arduino with an Atmega328PB processor, which has an extra UART and an extra SPI port, and they don't seem to cost any more than the older kind.

Or you can get an interrupt on every clock pulse, but you'd need to check the time taken to get in and out of the interrupt, plus buffer the incoming data during the interrupt, and compare it with the frequency of the SCLK line.
 

Futurist

Joined Apr 8, 2025
721
There is an additional snag, which you might want to guard against, depending on how robust you want your design to be. If the system misses a pulse on the clock line, or somehow adds an extra one, characters will be out of sync forever, and you can't detect it. You'd need to use the SS line from the master to signal the end of a character, or wait for pauses between characters if you can be sure that the bus will sometimes be inactive.

As Mr Chips said, having a processor with 2 SPI ports is the easy way to do this task. These days, you can get an Arduino with an Atmega328PB processor, which has an extra UART and an extra SPI port, and they don't seem to cost any more than the older kind.

Or you can get an interrupt on every clock pulse, but you'd need to check the time taken to get in and out of the interrupt, plus buffer the incoming data during the interrupt, and compare it with the frequency of the SCLK line.
He seemed to be concerned that attaching another slave, purely to listen, might impact the traffic or signals in some way, so I think this is why he's talking about interrupts and stuff. To my knowledge he can just use an SPI peripheral (as you guys just described) in an MCU to do this, very little to be concerned about.
 

Futurist

Joined Apr 8, 2025
721
But in my case, the SPI communication is confirmed to be working in Mode 0 (CPOL = 0, CPHA = 0).

So I want to configure the third microcontroller in such a way that whenever it detects a rising edge of the SPI clock (SCLK), an interrupt gets triggered, and inside the ISR I will read the MOSI and MISO pin values. The third microcontroller is only monitoring the bus; it is not participating in SPI communication.
What these guys advise, is simply connect your other MCU' SPI peripheral as a slave, it will in electronics, do everything you are talking about doing in low level code, doing this is 100% passive, will have no impact on the integrity of the traffic.
 

drjohsmith

Joined Dec 13, 2021
1,563
Or simply use two small MCUs with SPI programmed in slave mode to capture the two streams.
in case its not clear @Embededd

the two spi your using to monitor,

they both share sclk and ncs
one you wire mosi on the master into the mosi input of the slave
second you wire the miso of the master into the mosi of the slave
 

Thread Starter

Embededd

Joined Jun 4, 2025
131
In project, I was asked to monitor the SPI bus between two existing devices. we cannot modify the master or the slave. I was given a separate microcontroller only for monitoring the SPI signals.

something like
1764661505529.png

The requirement given to me is:

  • Configure an external interrupt on the monitoring MCU to detect the rising edge of SCLK.
  • Whenever the interrupt is triggered, inside the ISR I must read the MOSI and MISO pin levels to capture the data at that exact clock edge.
  • I also need to store approximately 1 KB of captured data for later processing.

So my task is to correctly configure the interrupt for SCLK rising edge, sample MOSI/MISO in the ISR, and buffer around 1 KB of the recorded data
 
Last edited:

drjohsmith

Joined Dec 13, 2021
1,563
In project, I was asked to monitor the SPI bus between two existing devices. we cannot modify the master or the slave. I was given a separate microcontroller only for monitoring the SPI signals.

something like
View attachment 359837

The requirement given to me is:

  • Configure an external interrupt on the monitoring MCU to detect the rising edge of SCLK.
  • Whenever the interrupt is triggered, inside the ISR I must read the MOSI and MISO pin levels to capture the data at that exact clock edge.
  • I also need to store approximately 1 KB of captured data for later processing.

So my task is to correctly configure the interrupt for SCLK rising edge, sample MOSI/MISO in the ISR, and buffer around 1 KB of the recorded data
Sounds like someone's micro managed that for you then .
Do what they say.
 

Futurist

Joined Apr 8, 2025
721
In project, I was asked to monitor the SPI bus between two existing devices. we cannot modify the master or the slave. I was given a separate microcontroller only for monitoring the SPI signals.

something like
View attachment 359837

The requirement given to me is:

  • Configure an external interrupt on the monitoring MCU to detect the rising edge of SCLK.
  • Whenever the interrupt is triggered, inside the ISR I must read the MOSI and MISO pin levels to capture the data at that exact clock edge.
  • I also need to store approximately 1 KB of captured data for later processing.

So my task is to correctly configure the interrupt for SCLK rising edge, sample MOSI/MISO in the ISR, and buffer around 1 KB of the recorded data
Is this an educational assignment then? or a professional job related question?
 
Top