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.

  • 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 '23 at 07: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 '23 at 07:15
  • Thanks!That works for me – insipidintegrator Jun 24 '23 at 07: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: https://howtomechatronics.com/tutorials/arduino/arduino-wireless-communication-nrf24l01-tutorial/ – 6v6gt Jun 24 '23 at 07: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. – insipidintegrator Jun 24 '23 at 07:44
  • The IRQ pin is active LOW according to this: https://www.sparkfun.com/datasheets/Components/SMD/nRF24L01Pluss_Preliminary_Product_Specification_v1_0.pdf . I'd use the input pin pullup resistor and look for a falling edge. The pins should be 5v tolerant. You may have to explicitly enable the IRQ pin using the NRF24L01 library: https://nrf24.github.io/RF24/classRF24.html#abf68b9b0c9cd17179e9e144c3e7f9c45 – 6v6gt Jun 24 '23 at 07:52
  • Thanks @6v6gt for the help – insipidintegrator Jun 24 '23 at 07:55
  • If it works as you want, then add an additional answer in the thread saying what you did, It may help someone else. – 6v6gt Jun 24 '23 at 07:57
  • @6v6gt Look, this is why answers are supposed to go in answer boxes. Grrr. I scanned the answers to see if anyone had answered the question about the IRQ pin and saw no such answer. So I typed my own. Then I see your comment above answering the question and mentioning the IRQ pin. And now we have, forum-style, more comments querying how your "answer" works. Please, please use the answer "feature" to answer questions. Then comments under the answer make sense. This isn't a forum. – Nick Gammon Jun 24 '23 at 21:50
  • @nickgammon Yes. Sorry. It was a special case. As you have seen, the OP's question had nothing to do with what he wanted to achieve so an answer would not have matched the question. I had tried to get him to sort it out by adding his own answer based on his own experience of the suggested IRQ method but, alas, that never happened. – 6v6gt Jun 25 '23 at 00:50

2 Answers2

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.

Nick Gammon
  • 38,184
  • 13
  • 65
  • 124
  • "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. – insipidintegrator Jun 24 '23 at 07:45
  • Actually I've never used bit-banging before, so I will just dive a bit more into the topic. Thanks for the resources. – insipidintegrator Jun 24 '23 at 07: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 '23 at 07:53
  • Thanks, Nick, for the help. – insipidintegrator Jun 24 '23 at 07: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 '23 at 09:37
  • @Juraj OK, but in that case the slave won't be doing an unsolicited send. So therefore the slave would be sending a signal using some other pin (eg. "data ready"?) which could be connected to pin 2 or pin 3 for an interrupt. – Nick Gammon Jun 24 '23 at 21:18
  • In the example on the linked page the receiver just polls for a message to appear. – Nick Gammon Jun 24 '23 at 21:22
  • @Juraj Ach, I see we have an XY problem here. I made another answer. This answer is still "good" in the sense that it answers the question in bold asked by the OP. My other answer deals with the Y part of the problem. – Nick Gammon Jun 24 '23 at 21:47
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).

Nick Gammon
  • 38,184
  • 13
  • 65
  • 124
  • 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 '23 at 09:40