cancel
Showing results for 
Search instead for 
Did you mean: 

Fast output of a data stream via GPIOs or SPI with 2MHz

MBran.21
Associate II

Hello everyone,

I currently have a problem where I am not sure about the implementation. I have to control a driver module, which has a serial interface.

The problem is that it needs a LATCH line in addition to clock and data line. So far so good. But I have to set the LATCH line to high at certain points so that the driver recognizes it as a data stream or command stream.

With a SPI I realized it, but only in so far that I set the clock of the SPI to an external interrupt, count the clocks and then set the LATCH to High/Low accordingly (only works with 180MHz clock and 1MHz SPI clock, but I want a faster SPI clock. Alternatively I clocked it by hand, so set Clock, Data and LATCH for my whole data stream by hand.

Now the question: Is there a nice way to do this as efficiently as possible?

7 REPLIES 7

Which STM32?

Use timer(s).

Probably the easiest way is to generate both SCK and LATCH from two or three mutually coupled timers, connect SCK (and maybe LATCh too, if it can be used as NSS) externally to SPI and use SPI in slave mode.

JW

MBran.21
Associate II

Sorry, i forgot this. I want to use a STM32F100, alternatively a STM32L151

i don't quite understand how i can generate the LATCH signal with one (or more) timers. Can you explain this in more detail? (I need yes, say 47 bars LATCH Low, then one bar LATCH High, etc.) And if I have a command: 45 bars LATCH Low, then three bars LATCH High, etc.

What do you mean by "bar"?

JW

MBran.21
Associate II

bars = tacts = beats

TDK
Guru

You could use a separate SPI peripheral acting in slave mode to generate the LATCH signal. Clock it with the master SPI clock. Set it to put out circular DMA data and change the last byte based on if you're sending a command or data.

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

Thanks for your reply. That sounds promising. I just tried this, but now i have the problem with the SPI clocks. I have the SPI1 as master and the SPI2 as slave. I connect the clocks externally. Unfortunately I have no signal on the clock line after connecting the clocks.

Any idea, what the problem could be?

Read out the SPI registers and check they are set as expected i.e. one of them as slave. If yes, read our and check the respective GPIO and AFIO registers.

JW