SPI.setClockDivider() in Arduino Duemilanove

Hello, I have an Arduino Duemilanove and I want to send data through SPI to another microcontroller. The crystal of the Arduino is 16MHz and I want the data on SPI to be sent over this frequency(16MHz). My question is what value should I put on SPI.setClockDivider() ??? Thank you!

There is no such divider. The fastest is divide by 2 (8 MHz).

http://www.gammon.com.au/spi

So If the one microcontroller runs in 8MHz and the other runs in 16MHz, how we send data through SPI?

No problem at all. SPI has a clock (SCK). The slave just uses the master clock speed. Just use the clock speed that suits both.

So I can have the master microcontroller in 8 MHz and the Slave in 16MHz?

The clock rate does not need to be set on the slave - setClockDivider() serves no purpose on the slave board. The slave's SCK is an input and this signal comes from the master where the SCK is an output. If the master SCK is 8MHz, then the slave will also be 8MHz.

Thank you!

So If I want to transfer data between 2 microcontrollers, that each one has different clock frequency, is there any other method that works?

What other method? Just choose a frequency they can both handle. For example SPI_CLOCK_DIV8.

By other method do you mean I2C? Serial? There are lots of ways of transferring data.

What is wrong with using SPI? Don’t you think it will work?

[quote author=Nick Gammon link=msg=2150978 date=1426973949] What other method? Just choose a frequency they can both handle. For example SPI_CLOCK_DIV8.

By other method do you mean I2C? Serial? There are lots of ways of transferring data.

What is wrong with using SPI? Don't you think it will work? [/quote]

I understood my mistake! Thank you!

I managed to make both work at 8 MHz. The problem now by using SPI, is that Master sends irrelevant characters to the Slave end!! What is wrong???

You want to know what is wrong in the code you haven't posted, is that it?

How to use this forum