Author Topic: ST 32F417: any way to poll a SPI device via DMA and interrupt on a data value?  (Read 1177 times)

0 Members and 1 Guest are viewing this topic.

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3669
  • Country: gb
  • Doing electronics since the 1960s...
I don't see any way to do this but perhaps someone might know of some cunning trick.

The chip does have some curious features like the ADC can run continuously and interrupt when the input voltage is outside a window.

What I would like to do is set up a timer to trigger a DMA read of an SPI peripheral, at 125kHz (SPI clock can be up to 5.5MHz on the said device), to a constant memory address. That is definitely possible.

But I would also like to interrupt, or detect in some way which doesn't involve the CPU while looking for it, if the byte received is not 0xFF. Most of the bytes are 0xFF and this signifies "got no data".

The background to this is here
https://www.eevblog.com/forum/projects/anyone-using-the-u-blox-neo-m9n-gps/
and I have got it running in software, polling the SPI.

Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4208
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
<hack>

Set up an EXTI interrupt on SPI MISO, to interrupt on falling edges.

In the ISR, ensure the SPI transfer is complete, then check and act upon the most recently received data, which you now know contains at least one zero.

Won't work if SPI MISO doesn't stay high all the time, ie. if it goes low when CS is not asserted (use a pull-up), or if it's driven low during the interval between CS going low and the first active clock edge on SCK.

</hack>
 
The following users thanked this post: voltsandjolts, peter-h

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3669
  • Country: gb
  • Doing electronics since the 1960s...
That's very clever - thanks :)

Yes one would to gate MISO with CS so if CS=1 MISO=1.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3669
  • Country: gb
  • Doing electronics since the 1960s...
I am wondering if one could direct the received SPI data to some fixed address which happens to be a peripheral which interrupts if it sees non-FF, perhaps as a side effect. Maybe a capture register on some timer.

It is fairly obvious this can be arranged with some value (e.g. a value which starts a timer whose compare register is set to 1 so it interrupts immediately) but not so obvious doing it with a non-FF.

For detecting equality to FF, there may well be a timer mode where loading a byte of FF would trigger a compare match and thus an interrupt? Most of the timers are 16 or 32 bit compare types so one would need to preload the other half with FF.

A truly horrid hack would be to use the ADC window interrupt feature, with the ADC input suitably tied to some voltage, and rigged so that any value less than FF creates the interrupting condition.

And there may be a clue: looking for non-FF, one is really looking for any value smaller than FF. That might be a way to use a timer compare reg.
« Last Edit: May 20, 2022, 08:47:08 pm by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Online uer166

  • Frequent Contributor
  • **
  • Posts: 872
  • Country: us
Another hack idea: IIRC the USART peripheral has some address decode logic. Maybe DMA from the SPI input, into a USART TX, which loop-backs back to RX, which can then use the USART facilities. Would be a hack of the century if it works.
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3669
  • Country: gb
  • Doing electronics since the 1960s...
Hmmm thanks I will look into that one also :)

I wonder if one can also use a USART which doesn't come out on any pin (because you had no pins left).
« Last Edit: May 21, 2022, 06:01:10 am by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4208
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Yes one would to gate MISO with CS so if CS=1 MISO=1.

If you're using a timer to trigger a DMA transfer, does that actually allow for control of CS?

Some STM32 devices have a very limited hardware NSS feature, which I've never found useful. I always end up controlling CS in software - in which case you may as well have a timer interrupt which asserts CS, performs the SPI transfer, negates CS and then checks the value of the returned data before exiting.

This does have a performance impact, of course, but it's much more flexible and maintainable than a hardware hack.

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 3669
  • Country: gb
  • Doing electronics since the 1960s...
Actually yes you are absolutely right; /CS cannot be done using the chip alone (NSS) unless there are no other SPI slaves connected, and even then you have no control over the two CS timing periods.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf