Страница 2 из 6 ПерваяПервая 123456 ПоследняяПоследняя
Показано с 11 по 20 из 60
  1. #11
    Администратор Аватар для Chip
    Регистрация
    08.06.2007
    Возраст
    54
    Сообщений
    13,378
    Вес репутации
    10

    По умолчанию Re: Программатор из Arduino

    Не проблема , я ардуиной прошивал контроллеры Atmega, нужно только в конфигурации указывать тип контроллера, за это отвечает ключ -p
    Последний раз редактировалось Chip; 25.10.2009 в 19:54.

  2. #12
    Гуру Аватар для (vS)
    Регистрация
    18.06.2007
    Возраст
    46
    Сообщений
    1,981
    Вес репутации
    684

    По умолчанию Re: Программатор из Arduino

    Цитата Сообщение от Chip Посмотреть сообщение
    -U flash:w:ATmegaBOOT_168_diecimila.hex - указывает на .hex файл с прошивкой
    а под МЕГА8 случайно нет лоадера?
    автоMOBILEвый моDDEр
    мой карпутер второй очередной

  3. #13
    Пользователь
    Регистрация
    11.11.2008
    Возраст
    43
    Сообщений
    59
    Вес репутации
    201

    По умолчанию Re: Программатор из Arduino

    есть. он идет в комплекте с прогой Arduinio IDE и лежит в папке arduino-0017\hardware\bootloaders\atmega8
    Последний раз редактировалось KotKin; 30.12.2009 в 12:59.

  4. #14
    Гуру Аватар для (vS)
    Регистрация
    18.06.2007
    Возраст
    46
    Сообщений
    1,981
    Вес репутации
    684

    По умолчанию Re: Программатор из Arduino

    спасиба
    автоMOBILEвый моDDEр
    мой карпутер второй очередной

  5. #15
    Новичок
    Регистрация
    26.10.2009
    Сообщений
    18
    Вес репутации
    182

    По умолчанию Re: Программатор из Arduino

    а как мне прошить Attiny 2313?

  6. #16
    Администратор Аватар для Chip
    Регистрация
    08.06.2007
    Возраст
    54
    Сообщений
    13,378
    Вес репутации
    10

    По умолчанию Re: Программатор из Arduino

    Вот здесь посмотри

    И еще один вариант
    PHP код:
    // 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
    // 
    // February 2009 by Randall Bohn
    // - Added support for writing to EEPROM (what took so long?)
    // Windows users should consider WinAVR's avrdude instead of the
    // avrdude included with Arduino software.
    //
    // January 2008 by Randall Bohn
    // - Thanks to Amplificar for helping me with the STK500 protocol
    // - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader
    // - The SPI functions herein were developed for the AVR910_ARD programmer 
    // - More information at http://code.google.com/p/mega-isp

    #define SCK 13
    #define MISO 12
    #define MOSI 11
    #define RESET 10

    #define LED_HB 9
    #define LED_ERR 8
    #define LED_PMODE 7

    #define HWVER 2
    #define SWMAJ 1
    #define SWMIN 18

    // STK Definitions
    #define STK_OK 0x10
    #define STK_FAILED 0x11
    #define STK_UNKNOWN 0x12
    #define STK_INSYNC 0x14
    #define STK_NOSYNC 0x15
    #define CRC_EOP 0x20 //ok it is a space...

    void pulse(int pinint times);

    void setup() {
      
    // 19200?
      
    Serial.begin(19200);
      
    pinMode(7OUTPUT);
      
    pulse(72);
      
    pinMode(8OUTPUT);
      
    pulse(82);
      
    pinMode(9OUTPUT);
      
    pulse(92);
    }

    int error=0;
    int pmode=0;
    // address for reading and writing, set by 'U' command
    int here;
    uint8_t buff[256]; // global block storage

    #define beget16(addr) (*addr * 256 + *(addr+1) )
    typedef struct param {
      
    uint8_t devicecode;
      
    uint8_t revision;
      
    uint8_t progtype;
      
    uint8_t parmode;
      
    uint8_t polling;
      
    uint8_t selftimed;
      
    uint8_t lockbytes;
      
    uint8_t fusebytes;
      
    int flashpoll;
      
    int eeprompoll;
      
    int pagesize;
      
    int eepromsize;
      
    int flashsize;

    parameter;

    parameter param;

    // this provides a heartbeat on pin 9, so you can tell the software is running.
    uint8_t hbval=128;
    int8_t hbdelta=8;
    void heartbeat() {
      if (
    hbval 192hbdelta = -hbdelta;
      if (
    hbval 32hbdelta = -hbdelta;
      
    hbval += hbdelta;
      
    analogWrite(LED_HBhbval);
      
    delay(40);
    }
      

    void loop(void) {
      
    // is pmode active?
      
    if (pmodedigitalWrite(LED_PMODEHIGH); 
      else 
    digitalWrite(LED_PMODELOW);
      
    // is there an error?
      
    if (errordigitalWrite(LED_ERRHIGH); 
      else 
    digitalWrite(LED_ERRLOW);
      
      
    // light the heartbeat LED
      
    heartbeat();
      if (
    Serial.available()) {
        
    avrisp();
      }
    }

    uint8_t getch() {
      while(!
    Serial.available());
      return 
    Serial.read();
    }
    void readbytes(int n) {
      for (
    int x 0nx++) {
        
    buff[x] = Serial.read();
      }
    }

    #define PTIME 30
    void pulse(int pinint times) {
      do {
        
    digitalWrite(pinHIGH);
        
    delay(PTIME);
        
    digitalWrite(pinLOW);
        
    delay(PTIME);
      } 
      while (
    times--);
    }

    void spi_init() {
      
    uint8_t x;
      
    SPCR 0x53;
      
    x=SPSR;
      
    x=SPDR;
    }

    void spi_wait() {
      do {
      } 
      while (!(
    SPSR & (<< SPIF)));
    }

    uint8_t spi_send(uint8_t b) {
      
    uint8_t reply;
      
    SPDR=b;
      
    spi_wait();
      
    reply SPDR;
      return 
    reply;
    }

    uint8_t spi_transaction(uint8_t auint8_t buint8_t cuint8_t d) {
      
    uint8_t n;
      
    spi_send(a); 
      
    n=spi_send(b);
      
    //if (n != a) error = -1;
      
    n=spi_send(c);
      return 
    spi_send(d);
    }

    void empty_reply() {
      if (
    CRC_EOP == getch()) {
        
    Serial.print((char)STK_INSYNC);
        
    Serial.print((char)STK_OK);
      } 
      else {
        
    Serial.print((char)STK_NOSYNC);
      }
    }

    void breply(uint8_t b) {
      if (
    CRC_EOP == getch()) {
        
    Serial.print((char)STK_INSYNC);
        
    Serial.print((char)b);
        
    Serial.print((char)STK_OK);
      } 
      else {
        
    Serial.print((char)STK_NOSYNC);
      }
    }

    void get_version(uint8_t c) {
      switch(
    c) {
      case 
    0x80:
        
    breply(HWVER);
        break;
      case 
    0x81:
        
    breply(SWMAJ);
        break;
      case 
    0x82:
        
    breply(SWMIN);
        break;
      case 
    0x93:
        
    breply('S'); // serial programmer
        
    break;
      default:
        
    breply(0);
      }
    }

    void set_parameters() {
      
    // call this after reading paramter packet into buff[]
      
    param.devicecode buff[0];
      
    param.revision buff[1];
      
    param.progtype buff[2];
      
    param.parmode buff[3];
      
    param.polling buff[4];
      
    param.selftimed buff[5];
      
    param.lockbytes buff[6];
      
    param.fusebytes buff[7];
      
    param.flashpoll buff[8]; 
      
    // ignore buff[9] (= buff[8])
      //getch(); // discard second value
      
      // WARNING: not sure about the byte order of the following
      // following are 16 bits (big endian)
      
    param.eeprompoll beget16(&buff[10]);
      
    param.pagesize beget16(&buff[12]);
      
    param.eepromsize beget16(&buff[14]);

      
    // 32 bits flashsize (big endian)
      
    param.flashsize buff[16] * 0x01000000
        
    buff[17] * 0x00010000
        
    buff[18] * 0x00000100
        
    buff[19];

    }

    void start_pmode() {
      
    spi_init();
      
    // following delays may not work on all targets...
      
    pinMode(RESETOUTPUT);
      
    digitalWrite(RESETHIGH);
      
    pinMode(SCKOUTPUT);
      
    digitalWrite(SCKLOW);
      
    delay(50);
      
    digitalWrite(RESETLOW);
      
    delay(50);
      
    pinMode(MISOINPUT);
      
    pinMode(MOSIOUTPUT);
      
    spi_transaction(0xAC0x530x000x00);
      
    pmode 1;
    }

    void end_pmode() {
      
    pinMode(MISOINPUT);
      
    pinMode(MOSIINPUT);
      
    pinMode(SCKINPUT);
      
    pinMode(RESETINPUT);
      
    pmode 0;
    }

    void universal() {
      
    int w;
      
    uint8_t ch;

      for (
    04w++) {
        
    buff[w] = getch();
      }
      
    ch spi_transaction(buff[0], buff[1], buff[2], buff[3]);
      
    breply(ch);
    }

    void flash(uint8_t hiloint addruint8_t data) {
      
    spi_transaction(0x40+8*hilo
      
    addr>>0xFF
      
    addr 0xFF,
      
    data);
    }
    void commit(int addr) {
      
    spi_transaction(0x4C, (addr >> 8) & 0xFFaddr 0xFF0);
    }

    //#define _current_page(x) (here & 0xFFFFE0)
    int current_page(int addr) {
      if (
    param.pagesize == 32) return here 0xFFFFFFF0;
      if (
    param.pagesize == 64) return here 0xFFFFFFE0;
      if (
    param.pagesize == 128) return here 0xFFFFFFC0;
      if (
    param.pagesize == 256) return here 0xFFFFFF80;
      return 
    here;
    }
    uint8_t write_flash(int length) {
      if (
    param.pagesize 1) return STK_FAILED;
      
    //if (param.pagesize != 64) return STK_FAILED;
      
    int page current_page(here);
      
    int x 0;
      while (
    length) {
        if (
    page != current_page(here)) {
          
    commit(page);
          
    page current_page(here);
        }
        
    flash(LOWherebuff[x++]);
        
    flash(HIGHherebuff[x++]);
        
    here++;
      }

      
    commit(page);

      return 
    STK_OK;
    }

    uint8_t write_eeprom(int length) {
      
    // here is a word address, so we use here*2
      // this writes byte-by-byte,
      // page writing may be faster (4 bytes at a time)
      
    for (int x 0lengthx++) {
        
    spi_transaction(0xC00x00here*2+xbuff[x]);
        
    delay(45);
      } 
      return 
    STK_OK;
    }

    void program_page() {
      
    char result = (charSTK_FAILED;
      
    int length 256 getch() + getch();
      if (
    length 256) {
          
    Serial.print((charSTK_FAILED);
          return;
      }
      
    char memtype getch();
      for (
    int x 0lengthx++) {
        
    buff[x] = getch();
      }
      if (
    CRC_EOP == getch()) {
        
    Serial.print((charSTK_INSYNC);
        if (
    memtype == 'F'result = (char)write_flash(length);
        if (
    memtype == 'E'result = (char)write_eeprom(length);
        
    Serial.print(result);
      } 
      else {
        
    Serial.print((charSTK_NOSYNC);
      }
    }
    uint8_t flash_read(uint8_t hiloint addr) {
      return 
    spi_transaction(0x20 hilo 8,
        (
    addr >> 8) & 0xFF,
        
    addr 0xFF,
        
    0);
    }

    char flash_read_page(int length) {
      for (
    int x 0lengthx+=2) {
        
    uint8_t low flash_read(LOWhere);
        
    Serial.print((charlow);
        
    uint8_t high flash_read(HIGHhere);
        
    Serial.print((charhigh);
        
    here++;
      }
      return 
    STK_OK;
    }

    char eeprom_read_page(int length) {
      
    // here again we have a word address
      
    for (int x 0lengthx++) {
        
    uint8_t ee spi_transaction(0xA00x00here*2+x0xFF);
        
    Serial.print((charee);
      }
      return 
    STK_OK;
    }

    void read_page() {
      
    char result = (char)STK_FAILED;
      
    int length 256 getch() + getch();
      
    char memtype getch();
      if (
    CRC_EOP != getch()) {
        
    Serial.print((charSTK_NOSYNC);
        return;
      }
      
    Serial.print((charSTK_INSYNC);
      if (
    memtype == 'F'result flash_read_page(length);
      if (
    memtype == 'E'result eeprom_read_page(length);
      
    Serial.print(result);
      return;
    }
    //////////////////////////////////////////
    //////////////////////////////////////////


    ////////////////////////////////////
    ////////////////////////////////////
    int avrisp() { 
      
    uint8_t datalowhigh;
      
    uint8_t ch getch();
      switch (
    ch) {
      case 
    '0'// signon
        
    empty_reply();
        break;
      case 
    '1':
        if (
    getch() == CRC_EOP) {
          
    Serial.print((charSTK_INSYNC);
          
    Serial.print("AVR ISP");
          
    Serial.print((charSTK_OK);
        }
        break;
      case 
    'A':
        
    get_version(getch());
        break;
      case 
    'B':
        
    readbytes(20);
        
    set_parameters();
        
    empty_reply();
        break;
      case 
    'E'// extended parameters - ignore for now
        
    readbytes(5);
        
    empty_reply();
        break;

      case 
    'P':
        
    start_pmode();
        
    empty_reply();
        break;
      case 
    'U':
        
    here getch() + 256 getch();
        
    empty_reply();
        break;

      case 
    0x60//STK_PROG_FLASH
        
    low getch();
        
    high getch();
        
    empty_reply();
        break;
      case 
    0x61//STK_PROG_DATA
        
    data getch();
        
    empty_reply();
        break;

      case 
    0x64//STK_PROG_PAGE
        
    program_page();
        break;
        
      case 
    0x74//STK_READ_PAGE
        
    read_page();    
        break;

      case 
    'V':
        
    universal();
        break;
      case 
    'Q':
        
    error=0;
        
    end_pmode();
        
    empty_reply();
        break;

      
    // expecting a command, not CRC_EOP
      // this is how we can get back in sync
      
    case CRC_EOP:
        
    Serial.print((charSTK_NOSYNC);
        break;
        
      
    // anything else we will return STK_UNKNOWN
      
    default:
        if (
    CRC_EOP == getch()) 
          
    Serial.print((char)STK_UNKNOWN);
        else
          
    Serial.print((char)STK_NOSYNC);
      }

    Последний раз редактировалось Chip; 03.02.2010 в 03:24.

  7. #17
    Пользователь
    Регистрация
    24.02.2010
    Возраст
    47
    Сообщений
    47
    Вес репутации
    184

    По умолчанию Re: Программатор из Arduino

    Помогите победить Arduino ATMega2560 (такая вот: http://emartee.com/product/41884/Ard...ega-ATmega2560)

    Скоммутировал X3 и ICSP как описано в первом посте. Скачал avrdude. Попробовал прошить такой командой:

    avrdude.exe -p m2560 -U flash:w:ATmegaBOOT_168_mega2560.hex -c diecimila -P ft0
    получил:

    > avrdude.exe -p m2560 -U flash:w:ATmegaBOOT_168_mega2560.hex -c diecimila -P ft0

    avrdude.exe: BitBang OK
    avrdude.exe: pin assign miso 3 sck 5 mosi 6 reset 7
    avrdude.exe: drain OK

    ft245r: bitclk 230400 -> ft baud 115200
    avrdude.exe: ft245r_program_enable: failed
    avrdude.exe: initialization failed, rc=-1
    Double check connections and try again, or use -F to override
    this check.

    avrdude.exe done. Thank you.
    Соответственно перепроверил соединения - ошибки быть не может. Также пробовал прошить через оболочку Arduino (версия 0018) - нет пункта меню Tools > Burn Bootloader > w/ FTDI Bitbang (метод описан здесь: http://www.geocities.jp/arduino_diec..._w_ide_en.html)

    Как быть? Найти плату-прошивальщик, другую ардуину или спаять программатор самому не представляется возможным - познания в построении устройств заканчиваются на знаниях "что куда подключить", да и то по руководству. Я программист. Спасите-помогите, пытливый ум хочет чего-нить сотворить....

    Спасибо!

  8. #18
    Администратор Аватар для Chip
    Регистрация
    08.06.2007
    Возраст
    54
    Сообщений
    13,378
    Вес репутации
    10

    По умолчанию Re: Программатор из Arduino

    Попробуй так:
    avrdude -F -e -C avrdude.conf -c diecimila -P ft0 -p m2560 -B 4800 -U flash:w:ATmegaBOOT_168_mega2560.hex
    Последний раз редактировалось Chip; 14.06.2010 в 20:43.

  9. #19
    Пользователь
    Регистрация
    24.02.2010
    Возраст
    47
    Сообщений
    47
    Вес репутации
    184

    По умолчанию Re: Программатор из Arduino

    Попробовал, вот:
    avrdude.EXE: Device signature = 0xffffff
    avrdude.EXE: Yikes! Invalid device signature.
    avrdude.EXE: Expected signature for ATMEGA2560 is 1E 98 01
    avrdude.EXE: erasing chip
    ft245r: bitclk 230400 -> ft baud 115200
    avrdude.EXE: ft245r_program_enable: failed
    avrdude.EXE: reading input file "ATmegaBOOT_168_mega2560.hex"
    avrdude.EXE: input file ATmegaBOOT_168_mega2560.hex auto detected as Intel Hex
    avrdude.EXE: writing flash (256444 bytes):

    Writing | ################################################## | 100% 97.30s



    avrdude.EXE: 256444 bytes of flash written
    avrdude.EXE: verifying flash memory against ATmegaBOOT_168_mega2560.hex:
    avrdude.EXE: load data flash data from input file ATmegaBOOT_168_mega2560.hex:
    avrdude.EXE: input file ATmegaBOOT_168_mega2560.hex auto detected as Intel Hex
    avrdude.EXE: input file ATmegaBOOT_168_mega2560.hex contains 256444 bytes
    avrdude.EXE: reading on-chip flash data:

    Reading | ################################################## | 100% 44.81s



    avrdude.EXE: verifying ...
    avrdude.EXE: verification error, first mismatch at byte 0x3e000
    0x0d != 0xff
    avrdude.EXE: verification error; content mismatch

    avrdude.EXE: safemode: Fuses OK

    avrdude.EXE done. Thank you.
    Судя по всему проверка не прошла

  10. #20
    Администратор Аватар для Chip
    Регистрация
    08.06.2007
    Возраст
    54
    Сообщений
    13,378
    Вес репутации
    10

    По умолчанию Re: Программатор из Arduino

    Нужно биты конфигурации устанавливать, к сожалению на ATMEGA2560 я не конфигурировал, так что не подскажу

Страница 2 из 6 ПерваяПервая 123456 ПоследняяПоследняя

Информация о теме

Пользователи, просматривающие эту тему

Эту тему просматривают: 1 (пользователей: 0 , гостей: 1)

Ваши права

  • Вы не можете создавать новые темы
  • Вы не можете отвечать в темах
  • Вы не можете прикреплять вложения
  • Вы не можете редактировать свои сообщения
  •