Running SPI at uncommon frequencies

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Freaks,

I am trying to run SPI on Atmega168 at uncommon frequencies like 6MHz,7MHz and so on. How can I do this? Is one way to do this is to bit bang the AVR ports? The other way I was thinking was to use a timer output as the SPI clock so I can adjust the counter to get 6MHz for example. Will this work? The slave will be another AVR so does the slave crystal frequency have to be equal to the master SPI clock frequency (in this case 6MHz)?

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Regular SPI goes at F_CPU/4
You also have the SPI2X bit. And can divide the SPI clock with several dividers.

So with an AVR @ 7MHz, you will have 1.75MHz SPI clock.

I will give you a medal if you can achieve this by bit-banging.

I have never tried, but you can make the USI do many things. a mega168 has a USI doesn't it.

The SPI slave will not mind if you clock it at 1.75MHz or 1.75kHz. It will just follow the Master SCK signal.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The SPI is a synchronous interface by nature (single clock source generated by master only), so the clock frequencies of the master and slave(s) can be totally different.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

npat_avr wrote:
I am trying to run SPI on Atmega168 at uncommon frequencies like 6MHz,7MHz and so on. How can I do this? Is one way to do this is to bit bang the AVR ports? The other way I was thinking was to use a timer output as the SPI clock so I can adjust the counter to get 6MHz for example. Will this work? The slave will be another AVR so does the slave crystal frequency have to be equal to the master SPI clock frequency (in this case 6MHz)?
Using the USART in SPI mode,
you can run SPI at a lot of frequencies.
A more important question is why?
The slave is insensitive to the precise frequency of the SPI clock.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

npat_avr,

You may want to look up the dictionary definition of "synchronous". The whole point of carrying the clock alongside the data is so that it doesn't matter what speed it is. The only requirement is that the bandwidth you achieve is high enough for the desired application. You could put out one SCK pulse every 3 days if you want to run it real slow ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can a slave avr actually receive at those rates?

Quote:

master SPI clock frequency (in this case 6MHz)?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Usually, the max clock rate a slave can handle is 1/2 or 1/4 of its own clock rate. Usually, there is no minimum. Depends on the device.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Usually, the max clock rate a slave can handle is 1/2 or 1/4 of its own clock rate.

Never seen the 1/2 for the slave. When mentioned in the datasheets it is 1/4. Got a model # that can hadle 1/2?

Even if you could receive at that rate what are you going to do with it?