Pages: [1]   Go Down
Author Topic: SCK and CLK in SPI communication  (Read 1276 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to establish communication with a device via SPI with the Arduino Due.

The device is a ATA6870:

The datasheet makes me believe the system requires a system clock CLK of 450-550khz (maximum) and an SCK of half the system clock.

The Due has an 84MHz system clock and the SPI library allows us to divide the clock by 255 maximum. This would give the slowest SPI SCK of approximately 330kHz so in order to meet the half system clock criteria the system clock would need to be 660Hz which is more than its allowed maximum.

I am not confident enough in my knowledge to understand how I can overcome this problem or even if it is in fact a problem!. Any pointers in the right direction would be much appreciated.



Offline Offline
Sr. Member
Karma: 14
Posts: 330
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It would seem to me that you are correct: The SPI clock on the ATA6870 is meant to be up to 250KHz. You cannot get down to 250KHz with the master clock running at 84MHz on the Due. This would require a scale value of 336 but you can't go past 255.

The solution, of course, is to slow the master clock down. Cutting it in half to 42MHz would allow you to set an SPI prescaler of 168 and get the 250KHz you need. Now, it sounds easy to do that but of course the Arduino IDE does not expose any way for you to slow down the master clock. So, you're kind of stuck there. You can directly edit the Arduino core files to make the master clock slower but then you're stuck with a specially modified version of Arduino.

An alternative would be to write a sketch to actually mess with the clock settings. So, your sketch could turn the clock down. The problem with doing that is that every other peripheral will also clock down and this will mess up all of the settings for things like UART. Also, I'll bet that the delay routines expect a constant 84MHz as well. God only knows what other things on the board are expecting the 84MHz and will break if they don't get it. In short, a lot of crap will go south for you in a real hurry.

I wrote all that to reinforce my reason for saying this: your best bet is to find a different battery measuring chip. You really want something that can handle a 1MHz or higher clock so that you can drive it without messing with the main clock frequency.

Pages: [1]   Go Up
Jump to: