cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Communication with Timer to clock the SPI

vbesson
Senior

Hello, 

I am building a time critical application with SPI output communication using DMA circular buffer

I need to output data at a very precise frequency that is a multiple of 0.125 ns. Normally it should be 4us but It would need to be sometime 3.9us or 3.8. 

For the moment I use SPI1 as Master with 64 MHz and a prescaler of 256 to get 4us data pulse.

Quick question: 

Can I use a timer to clock the SPI ? in that case does it mean that I have to change it to slave mode ? Can I init transfer in slave mode and trigger DMA transmit buffer still in circular mode ? 

That way I can define the period if the timer and adjust the output frequency of the SPI clock 

Is there any exemple of this (if it make sens)

Thanks

Vincent 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

> Can I use a timer to clock the SPI ?

Yes, if you connect SCK to timer output externally.

> in that case does it mean that I have to change it to slave mode ?

Yes.

> Can I init transfer in slave mode and trigger DMA transmit buffer still in circular mode ?

Yes, but the SPI Tx won't start upon the DMA transfer. You have to be careful to start DMA before the timer, so that the SPI dta register has been written, i.e. Tx buffer already has the data, at the moment when the clocks start.

You have to manage NSS, too (either external or, probably better, internal).

> Is there any exemple of this 

I don't think so.

JW

View solution in original post

2 REPLIES 2

> Can I use a timer to clock the SPI ?

Yes, if you connect SCK to timer output externally.

> in that case does it mean that I have to change it to slave mode ?

Yes.

> Can I init transfer in slave mode and trigger DMA transmit buffer still in circular mode ?

Yes, but the SPI Tx won't start upon the DMA transfer. You have to be careful to start DMA before the timer, so that the SPI dta register has been written, i.e. Tx buffer already has the data, at the moment when the clocks start.

You have to manage NSS, too (either external or, probably better, internal).

> Is there any exemple of this 

I don't think so.

JW

vbesson
Senior

Thanks Jan, 

This is a bit what I thought, I will give it a try

Vincent