0
\$\begingroup\$

I want to use an atmega328p with nrf24l01 + wireless module and communicate it with an arduino nano with nrf24l01 +.

My question is this, if I use different frequencies in the microcontrollers, will there be a problem?

Arduino nano goes to 16MHz and the atmega328p I want to put 8Mhz internal or external or maybe 12MHz since I feed it with a battery to [4-3] V.

\$\endgroup\$
  • 2
    \$\begingroup\$ Not as long as it supports the clock frequency. The code written for 16MHz may not exactly work as desire or sometime is absolutely broken for 8MHz if the CPU Frequency has not be handled properly in code. \$\endgroup\$ – MaNyYaCk Nov 19 '18 at 12:13
0
\$\begingroup\$

The nrf24l01 SPI clock frequency is limited to 8 MHz (the max on-air data rate is 2 MHz). If you are using hardware SPI, there is a divider that can be used to set the SPI frequency to a fraction of the processor frequency (CPHA register if you are programming registers directly, setClockDivider() in Arduino) allowing you to run the SPI clock at a lower frequency than the processor.

\$\endgroup\$
  • \$\begingroup\$ It is not assumed that when configuring the microcontroller in the bootloader with the frequency that one chooses, the SPI should be configured as well? \$\endgroup\$ – Wave Wolf Nov 19 '18 at 12:37
  • 1
    \$\begingroup\$ Programs should not assume pre-configuration by a bootloader. \$\endgroup\$ – Chris Stratton Nov 19 '18 at 13:49
  • \$\begingroup\$ This issue is relatively moot anyway; the maximum SPI clock rate for an ATmega is half the oscillator frequency (there is an implicit division in how it is built, in additional to the optional one you can set). So only at speeds greater than 16 MHz (ie, running the ATmega at 20 MHz) would the stated SPI clock limit for the radio be violated. In the Arduino world one does not need to worry about this with either of the stock clock choices of 16 MHz or 8 MHz. \$\endgroup\$ – Chris Stratton Nov 19 '18 at 14:52
  • \$\begingroup\$ I have managed to communicate atmega328p with 8 internal Mhz with an arduino MEGA with the configuration: SPI.beginTransaction (SPISettings (4000000, MSBFIRST, SPI_MODE0)); My question is the following, in what sense would improve the speed of 4000000 to 8000000 for example? \$\endgroup\$ – Wave Wolf Nov 19 '18 at 14:59
0
\$\begingroup\$

While it has been claimed that the nRF24 chips have an SPI clock limit of 8 MHz, in practice this will not be an issue with an Arduino board at either stock clock frequency (8 MHz or 16 MHz), because the ATmega's SPI clock rate is limited to half of the chip's oscillator frequency to begin with.

You can optionally configure at ATmega to further divide the SPI clock, but the minimum divisor is 2 as a result of how the peripheral engine itself is built (such a division is common to most MCUs).

In theory, if one were operating an ATmega at 20 MHz which is close to the limit of its specification, then the SPI clock could be as high as 10 MHz which might be out of spec.

But at that point one should perhaps consider that many of the items sold as nRF24 chips are actually mislabeled work-alikes from different vendors.

What is perhaps most important for the purposes of the question is that the SPI clock has no relation to the air data rate. You can use a fast SPI clock to load up data for a slow air data rate, or you can use a fast air data rate and read out the result with a slow bit-bang SPI implementation. It is the air data rate and related settings which must match between transmitter and receiver - the SPI only needs to get the radio into the right mode (especially on the right frequency) at the right time to coordinate with the other end.

Further, these radios are not designed for a high duty cycle. Typically the time between packets would be long compared to the duration of a packet. So there should be plenty of time to write in the data and read it out. If you're trying to move high volumes of data, you're probably using the wrong radio solution - not to mention the wrong MCUs. These chips were meant for things like wireless mice and keyboards, then re-purposed for the control side of RC toys; if you want something more like WIFI, then that is what you should be using.

\$\endgroup\$
  • \$\begingroup\$ The information I need to send is very small. I just wanted to make sure that microcontrollers with different frequencies (transmitter and receiver) could be used to establish a communication with the nrf24l01 + modules. My doubt was that by having two different frequencies in the microcontrollers, the modules would not be able to establish communication. Thanks \$\endgroup\$ – Wave Wolf Nov 20 '18 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.