Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ATTinyx61support #39

Open
astro59 opened this issue May 16, 2021 · 18 comments
Open

Add ATTinyx61support #39

astro59 opened this issue May 16, 2021 · 18 comments

Comments

@astro59
Copy link

astro59 commented May 16, 2021

Is it possible to use PinChangeInterrupt with ATTiny861 ?

@NicoHood
Copy link
Owner

Not yet, but I can add support for it, if you like. It seems to support PCINT on all pins:
http://ww1.microchip.com/downloads/en/devicedoc/atmel-2588-8-bit-avr-microcontrollers-tinyavr-attiny261-attiny461-attiny861_datasheet.pdf

@astro59
Copy link
Author

astro59 commented May 18, 2021

Yes, I like it. I will be happy to test this on my project. I need a lot of independent pins, a few of which are interrupts.

@NicoHood
Copy link
Owner

I accidentally commited the changes directly to master, without a PR. The commit is this one:
ca4fe2e

Please test and report if it works. Please test all pins (not just a few), if possible.

@NicoHood
Copy link
Owner

I've just released 1.2.9. Please test if that works for you. I expect that this should be an easy one and just work. If not, I will try to fix it ASAP.

@astro59
Copy link
Author

astro59 commented May 18, 2021 via email

@NicoHood
Copy link
Owner

I cannot see a photo. Please paste your source, if possible.

This is the example to use for testing:
https://github.com/NicoHood/PinChangeInterrupt/blob/master/examples/PinChangeInterrupt_Led/PinChangeInterrupt_Led.ino

@astro59
Copy link
Author

astro59 commented May 19, 2021

#include <PinChangeInterrupt.h>
#include <PinChangeInterruptBoards.h>
#include <PinChangeInterruptPins.h>
#include <PinChangeInterruptSettings.h>

// ATMEL ATTINY 261/461/861 et 261V/461V/861V  -  BRANCHEMENTS

// Choose a valid PinChangeInterrupt pin of your Arduino board
#define pinBlink 4
#define pinLED   11

void setup() {
  // set pin to input with a pullup, led to output
  pinMode(pinBlink, INPUT_PULLUP);
  pinMode(pinLED, OUTPUT);

  // Manually blink once to test if LED is functional
  blinkLed();
  delay(1000);
  blinkLed();

  // Attach the new PinChangeInterrupt and enable event function below
  attachPCINT(digitalPinToPCINT(pinBlink), blinkLed, CHANGE);
}

void blinkLed() {
  // Switch Led state
  digitalWrite(pinLED, !digitalRead(pinLED));
}

void loop() {
  // Nothing to do here
}

`

@astro59
Copy link
Author

astro59 commented May 19, 2021

Oups !

for this the button is on physical pin 14 and led on physical pin 4
I have tested other configurations.

@astro59
Copy link
Author

astro59 commented May 19, 2021

@NicoHood
Copy link
Owner

NicoHood commented May 19, 2021

Can you check what digitalPinToPCINT(pinBlink) returns (it should return 4)? As an alternative you could use for physical pin14/PA4/D4/PCINT4:
attachPCINT(PCINT4, blinkLed, CHANGE);

Can you also check if a normal digitalread on the button pin works?

Which attiny core do you use? For example there are two versions for digital pins in this core:
https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/variants/tinyX61_New/pins_arduino.h#L173
https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/variants/tinyX61/pins_arduino.h#L189

@NicoHood NicoHood changed the title Ajout ATTinyx61 Add ATTinyx61support May 19, 2021
@astro59
Copy link
Author

astro59 commented May 19, 2021

I have to go
I'm doing this tonight when I get home

@astro59
Copy link
Author

astro59 commented May 19, 2021

IDE 1.8.13
ATTinyCore Spence Konde 1.5.2
Apparently C:\ ... \Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\variants\tinyX61_New\pins_arduino.h

Tested with 4, PA4 and PCINT4
Start up the led lights up for 1 second
Pin 14 (PCINT4) : Button released 5V - Button pressed 0V - No réaction

in digital mode, all is OK

@NicoHood
Copy link
Owner

NicoHood commented May 20, 2021

What does digitalPinToPCINT(4) return?

@astro59
Copy link
Author

astro59 commented May 20, 2021

I don't know.
how i do that?

@NicoHood
Copy link
Owner

Something like:

if (digitalPinToPCINT(4) == 4){
led on
}

if it is not true, please check against -1 or try & error all other numbers.

@tredpath
Copy link

digitalPinToPCINT(0) == 1
digitalPinToPCINT(1) == 2
digitalPinToPCINT(2) == 4
digitalPinToPCINT(3) == 8
digitalPinToPCINT(4) == 16
digitalPinToPCINT(5) == 32
digitalPinToPCINT(6) == 64
digitalPinToPCINT(7) == 128
digitalPinToPCINT(8) == 9
digitalPinToPCINT(9) == 10
digitalPinToPCINT(10) == 12
digitalPinToPCINT(11) == 16
digitalPinToPCINT(12) == 24
digitalPinToPCINT(13) == 40
digitalPinToPCINT(14) == 72
digitalPinToPCINT(15) == 136

There aren't separate interrupt vectors for each port either. ISR(PCINT_vect) covers everything (see table 9-1 in the datasheet for the list of interrupt vectors).

@NicoHood
Copy link
Owner

NicoHood commented Jul 9, 2021

Great progress on your PR so far! I want to note, that we need to also identify the root cause of the invalid digitalPinToPCINT() mappings.

@NicoHood
Copy link
Owner

NicoHood commented Jul 9, 2021

Which Core are you using to support this attiny? I need to check if they defined every marco correct.

#define digitalPinToPinChangeInterrupt(p) (digitalPinToPCICR(p) ? ((8 * (digitalPinToPCICRbit(p) - PCIE0)) + digitalPinToPCMSKbit(p)) : NOT_AN_INTERRUPT)

Edit:
I've opened an issue (with suggested fix) here:
SpenceKonde/ATTinyCore#589

It would be nice if you can test that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants