cancel
Showing results for 
Search instead for 
Did you mean: 

spi slave weird data on mid-high speeds ?!

arhi
Associate III

I am having weird issue with STM32F767 (configured to run at 200mhz) that needs to be SPI slave .. I configured it with 0,1 (clock low, second edge), hardware cs.. when master sends data at 350kbps everything is ok, when master sends at higher speeds output is random (like bits are swallowed).

code is super simple just hal_spi_transmitreceive() in a loop sending 2 same bytes non stop

it behaves like hardware can't catch up and start sending data late and slower than the clock...

24 REPLIES 24
TDK
Guru

Consider what it's connected to, the limitations of that device, and the limitations of the connections.

Long lengths of wire will not support 200 MHz. Heck, even short lengths may struggle at those speeds.

Ensure pins are set to the highest frequency speed.

Consider putting a logic analyzer or oscilloscope on the pins to ensure signal integrity is sufficient.

If you feel a post has answered your question, please click "Accept as Solution".
arhi
Associate III

I'm looking at the https://community.st.com/t5/stm32-mcus-products/slave-spi-on-stm32f4-receives-incorrect-data/m-p/601574#M225721 and it looks like similar issue ...

200MHz is the mcu clock, I'm running SPI much slower ... attm 333kbps works ok, 666 "mostly ok" but 1.2mhz and 2.3MHz are totally messed up ... there is ADUM isolator between MCU and the MASTER device, and wires are .. ratsnest attm... LA is what I'm looking at now and it showing me these wrong data SLAVE (mcu) is sending, I'll attach a scope to the lines to see what's going on with clock on both sides of the ADUM ... ADUM should be good up to 90MHz but...

arhi
Associate III

This is making less and less sense ...

code is rather simple:

 

...
tx_data[0] = 0xf7;
tx_data[1] = 0x7f;
tx_data[2] = 0;
tx_data[3] = 0;
for(;;) HAL_SPI_TransmitReceive(&hspi1, tx_data, rx_data, 2, 100);

...
static void MX_SPI1_Init(void) {   
   hspi1.Instance = SPI1;
   hspi1.Init.Mode = SPI_MODE_SLAVE;
   hspi1.Init.Direction = SPI_DIRECTION_2LINES;
   hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
   hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
   hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
   hspi1.Init.NSS = SPI_NSS_HARD_INPUT;
   hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
   hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
   hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
   hspi1.Init.CRCPolynomial = 7;
   hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
   hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
   if (HAL_SPI_Init(&hspi1) != HAL_OK)   {     Error_Handler();   }
}

 

So I should see on MISO line 0xF77F non stop.

What I see is same "shape" as 0xF77F only looking at some random clock. here is from LA at two different speeds of the MASTER:

arhi_0-1702164087615.jpegarhi_1-1702164135697.jpeg

and the scope on the clock directly on MCU pin (slave mcu) looks ok, not super perfect but ok

arhi_2-1702164242403.pngarhi_3-1702164259076.png

 

arhi
Associate III

also, connections are rather short, between adum isolator and mcu is maybe 10mm, then after adum I have 5-10cm of wires only... so I doubt it's the issue with wires but I'm open to suggestions banging head with this for days

arhi
Associate III

sending F77F

looking at both 666khz and 1.2mhz I see FF77 .. so first nibble is ?!?!?! then I have ok F77 and then I'm missing a nibble .. like whole word is "nibble late" ?!

CS is properly going up/down as expected and SPI is configured to use HW CS (

hspi1.Init.NSS = SPI_NSS_HARD_INPUT;

 

David Littell
Senior III

A logic analyzer trace starting at the SPI slave's reset negation might show something interesting.

my tip: 

- use a "better" pattern, like : 0xA5A5

+ i have slave spi (over 40cm CAT6 cable for spi + power ) running at 32Mbit ; (sender is a ESP8266)  🙂

If you feel a post has answered your question, please click "Accept as Solution".

not sure I understand "spi slave's reset negation" - can you elaborate?

I tried first with 5555 then aaaa then a5a5 then 5a5a ... this was just to easily see 2 bits and where they are and I see width of the single bit is ok, it just looks like some phantom clock is happening somewhere... if I could somehow output on some gpio pulse every time spi slave sees a clock it would be interesting to see ... the pcb is "terrible ratsnest" but between mcu and adum there's under 10mm and after adum I have few cm so not enough length for issues, also I do not see anything weird or bad on the scope (400mhz bw) ... but even at 400khz I see same %@#$_()^&#U@ .. I used some M4 to play master and slave and it works with same odrive at few mhz no problem over same wires, and I made it master to this 676 and even at 400khz I see this weird data :(