Maximum SPI clock

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

Hi guys may I ask what is the maximum allowed speed for the SPI of the master MCU.

I connected 2 MCUs with the master as ATMEGA2560 and slave as ATMEGA 328P. The master has 16MHz clock frequency while the slave has 1MHz clock frequency. Initially I set SPR0 to divide fosc with 16 to set the master clock. Then I found out it is not working so I tried to change the divider to 128. After that I got a good result. May I ask what are considerations in setting the clock divider. Thank you.

This topic has a solution.
Last Edited: Tue. Jun 23, 2020 - 01:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What does the datasheet say?

 

How do you know that it was actually the SPI clock rate that was the problem?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The SPI master clock must be no faster than 1/4 of the AVR SPI slave CPU clock frequency.

 

1MHz slave CPU clock divided by 4 gives 250KHz. So, to reach this, a 16MHz master must have an SPI prescale of at least 16MHz/250KHz = 64. Using 128 satisfies that criterion.

 

Jim

 

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

 

 

Last Edited: Mon. Jun 22, 2020 - 05:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

May I ask what are considerations in setting the clock divider. 

Solid wiring & proper bypassing are critical, these are high speed signals and need treated as such! 

Are the chips 2 inches apart or 2 miles apart?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

Thank you for the detailed explanation.

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

avrcandies wrote:

May I ask what are considerations in setting the clock divider. 

Solid wiring & proper bypassing are critical, these are high speed signals and need treated as such! 

Are the chips 2 inches apart or 2 miles apart?

They are few inches apart. Thanks for the hint.