arduino / arduino/ArduinoCore-avr
Arduino nano SPI & INT0
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
I have experienced some problem.
On the Arduino nano Atmega328,
INT0 and SPI can't do their jobs concurrently.
1) I have made the toggle wave (8.3333mSec Period) externally and
input it into the pin 2
2) I have made a test code for that as belows
if I have blocked the code line
//SPCR |= _BV(SPE);
then INT0 interrupt handler "void PCI_ZC1()" called and 8.333mSec period LED Toggling can
be shown by oscilloscope.
but if // is removed.. There is no LED Toggling on Oscilloscope...
Does SPE bit of SPCR determs the INT0 or BUILTIN LED or function digitalWrite()?
```C
-------------------------------------
#define _sclk 13
#define _miso 12
#define _mosi 11
#define _cs 10
#define _dc 9
#define _rst 8
#define ZC1 2
#define ZC2 3
//uint8_t _cs, _dc, _rst, _mosi, _miso, _sclk,
//uint8_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
// volatile uint8_t *mosiport, *clkport, *dcport, *rsport, *csport;
unsigned char state;
//--------------------------------------------------
void INT0_Handler()
{
state=!state;
digitalWrite(LED_BUILTIN,state);
}
//----------------------------------------------
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN,OUTPUT);
pinMode(ZC1,INPUT); //no pullup
attachInterrupt(digitalPinToInterrupt(ZC1),INT0_Handler,CHANGE);
//
pinMode(_rst, OUTPUT);
digitalWrite(_rst, LOW);
pinMode(_dc, OUTPUT);
pinMode(_cs, OUTPUT);
//csport = portOutputRegister(digitalPinToPort(_cs));
//dcport = portOutputRegister(digitalPinToPort(_dc));
//cspinmask = digitalPinToBitMask(_cs);
//dcpinmask = digitalPinToBitMask(_dc);
SPCR |= _BV(MSTR);
//SPCR |= _BV(SPE);
}
void loop() {
// put your main code here, to run repeatedly:
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the sketch's setup(), attachInterrupt(), and SPCR configuration. Reproduce the behavior with SPE commented and uncommented, then trace the AVR interrupt and SPI setup involved; done means identifying whether enabling SPE causes the INT0 failure and documenting a verified cause or required core change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, c
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100