2

My end goal is to read information from an nRF24l01 module connected to my Arduino UNO R3, and generate an interrupt whenever a message is sent to the Arduino.

Now, I have read that for Hardware interrupts, only pins D2 and D3 can be used to generate interrupts. However, while connecting the MISO line, I saw that here it was mentioned that

On some Arduino boards (see table above), pins MOSI, MISO and SCK are the same pins as digital pin 11, 12 and 13, respectively. That is why many tutorials instruct you to hook up the target to these pins.

On every website I have searched, MISO is always connected to 12. Is there any way to change the MISO line from 12 to 3, or will I have to resort to using Pin change interrupts? Another way I can think of to bypass this is to connect D12 to D3, but I'm afraid this may cause complications in the circuit.

10
  • SPI (and all the none-GPIO peripherals) has its own interrupt that you can enable it by setting the SPE bit of the SPI Control Register, and when a data is received an interrupt would be triggered. Search for SPI Slave example or read my blog for the section of SPI Slave .
    – hcheung
    Jun 24, 2023 at 7:14
  • If you are using Arduino Uno (based on ATMega328 chip), it does not support alternative pin for SPI port. On your assumption that " MISO is always connected to 12", this is only true for Arduino board based on ATMega328. For other Arduino Core (e.g. ESP or STM32), or even different MCU(e.g. Arduino Leonardo which is based on ATMega32U4) using the same Arduino AVR Core, this will not be the case.
    – hcheung
    Jun 24, 2023 at 7:15
  • Thanks!That works for me Jun 24, 2023 at 7:31
  • The NRF24L01 itself can optionally generate an interrupt on receiving a message. The pin on the NRF24L01 is marked IRQ where it is broken out on most modules. You can connect this to an external interrupt pin on a Uno or use any pin which configured for a pin change interrupt. I am not sure how far you will get attempting to use MISO for the same purpose. See here for an example: howtomechatronics.com/tutorials/arduino/…
    – 6v6gt
    Jun 24, 2023 at 7:38
  • @6v6gt the IRQ line, in idle state, is HIGH or LOW? I am asking because I want to fill in the last parameter of attachInterrupt(digitalPintoInterrupt(3), func_name, ________) correctly. Jun 24, 2023 at 7:44

2 Answers 2

1

I have read that for Hardware interrupts, only pins D2 and D3 can be used to generate interrupts

The pin-change interrupts, available on all pins of the Arduino Uno, are almost as good. I say "almost" because the only thing you have to do is work out which pin caused the interrupt, which can be trivial if you only set up one pin to generate interrupts.

Is there any way to change the MISO line from 12 to 3,

Not if you used the hardware SPI on the chip. If you use bit-banged SPI you can use any pins.

I did a project for a temperature and humidity sensor, which logs to a SD card (using SPI), and also displays on a 8-digit display (using SPI). For the latter case I used bit-banged SPI, as described there.

I have a page about SPI and also a similar one on Stack Exchange.

My bit-banged SPI code is available here.


I'm not clear about why you don't just use the hardware SPI pins. Is that you want an interrupt when a SPI message arrives? There is a hardware interrupt for just that. See my posts about SPI for more details about that.

8
  • "Is that you want an interrupt when a SPI message arrives?" :My end goal is to read information from an nRF24l01 module connected to my Arduino UNO R3, and generate an interrupt whenever a message is sent to the Arduino. So yeah, that's exactly what I'm looking for. Jun 24, 2023 at 7:45
  • Actually I've never used bit-banging before, so I will just dive a bit more into the topic. Thanks for the resources. Jun 24, 2023 at 7:46
  • An SPI interrupt would seem to meet your requirements, no need to muck around trying to generate a different sort of interrupt.
    – Nick Gammon
    Jun 24, 2023 at 7:53
  • Thanks, Nick, for the help. Jun 24, 2023 at 7:55
  • Nick, a SPI slave can only send data if requested by the master. so if polling SPI in master is not good enough, there must be some other way for the slave to signal to master that it should do a request.
    – Juraj
    Jun 24, 2023 at 9:37
1

My second answer ...

Your question, in bold, is a good example of an XY Problem. You asked:

Is there any way to change the MISO line from 12 to 3, or will I have to resort to using Pin change interrupts?

This is the X question. However the Y question is your goal:

My end goal is to read information from an nRF24l01 module connected to my Arduino UNO ...

I answered, in another answer, first about changing the MISO line from pin 12, and also pointed out that SPI transactions can generate interrupts.

However, as Juraj pointed out in a comment, the Arduino in this case is the master and the nRF24l01 is the slave (from the SPI point of view).

There is no way that a slave can burst into life and generate a message, and hence cause an interrupt. That is the master's job.

As I read on this page about the module it has an IRQ pin described thus:

IRQ is an interrupt pin that can notify the master when there is new data to process.

So, your job is simplified, really. You don't need to detect when an SPI transaction starts (the Arduino will start the transaction), you need to connect the IRQ pin to an Arduino pin and detect that data is ready. Simple! Then you can easily use pin 2 or pin 3 if you want to use the "hardware" interrupts rather than the pin-change interrupts. (The pin-change interrupts are hardware interrupts too, though).

1
  • I would say Y is the pseudo-problem which doesn't need a solution (move MISO to interrupt pin). the real problem X is the right use of the IRQ pin
    – Juraj
    Jun 25, 2023 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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