Avrdude error could not find usbtiny device 0x2341 0x49 ошибка при записи загрузчика

Hi, I am trying to program an ATtiny85 from Arduino IDE 1.6.9, under Linux (Ubuntu -based machine) after following the indications from there: https://github.com/damellis/attiny - http://highlowtec...

Hi,
I am trying to program an ATtiny85 from Arduino IDE 1.6.9, under Linux (Ubuntu -based machine) after following the indications from there:

  • https://github.com/damellis/attiny
    • — http://highlowtech.org/?p=1695
    • — http://highlowtech.org/?p=1706

The ArduinoISP seems fine: «HeartBeat» LED is glowing non stop.
Trying to push the «blink» code to the ATtiny85 ends with this exact error message:
avrdude: Error: Could not find USBtiny device (0x2341/0x49) while all necessary settings from the menu are set properly (i.e. Board: ATtiny25/45/85 ; Processor: ATtiny85 ; Clock: Internal 1MHz ; Port: /dev/ttyUSB0 ; Porgrammer: ArduinoISP)

Port is /dev/ttyUSB since using an Arduino clone (WaveShare «UNO Plus») with a switch to disable the reset from DTR signal.

I also tried with an Arduino UNO R3 original, same issue: Whatever programmer I select, there is an automatic selection for USBtiny over-riding my selection.
I faced the same issue prior to engage into ATtiny85 development.

Any idea for a workaround ?

Thanks in advance !

Best regards,
HP_

  1. Здравствуйте! Купил attiny85, пытаюсь зашить на нее загрузчик (через Iskra Neo). Arduino IDE выдает ошибку:Подключал по такой схеме:

    [​IMG]

    Как бороться с ошибкой? Спасибо!

  2. На искре — да, на attiny его нет — пытаюсь зашить.

  3. Что за прошивка в Iskra Neo зашита?

  4. Видимо Ардуино ISP .Подключено правильно какой прогой зашиваете Бут? Делаете что то вроде этого? http://tinyurl.com/oxkldoj

  5. Да, делаю так. Загрузчик зашиваю дефолтный (в меню других и нету за ненадобностью) спомощью Arduino IDE.

  6. как то в итоге решили вопрос ?

Normal Topic avrdude: Error: Could not find USBtiny device (0x2341/0x49) (Read 8570 times)


Cy

Newbies

*
Offline

Posts: 2

Joined: Apr 24th, 2016

avrdude: Error: Could not find USBtiny device (0x2341/0x49)

Apr 24th, 2016 at 2:24pm

Print Post
 

This is very annoying, I’ve done every trick in the book and still getting this error! Please HELP ASAP. Thanks

My Arduino version 1.6.8

Program size: 1,554 bytes (used 1% of a 253,952 byte maximum) (0.27 secs)
Minimum Memory Usage: 9 bytes (0% of a 8192 byte maximum)

  Uploading to I/O board using ‘ArduinoISP’
Uploader started for board Arduino/Genuino Mega w/ ATmega2560 (Mega 2560)
Uploader will use programmer name: arduinoisp
C:Program Files (x86)Arduinohardwaretoolsavrbinavrdude «-CC:Program Files (x86)Arduinohardwaretoolsavr/etc/avrdude.conf» -v -patmega2560 -carduinoisp ketch1.ino.hex:i»
avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch
Error during upload using programmer
Upload failed

Upload failed
The uploader returned an error
         System wide configuration file is «C:Program Files (x86)Arduinohardwaretoolsavr/etc/avrdude.conf»
         Using Port                    : usb
         Using Programmer              : arduinoisp
avrdude: Error: Could not find USBtiny device (0x2341/0x49)
avrdude done.  Thank you.

« Last Edit: Apr 24th, 2016 at 2:35pm by Cy »  


Please Register or Login to the Forum to see File Attachments

Back to top

IP Logged
 


Tim@Visual Micro

Administrator

*****
Offline

Posts: 11684
Location: United Kingdom

Joined: Apr 10th, 2010

Re: avrdude: Error: Could not find USBtiny device (0x2341/0x49)

Reply #1 — Apr 24th, 2016 at 2:33pm

Print Post
 

Can I assume that you do NOT have a second Arduino that you have wired as an ISP programmer? That you are simply trying to upload using standard usb cable or ftdi?

1)
If yes, then you have ticked «vMicro>Always use programmer for upload» by mistake. Please untick and ensure the correct COM port is selected, then try the upload again.

2)
If no and you are trying to upload using another Arduino as an ISP then:-

  • Please switch on «vMicro>Verbose messages», try the upload again and post or email the output as a .txt file. 
  • Confirm if «Sketch>Upload using programmer» works in the Arduino IDE because that would be similar functionality? If not, then you have checked the «always upload using programmer» menu item by mistake.

Thanks

« Last Edit: May 27th, 2016 at 7:57pm by Tim@Visual Micro »  

Back to top

WWW
 

IP Logged
 


Cy

Newbies

*
Offline

Posts: 2

Joined: Apr 24th, 2016

Re: avrdude: Error: Could not find USBtiny device (0x2341/0x49)

Reply #2 — Apr 24th, 2016 at 2:40pm

Print Post
 

Thank you so very much for your prompt response. Case A solved the problem. you guys are great I’m going to buy the program!

Back to top

IP Logged
 

PlatformIO Community

Loading

После нескольких попыток загрузчик вроде записался)) Второй раз прописываться не хочет, выдает ошибку

Код

avrdude: ser_open(): cant open divice "\.COM30": Отказано в доступе.

Потом попробовал прошить программу. Сначала была пара ошибок, которые я не записал) Потом я все отключил, подключил обратно и вроде прошивка стала прописываться. Однако мк никак не реагирует… Посему опять парочка вопросов.

1. Кварц я взял от платы stm32vl discovery, на 8 МГц. Есть еще на 12 МГц, на 16 нету =( Какой лучше брать?

И подключаю я его без конденсаторов, на ножки (XTAL1/TOSC1) PB6 — (XTAL2/TOSC2) PB7. Конденсаторов при себе нет, а в инете видел, что так тоже должно прокатить)

2. После того, как я прошил программу, я отключаю ножку RESIT, вытаскиваю кварц, вытаскиваю питание и обратно его подключаю… Что то еще надо сделать, чтоб заработало?

Не вытаскивать кварц тоже пробовал, мк все равно не реагирует.

3. Прошивать пробовал двумя способами: «Загрузка» и «Загрузить через программатор». Никакой разницы я не вижу, но может какой то определенный метод нужен?

И прошиваю я с настройками для Atmega8… Может надо менять на UNO? Хотя тогда сама UNO будет по идее прошиваться…

4. Опять непонятки с портами)) Пишу digitalWrite(2, HIGH) — значит, если смотреть на распиновку в даташите, то это ножка PD0?
Просто я, мало того, что не уверен в правильности процесса прошивки, еще и не уверен в том, какую ногу проверять))

Note: Only the Arduino IDE has Burn Bootloader functionality. It is not possible to do this via Arduino Web Editor or arduino-cli.


General troubleshooting advice


How do I burn the bootloader to my AVR board?

The following instructions are for targets that use the AVR architecture (e.g., Uno, Nano, Leonardo, Mega).

You will need an ISP programmer. If you don’t have a programmer, you can use a spare Arduino board as an “Arduino as ISP” programmer. Although the “Arduino as ISP” only works for programming targets of the AVR architecture, you can use boards of any architecture as an “Arduino as ISP” programmer.

Instructions:

  1. Make the following connections between the Arduino board you will be using as the programmer and the target. Refer to the “Connections” table on the SPI library reference page to determine the pins:

    Programmer Target
    MISO MISO
    VCC 5V (or VCC on 3.3 V boards)
    SCK SCK
    MOSI MOSI
    10 RESET
    GND GND
  2. Connect the programmer board to your computer with a USB cable.
  3. File > Examples > 11.ArduinoISP > Arduino ISP
  4. Select the port of your board from the Tools > Port menu.
  5. Sketch > Upload
  6. Wait for the upload to finish.

You are now ready to burn the bootloader using your “Arduino as ISP” programmer.

Instructions for burning the bootloader:

  1. Connect an ISP programmer to the ICSP header on your Arduino board.
  2. Select the target board from the Tools > Board menu and any other custom Tools menus (e.g. Tools > Processor).
  3. Select the appropriate programmer from the Tools > Programmer menu.
  4. Tools > Burn Bootloader
  5. Wait for the process to finish successfully.

You can also use your ISP programmer to upload sketches to the target board via Sketch > Upload Using Programmer. Note that when you do this, the bootloader is erased. After using Upload Using Programmer, you would need to do another Burn Bootloader before you can go back to uploading to the target board normally via the USB cable.


How do I burn the bootloader to my MKR or Nano 33 IoT board?

You’ll need:

  • An extra Arduino board that runs at 3.3 V.
    • It is possible to use an Arduino board that runs at 5 V as the programmer, but you’ll need to use level shifting circuitry on the programming lines to avoid exposing the target board to 5 V logic levels, which would damage it.
  • An SD slot. This could be built into your Arduino board (e.g., MKR Zero), a shield (e.g., MKR SD Proto Shield), or one of the common SD modules.
  • An SD card that fits your SD slot.
  • A way to connect the SD card to your computer.
  • A way to make the connections to the SWD pins on your target Arduino board:
    • MKR1000: The SWD header is a 0.05” pitch 2×5 male header on the top of the board.
      • You will need an adapter, something like this one.
    • Other MKR boards and Nano 33 IoT: The SWD header is a 2×3 footprint or test pads on the bottom of the board.
      • You can use a 0.1” pitch 2×3 POGO adapter like this one.
      • You can solder wires to the test points.
      • On the MKR boards, it is the footprint for a 0.1” pitch SMD header (e.g., https://www.digikey.com/short/z3dvdv).

Instructions:

  1. Connect an SD card to your computer.
  2. Open this link in your browser: https://github.com/arduino/ArduinoCore-samd/tree/master/bootloaders
  3. Click the folder that matches the name of your target board.
  4. Click the file that ends in .bin
  5. Click the “Download” button.
  6. Rename the downloaded file to fw.bin
  7. Move fw.bin to the SD card.
  8. Eject the SD card from your computer.
  9. Plug the USB cable of the Arduino board you will be using as a programmer into your computer.
  10. (In the Arduino IDE) Sketch > Include Library > Manage Libraries
  11. Wait for the download to finish.
  12. In the “Filter your search…” field, type “Adafruit DAP library”.
  13. Press “Enter”.
  14. Click on “Adafruit DAP library by Adafruit”.
  15. Click the “Install” button.
  16. Wait for the installation to finish.
  17. Click the “Close” button.
  18. File > Examples > Adafruit DAP library > flash_from_SD
  19. Change this line:

    according to the Arduino pin connected to the SD CS pin. If your board has a built-in SD slot (e.g., MKR Zero), then you can change this line:

    to:

  20. Select the correct board from the Tools > Board menu.
  21. Select the correct port from the Tools > Port menu.
  22. Sketch > Upload
  23. Wait for the upload to finish successfully.
  24. Unplug the programmer Arduino board from your computer.
  25. Plug the SD card into the SD slot connected to your Arduino board.
  26. Connect the programmer Arduino board to the target Arduino board (see pinout diagrams below) as follows:

    Programmer Target
    VCC +3V3
    10 SWDIO
    9 SWCLK
    GND GND
    11 RESETN
  27. Plug the USB cable of the programmer Arduino board into your computer.
  28. Tools > Serial Monitor. You should now see the target board detected, and the bootloader file flashed to it successfully.
  29. Unplug the programmer Arduino board from your computer.
  30. Disconnect the programmer Arduino board from the target Arduino board.

Note: another alternative is to use a J-Link debug probe (J-Link EDU Mini and J-Link clones are available for a low price) with the Adalink software:
https://github.com/adafruit/Adafruit_Adalink

SWD pinout diagrams:

MKR boards other than MKR 1000

Code tags button

MKR 1000

Code tags button

Nano 33 IoT

Code tags button


How do I burn the bootloader to my Arduino Zero?

The Zero has a built-in programmer, which makes burning the bootloader very easy.

  1. Connect a USB cable to the “Programming Port” of the Zero.
  2. Plug the USB cable of the Zero into your computer.
  3. Tools > Board > Arduino Zero (Programming Port)
  4. Tools > Programmer > Atmel EDBG
  5. Tools > Burn Bootloader. The Burn Bootloader process should now proceed successfully.

How do I burn the bootloader to my Uno WiFi Rev2?

The Uno WiFi Rev2 has a built-in programmer, which makes burning the bootloader very easy.

  1. Plug the USB cable of the Uno WiFi Rev2 into your computer.
  2. Tools > Board > Arduino Uno WiFi Rev2
  3. Tools > Programmer > Onboard Atmel mEDBG (UNO WiFi Rev2)
  4. Tools > Burn Bootloader. The Burn Bootloader process should now proceed successfully.

Verbose output during Burn Bootloader

If the Burn Bootloader process is failing, it can be very helpful to check the verbose output to see what the problem is:

  1. File > Preferences
  2. Check the box next to “Show verbose output during: > upload”.
  3. Click the “OK” button.
  4. Do the Burn Bootloader.
  5. After the process fails, check the output in the black console window at the bottom of the Arduino IDE window. You may need to scroll up to see it all.

Specific issues


avrdude: warning: cannot set sck period. please check for usbasp firmware update.

This is normal with the common USBasp clones and does not indicate a problem. If you are having a problem burning the bootloader, this is not the cause. It is possible to upgrade the USBasp firmware, but it’s a somewhat advanced process so you should only upgrade if you actually need the features of the new firmware version.


avrdude: Device signature = 0x000000 or avrdude: Device signature = 0xffffff or avrdude: Device signature = {some random wrong signature}, avrdude: Yikes! Invalid device signature.

Carefully check the wiring between the programmer and target. If using an “Arduino as ISP” programmer, note that not all boards have the SPI bus on Arduino pins 11, 12, 13. Refer to the “Connections” table on the SPI library reference page to determine your board’s SPI pins.

If the target’s fuses were set to use an external clock/resonator/crystal, but no external clock source is attached, you will not be able to program the target. The solution is to connect a clock source to the target long enough to set the fuses to use the internal oscillator, after which the external clock source will no longer be required. The Arduino IDE’s Burn Bootloader process sets the fuses according to the definition of the currently selected board.

Make sure you have selected your target board from the Tools > Board menu.


avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x{some code}

Make sure you uploaded the File > Examples > 11.ArduinoISP > Arduino ISP sketch to the programmer board.

If you’re using an ATmega32U4-based board (e.g., Leonardo, Micro, Pro Micro, Yun) as an “Arduino as ISP” programmer, select “Arduino as ISP (ATmega32U4)” from the Tools > Programmer menu. If you don’t see that programmer option in the Tools > Programmer menu, you need to update Arduino AVR Boards, following these instructions:

  1. Tools > Board > Boards Manager
  2. Wait for the downloads to finish.
  3. Click on “Arduino AVR Boards”.
  4. Click the “Update” button.
  5. Wait for the update to finish.
  6. Click the “Close” button.

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x10, avrdude: stk500_initialize(): (b) protocol error, expect=0x10, resp=0x01, avrdude: initialization failed, rc=-1

Make sure you’re using Arduino AVR Boards 1.8.1 or newer. You can check the Arduino AVR Boards version and upgrade if necessary by following these instructions:

  1. Tools > Board > Boards Manager
  2. Wait for the download to finish.
  3. Click on “Arduino AVR Boards”.
  4. Click the “Update” button.
  5. Wait for the update to finish.
  6. Click the “Close” button.

If the problem still occurs with Arduino AVR Boards 1.8.1 or newer, connect a 10 uF capacitor between the GND and RST pins on the “Arduino as ISP” programmer board.


avrdude: Error: Could not find USBtiny device (0x2341/0x49) / avrdude: Error: Could not find USBtiny device (0x2a03/0x49) while using an “Arduino as ISP” programmer

This is caused by using the “ArduinoISP” or “ArduinoISP.org” Programmer menu selections when using the Arduino as ISP programmer. You need to select Tools > Programmer > Arduino as ISP.


How do I use -F to override AVRDUDE’s signature check?

Although AVRDUDE suggests overriding the signature check via the -F command line flag, this would only be helpful in extremely rare cases where the chip’s signature has somehow been corrupted. Much more often, the signature check fails because the programmer is incorrectly connected to the target or the wrong board was selected. In those cases, disabling the signature check won’t solve the problem.


avrdude: error: program enable: target doesn't answer. 0, avrdude: initialization failed, rc=-1

This error is caused by using the libusb-win32 driver with Arduino’s version of AVRDUDE. The solution is to use the libusbK driver instead:

  1. Download Zadig: https://zadig.akeo.ie. Note that Zadig is recommended on the official USBasp website.
  2. Plug in your USBasp
  3. Start Zadig
  4. From the dropdown menu, select USBasp. If it doesn’t show up on the menu, select Options > List all devices and check again.
  5. Click the up or down arrows next to the Driver selection box on the right side until you see libusbK.
  6. Click the “Replace Driver” button.
  7. Wait for the driver installation to finish.
  8. Close Zadig.

avrdude: error: program enable: target doesn't answer. 1, avrdude: initialization failed, rc=-1

Make sure the programmer’s cable is correctly connected to the target board. Pin 1 on the cable is indicated by a small triangle embossed on the plastic. Pin 1 on the Arduino board’s ICSP header is indicated by a white dot on the PCB’s silkscreen.

If your USBasp programmer has the official firmware, you must short the JP3 jumper to program chips that are running at <=1 MHz clock speed. The factory default clock configuration is running on the internal oscillator at 1 MHz. Many of the common Chinese USBasp clones come with a modified firmware that is able to work with chips running at the slower clock speeds without needing to set the jumper. There is also a alternate open source firmware provided by the community that has this functionality.


avrdude: stk500v2_program_enable(): bad AVRISPmkII connection status: RST fail, Target reverse inserted

Make sure the programmer’s cable is correctly connected to the target board. Pin 1 on the cable is indicated by a small triangle embossed on the plastic. Pin 1 on the Arduino board’s ICSP header is indicated by a white dot on the PCB’s silkscreen.

Старый
13.04.2016, 22:48

 
#21

Moderator

 

Регистрация: 20.07.2014

Адрес: МСК

Сообщений: 983

Вес репутации: 1021

Tohin is a jewel in the roughTohin is a jewel in the roughTohin is a jewel in the rough

По умолчанию
Re: AVR (mega328p)


Я запорол pro mini?
Прошил Uno в ArduinoISP, переставил настройки на ProMini 5V, запустил «записать загручик» и получил:

Цитата:

D:arduino-1.6.7-2hardwaretoolsavr/bin/avrdude -CD:arduino-1.6.7-2hardwaretoolsavr/etc/avrdude.conf -v -patmega328p -c arduinoisp -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xFF:m

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch

System wide configuration file is «D:arduino-1.6.7-2hardwaretoolsavr/etc/avrdude.conf»

Using Port : usb
Using Programmer : arduinoisp
avrdude: Error: Could not find USBtiny device (0x2341/0x49)

avrdude done. Thank you.

Tohin вне форума

 

Ответить с цитированием

Старый
13.04.2016, 22:52

 
#22

Administrator

 

Аватар для Admin

По умолчанию
Re: AVR (mega328p)


Да вроде ничего криминального, он написал что ему не удалось найти устройство

Цитата:

Не удалось найти USBtiny устройство

Admin вне форума

 

Ответить с цитированием

Старый
13.04.2016, 22:58

 
#23

Administrator

 

Аватар для Admin

По умолчанию
Re: AVR (mega328p)


Открываем Arduino IDE и заливаем в Arduino Uno sketch называющийся ArduinoISP (File -> Examples -> Arduino ISP)
В скетче есть распиновка программатора

Цитата:

// this sketch turns the Arduino into a AVRISP
// using the following pins:
// 10: slave reset
// 11: MOSI
// 12: MISO
// 13: SCK

// Put an LED (with resistor) on the following pins:
// 9: Heartbeat — shows the programmer is running
// 8: Error — Lights up if something goes wrong (use red if that makes sense)
// 7: Programming — In communication with the slave

Нужно подключить как минимум 6 выводов
10: slave reset
11: MOSI
12: MISO
13: SCK
GND: GND
+5v: 5v

Admin вне форума

 

Ответить с цитированием

Старый
13.04.2016, 23:23

 
#24

Moderator

 

Регистрация: 20.07.2014

Адрес: МСК

Сообщений: 983

Вес репутации: 1021

Tohin is a jewel in the roughTohin is a jewel in the roughTohin is a jewel in the rough

По умолчанию
Re: AVR (mega328p)


Спасибо за участие.
я вроде так и делал… из того же скетча:

Цитата:

// Put an LED (with resistor) on the following pins:
// 9: Heartbeat — shows the programmer is running

на 9м пине диод красиво мигает..
выводы все подключил.

UPD:
Сорри за беспокойство. я опять ступил. Нужно выбирать программатор не ArduinoISP а Arduino

as ISP…..


Последний раз редактировалось Tohin; 13.04.2016 в 23:30.

Tohin вне форума

 

Ответить с цитированием

Старый
13.04.2016, 23:31

 
#25

Administrator

 

Аватар для Admin

По умолчанию
Re: AVR (mega328p)


на 9 пину светодиод показывает, что осуществляется прошивка

Admin вне форума

 

Ответить с цитированием

Старый
13.04.2016, 23:52

 
#26

Moderator

 

Регистрация: 20.07.2014

Адрес: МСК

Сообщений: 983

Вес репутации: 1021

Tohin is a jewel in the roughTohin is a jewel in the roughTohin is a jewel in the rough

По умолчанию
Re: AVR (mega328p)


Цитата:

Сообщение от Admin
Посмотреть сообщение

на 9 пину светодиод показывает, что осуществляется прошивка

неа… на 7м прошивка:

Цитата:

// Put an LED (with resistor) on the following pins:
// 9: Heartbeat — shows the programmer is running
// 8: Error — Lights up if something goes wrong (use red if that makes sense)
// 7: Programming — In communication with the slave

Заработало… нажимаю кнопку на одной дуине, загорается лампочка на другой. На что я потратил свой отпуск, а?!

Tohin вне форума

 

Ответить с цитированием

Старый
13.04.2016, 23:58

 
#27

Administrator

 

Аватар для Admin

По умолчанию
Re: AVR (mega328p)


На 7-ом показывает что есть соединение

Admin вне форума

 

Ответить с цитированием

Старый
14.04.2016, 14:28

 
#28

Moderator

 

Регистрация: 20.07.2014

Адрес: МСК

Сообщений: 983

Вес репутации: 1021

Tohin is a jewel in the roughTohin is a jewel in the roughTohin is a jewel in the rough

По умолчанию
Re: AVR (mega328p)


Цитата:

Сообщение от Admin
Посмотреть сообщение

на 9 пину светодиод показывает, что осуществляется прошивка

Пр факту он плавно мигает при подаче питания. Мне показалось это обозначает, что залитый скетч является ISP программатором и он работает

Цитата:

Сообщение от Admin
Посмотреть сообщение

На 7-ом показывает что есть соединение

опять же, по факту, он моргает при выполнении прошивки ведомой платы.


Последний раз редактировалось Tohin; 14.04.2016 в 14:58.

Причина: Задумался…

Tohin вне форума

 

Ответить с цитированием

Старый
18.06.2016, 10:29

 
#29

Moderator

 

Регистрация: 20.07.2014

Адрес: МСК

Сообщений: 983

Вес репутации: 1021

Tohin is a jewel in the roughTohin is a jewel in the roughTohin is a jewel in the rough

По умолчанию
Re: AVR (mega328p)


Опять туплю где-то… Может кто свежим взглядом выведает:

PHP код:



#include <avr/interrupt.h>
volatile uint16_t Hot_CountCold_Count

uint16_t HotCold;
void setup() {

  
// put your setup code here, to run once:

PCICR 0b00000001// включаем прерывания PCINT0. цитата из даташита Bit 0 – PCIE0: Pin Change Interrupt Enable. Any change on any enabled PCINT[7:0] pin will cause an interrupt.

DDRB 0b00111100// пины 0 и 1 порта B - это входы, все остальное - выходы. 

PORTB 0x00;  // отключаем подтяжку на всех пинах. входы 0 и 1 подтянуты к земле через резистор,и к +5v через кнопку.

PCMSK0 0b00000011// Создаем маску для PCINT0, чтобы реагировать только на пины 0 и 1. Т.к. на остальных могут быть релешки и не нужно дергать прерыывание при их срабатывании.

 
sei();

  
Serial.begin(9600);

  
Serial.print("I'm readynr"); //Для отладки, пишем что ардуинка жива.
}
ISR(PCINT0_vect){  // Кто-то дернул прерывание на portb

   
Serial.print("start interruptnr");

 if ((
PINB&(<< PB0)) == 1&&Cold_Count==0){ //Если это PB0(8 пин), то нужно добавить 10л к холодной воде. второй частью проверяем, что мы это срабатывание еще не учитывали.

  
Cold_Count 1// сообщаем в основной цикл, что было срабатывание геркона на холодной воде.

    
Serial.print("Cold_countnr");

 }

 if ((

PINB&(<< PB1)) == 1&&Hot_Count==0){ //Если это PB1(9 пин), то делаем то же самое с горячей водой.

  
Hot_Count 1

    
Serial.print("Hot_countnr");

 }

   




С холодной все отрабатывает нормально… а вот на горячей в прерывание входит, а условие не отрабатывается.

UPD:
Нашел причину, но все равно не понял….

PHP код:



(PINB&(<< PB1)) == // Но почему? и как правильно? 





Последний раз редактировалось Tohin; 18.06.2016 в 11:01.

Tohin вне форума

 

Ответить с цитированием

Старый
18.06.2016, 10:44

 
#30

Administrator

 

Аватар для Admin

По умолчанию
Re: AVR (mega328p)


Если мне память не изменяет , то Serial.print в обработчике прерывания запрещено использовать

Admin вне форума

 

Ответить с цитированием

Понравилась статья? Поделить с друзьями:
  • Avrdude error could not find usbtiny device 0x1781 0xc9f
  • Avrdude error could not find usb device usbasp with vid 0x16c0 pid 0x5dc
  • Avrdude arduino error
  • Avr usart rx frame error
  • Avr studio error 51