Skip to main content
st239955_stm1_stmicro_com
Associate III
October 8, 2014
Question

Stm32 Spi Slave - How to detect Chip Select Edges?

  • October 8, 2014
  • 6 replies
  • 2112 views
Posted on October 09, 2014 at 00:36

Using:

  • Stm32F10x, F2xx, F4xx
  • gcc-arm-none-eabi-4_8-2014q2

On my Stm32, I've running a spi slave and serving events (RX/TX) within an ISR.

Slave select management is configured to hardware:

    ...

    spiInitStruct.SPI_Mode = SPI_Mode_Slave;

    spiInitStruct.SPI_NSS = SPI_NSS_Hard;

    ...

This works fine so far. My ISR is called in case of RXNE and TXE events.

Now, I wan't also to be notified each time the chip select goes active or inactive.

Would that also be handled over the spi module (same ISR) or do I have to setup the chip select pin (e.g. GPIOB, GPIO_Pin_12 for SPI2) for interrupt handling with an additional ISR (and if so, how to do this)?

#ssi #spi #stm32
This topic has been closed for replies.

6 replies

Tesla DeLorean
Guru
October 8, 2014
Posted on October 09, 2014 at 00:54

Don't know, EXTI?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
st239955_stm1_stmicro_com
Associate III
October 8, 2014
Posted on October 09, 2014 at 01:00

Does this mean, that I definitively must configure the chip select input for interrupt and set up an additional ISR?

Tesla DeLorean
Guru
October 8, 2014
Posted on October 09, 2014 at 01:16

It means I don't know....

The Hard NSS suggests a gating to cause the RXNE N-cycles into the transaction, ie slave accepting input based on a low -CS

If you want to get close and personal with the edges of the -CS pin, then I think you're going to have to use an EXTI based method to achieve that. It's not something I have tried, or plan on trying.
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
st239955_stm1_stmicro_com
Associate III
October 9, 2014
Posted on October 09, 2014 at 06:15

Ok, I got it working using EXTI for now.

Unfortulately, because of SPI2's select is on PB12, there is no EXTI12_IRQn but I have to use EXTI15_10_IRQn instead.

Btw: I'm mainly interested if the chipselect has been deactivated between calls of my SPI2_IRQHandler(). So I don't really need a ISR call for every chipselect edge.

For this I'd now tried to work without EXTI15_10_IRQHandler(). Using EXTI_Mode_Event instead of EXTI_Mode_Interrupt and hoping that I could check some kind of »event bit« inside of my SPI2_IRQHandler().

But in the case of using EXTI_Mode_Event, there seems no event bit which I could read out (I'd also checked out

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/DM00031020.pdf

, pages 381 ff.).

Well, I could use EXTI_Mode_Interrupt and simply not enable the related EXTI15_10_IRQn. Now I can check EXTI_GetITStatus(EXTI_Line12) (and clear pending bit afterwards) and this works as expected.

But there's also a disadvantage: If I later want to use e.g. EXTI_Line11 for calling an isr, this isr will also called every time a transition occours on my chipselect line (permanently if the pending bit was not cleared inside of the isr). So, it seems to be a bad idea to do such things.

http://lmgtfy.com/?q=EXTI_Mode_Event

brings quite less helpful results and there are also no code examples inside of the standard peripheral library. My impression is, that EXTI_Mode_Event was only for waking up the Stm32 from sleep mode - nothing more or less. No way to check if such an event has been occoured or not (isn't it?).
waclawek.jan
Super User
October 9, 2014
Posted on October 09, 2014 at 10:56

PB12 is TIM1_BKIN and I2C2_SMBA, both should be usable as interrupt sources if those peripherals are unused. I admit that it's an unorthodox solution and there may be bumps ahead.

JW

st239955_stm1_stmicro_com
Associate III
October 9, 2014
Posted on October 09, 2014 at 14:52

> … it's an unorthodox solution and there may be bumps ahead.

Within my application, the edges of the chip select are indicators for start and end of a transmission of a bunch of data. I think it's very common to use a chip select activation as some kind of »transmission start« when communicate over SPI.

May you know a better solution to detect chip select transitions between SPI2_IRQHandler() calls?