Menu

Help please with ATtiny861

Help
Keith
2016-08-20
2016-09-27
1 2 > >> (Page 1 of 2)
  • Keith

    Keith - 2016-08-20

    Well I’m back again on the quest for some help with the Black Arts forbidden fruit known as an ATtiny861.

    I have some source code for a soundclip player in C which may as well be in Japanese or Martian and a HEX file but after that I don’t know where to go.

    Common sense or probably the lack of it is telling me that my PicKit 2 or 3 will not look at an Atmeg device and my GCB IDE will probably not compile my C file so it looks like I'm stuck with the HEX file.

    Can anyone please point me in the most practical approach to get this thing up and running. What I need, etc.

    Once again Many thanks in advance.

     
    • Anobium

      Anobium - 2016-08-20

      Post the C source - that is a start. :-)

       
  • kent_twt4

    kent_twt4 - 2016-08-20

    I've used the AVRISP mkII programmer along side Atmel Studio to program hex files into ATTiny's and Mega's.

     
  • Keith

    Keith - 2016-08-20

    Hello again Evan, (Still making mini bombs with supercaps!)

    This is the C code that I have found on the net. It is a basic one chip riff /wav 256 voice player. I have the hex file so I don't really need to compile this but I would like a little insight into what is going on.

    As I said before I'm completely in the dark with Atmeg stuff - Kent has given me a clue as to what programmer to use which program to speak to it with.

    Pity, I couldn't transfer this to a PIC I half know what I'm doing there. (okay, less than half, !!)

    /----------------------------------------------------------------------------/
    / 8-pin SD audio player R0.05d (C)ChaN, 2011 /
    /-----------------------------------------------------------------------------/
    / This project, program codes and circuit diagrams, is opened under license
    / policy of following trems.
    /
    / Copyright (C) 2010, ChaN, all right reserved.
    /
    / * This project is a free software and there is NO WARRANTY.
    / * No restriction on use. You can use, modify and redistribute it for
    / personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
    / * Redistributions of source code must retain the above copyright notice.
    /
    /----------------------------------------------------------------------------
    /

    ~ #include <avr io.h="">
    #include <avr interrupt.h="">
    #include <avr sleep.h="">
    #include <avr wdt.h="">
    #include <string.h>
    #include "pff.h"
    #include "xitoa.h"</string.h></avr></avr></avr></avr>

    #ifndef MODE
    #error Wrong make file.
    #endif
    #if MODE == 0 / Single output /
    FUSES = {0xE1, 0xDD, 0xFF}; / Fuse bytes for mono: Low, High and Extended /
    #else / Dual output /
    FUSES = {0xE1, 0x7D, 0xFF}; / Fuse bytes for stereo and mono-HR: Low, High and Extended (HVS mode only) /
    #endif
    / This is the fuse settings of this project. The fuse data will be included
    in the output hex file with program code. However some old flash programmers
    cannot load the fuse bits from hex file. If it is the case, remove this line
    and use these values to program the fuse bits.
    /

    #define FCC(c1,c2,c3,c4) (((DWORD)c4<<24)+((DWORD)c3<<16)+((WORD)c2<<8)+(BYTE)c1) / FourCC /

    void delay_us (WORD); / Defined in asmfunc.S /

    /---------------------------------------------------------/
    / Work Area /
    /---------------------------------------------------------/

    volatile BYTE FifoRi, FifoWi, FifoCt; / FIFO controls /

    BYTE Buff[256]; / Wave output FIFO /

    FATFS Fs; / File system object /
    DIR Dir; / Directory object /
    FILINFO Fno; / File information /

    WORD rb; / Return value. Put this here to avoid avr-gcc's bug /

    /---------------------------------------------------------/

    static
    DWORD load_header (void) / 0:Invalid format, 1:I/O error, >=1024:Number of samples /
    {
    DWORD sz, f;
    BYTE b, al = 0;

    if (pf_read(Buff, 12, &rb)) return 1;   /* Load file header (12 bytes) */
    
    if (rb != 12 || LD_DWORD(Buff+8) != FCC('W','A','V','E')) return 0;
    
    for (;;) {
      wdt_reset();
      pf_read(Buff, 8, &rb);            /* Get Chunk ID and size */
      if (rb != 8) return 0;
      sz = LD_DWORD(&Buff[4]);      /* Chunk size */
    
      switch (LD_DWORD(&Buff[0])) { /* Switch by chunk ID */
      case FCC('f','m','t',' ') :                   /* 'fmt ' chunk */
        if (sz & 1) sz++;                       /* Align chunk size */
        if (sz > 100 || sz < 16) return 0;      /* Check chunk size */
        pf_read(Buff, sz, &rb);                 /* Get content */
        if (rb != sz) return 0;
        if (Buff[0] != 1) return 0;             /* Check coding type (LPCM) */
        b = Buff[2];
        if (b != 1 && b != 2) return 0;         /* Check channels (1/2) */
        GPIOR0 = al = b;                        /* Save channel flag */
        b = Buff[14];
        if (b != 8 && b != 16) return 0;        /* Check resolution (8/16 bit) */
        GPIOR0 |= b;                            /* Save resolution flag */
        if (b & 16) al <<= 1;
        f = LD_DWORD(&Buff[4]);                 /* Check sampling freqency (8k-48k) */
        if (f < 8000 || f > 48000) return 4;
        OCR0A = (BYTE)(F_CPU / 8 / f) - 1;      /* Set sampling interval */
        break;
    
      case FCC('d','a','t','a') :       /* 'data' chunk */
        if (!al) return 0;                          /* Check if format is valid */
        if (sz < 1024 || (sz & (al - 1))) return 0; /* Check size */
        if (Fs.fptr & (al - 1)) return 0;           /* Check word alignment */
        return sz;                                  /* Start to play */
    
      case FCC('D','I','S','P') :       /* 'DISP' chunk */
      case FCC('L','I','S','T') :       /* 'LIST' chunk */
      case FCC('f','a','c','t') :       /* 'fact' chunk */
        if (sz & 1) sz++;               /* Align chunk size */
        pf_lseek(Fs.fptr + sz);         /* Skip this chunk */
        break;
    
      default :                     /* Unknown chunk */
        return 0;
      }
    }
    
    return 0;
    

    }

    static
    void ramp (
    int dir / 0:Ramp-down, 1:Ramp-up /
    )
    {
    #if MODE != 3
    BYTE v, d, n;

    if (dir) {
      v = 0; d = 1;
    } else {
      v = 128; d = (BYTE)-1;
    }
    
    n = 128;
    do {
      v += d;
      OCR1A = v; OCR1B = v;
      delay_us(100);
    } while (--n);
    

    #else
    dir = dir ? 128 : 0;
    OCR1A = (BYTE)dir; OCR1B = (BYTE)dir;
    #endif
    }

    static
    FRESULT play (
    const char dir, / Directory /
    const char
    fn / File /
    )
    {
    DWORD sz;
    FRESULT res;
    BYTE sw;
    WORD btr;

    wdt_reset();
    
    xsprintf((char*)Buff, PSTR("%s/%s"), dir, fn);
    res = pf_open((char*)Buff);     /* Open sound file */
    if (res == FR_OK) {
      sz = load_header();           /* Check file format and ready to play */
      if (sz < 1024) return 255;    /* Cannot play this file */
    
      FifoCt = 0; FifoRi = 0; FifoWi = 0;   /* Reset audio FIFO */
    
      if (!TCCR1) {             /* Enable audio out if not enabled */
        PLLCSR = 0b00000110;    /* Select PLL clock for TC1.ck */
        GTCCR =  0b01100000;    /* Enable OC1B as PWM */
        TCCR1 = MODE ? 0b01100001 : 0b00000001; /* Start TC1 and enable OC1A as PWM if needed */
        TCCR0A = 0b00000010;    /* Statr TC0 as interval timer at 2MHz */
        TCCR0B = 0b00000010;
        TIMSK = _BV(OCIE0A);
        ramp(1);
      }
    
      pf_read(0, 512 - (Fs.fptr % 512), &rb);   /* Snip sector unaligned part */
      sz -= rb;
      sw = 1;   /* Button status flag */
      do {  /* Data transfer loop */
        wdt_reset();
    
        btr = (sz > 1024) ? 1024 : (WORD)sz;/* A chunk of audio data */
        res = pf_read(0, btr, &rb); /* Forward the data into audio FIFO */
        if (rb != 1024) break;      /* Break on error or end of data */
        sz -= rb;                   /* Decrease data counter */
    
        sw <<= 1;                   /* Break on button down */
      } while ((PINB & 1) || ++sw != 1);
    }
    
    while (FifoCt) ;            /* Wait for audio FIFO empty */
    OCR1A = 128; OCR1B = 128;   /* Return output to center level */
    
    return res;
    

    }

    static
    void delay500 (void)
    {
    wdt_reset();

    TCCR0B = 0; TCCR0A = 0; /* Stop TC0 */
    
    if (TCCR1) {    /* Stop TC1 if enabled */
      ramp(0);
      TCCR1 = 0; GTCCR = 0;
    }
    
    WDTCR = _BV(WDE) | _BV(WDIE) | 0b101;   /* Set WDT to interrupt mode in timeout of 0.5s */
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);    /* Enter power down mode */
    sleep_mode();
    
    wdt_reset();
    WDTCR = _BV(WDE) | 0b110;               /* Set WDT to reset mode in timeout of 1s */
    

    }

    EMPTY_INTERRUPT(WDT_vect);

    /-----------------------------------------------------------------------/
    / Main /

    int main (void)
    {
    FRESULT res;
    char *dir;
    BYTE org_osc = OSCCAL;

    MCUSR = 0;
    WDTCR = _BV(WDE) | 0b110;   /* Enable WDT reset in timeout of 1s */
    
    PORTB = 0b101001;       /* Initialize port: - - H L H L L P */
    DDRB  = 0b111110;
    
    sei();
    
    for (;;) {
      if (pf_mount(&Fs) == FR_OK) { /* Initialize FS */
        wdt_reset();
        Buff[0] = 0;
        if (!pf_open("osccal")) pf_read(Buff, 1, &rb);  /* Adjust frequency */
        OSCCAL = org_osc + Buff[0];
    
        res = pf_opendir(&Dir, dir = "wav");    /* Open sound file directory */
        if (res == FR_NO_PATH)
          res = pf_opendir(&Dir, dir = ""); /* Open root directory */
    
        while (res == FR_OK) {              /* Repeat in the dir */
          res = pf_readdir(&Dir, 0);            /* Rewind dir */
          while (res == FR_OK) {                /* Play all wav files in the dir */
            wdt_reset();
            res = pf_readdir(&Dir, &Fno);       /* Get a dir entry */
            if (res || !Fno.fname[0]) break;    /* Break on error or end of dir */
            if (!(Fno.fattrib & (AM_DIR|AM_HID)) && strstr(Fno.fname, ".WAV"))
              res = play(dir, Fno.fname);       /* Play file */
          }
        }
      }
      delay500();           /* Delay 500ms in low power sleep mode */
    }
    

    }

     

    Last edit: Keith 2016-08-28
  • Keith

    Keith - 2016-08-20

    @Kent... Wow Atmel Studio, that is one hell of a program. I have downloaded and installed ver 7. it looks at the hex file and the C file - don't know what do with it as yet and the chances are I never will but I;m on the road to my goal.

    The Authur of the projuct has put a comment on the schematic, 'This Project requires an HVSP Programmer'. I don't seem to be able to find anything on an HVSP Programmer. Does it mean aything to you guys?

     

    Last edit: Keith 2016-08-28
  • Chris Roper

    Chris Roper - 2016-08-20

    From http://www.atmel.com/webdoc/avrdragon/avrdragon.hvsp_description.html

    "Low pin count Atmel AVR devices do not have enough IO pins to support the full Parallel Programming interface. These devices instead use HVSP programming, which is a serial version of the Parallel Programming interface."

    So basicaly it is the equivelent of ICSP in the PIC world.
    Any of the curent generation of AVR programers such as the AVR Dragon should be fine.

    Cheers
    Chris

     
  • Keith

    Keith - 2016-08-20

    Im looking at an AVR Dragon programmer. Any good ?? don't want to wast 40 quid if I can help it.

     
  • Keith

    Keith - 2016-08-20

    Just seen your post Chris, Thank you. so for you its a thumbs up for the Dragon....

     
  • Chris Roper

    Chris Roper - 2016-08-20

    Well, I don't personally have one, I am a PIC person, don't even like the Arduino :) But from what I have heard the AVR Dragon is a good programer that also doubles as a Development board, so should be good bang for the buck.

    Talking of Arduino, if you have one, there is an Arduino Sketch that allows it to work as a programer for some AVR devices. You may be able to use that rather than buy a dedicated programer.

     

    Last edit: Chris Roper 2016-08-20
  • Keith

    Keith - 2016-08-20

    Arduino - not likley - PIC through and through, bit like Blackpool Rock, still very much a newbie with PIC's though but I am getting there my programming skills are growing day by day.

    Arduino I thought that was what we called the Ice Cream Man!!!

     
  • Chris Roper

    Chris Roper - 2016-08-20

    Well Microchip now own ATMEL so we may all end up being Arduino Users :) but seriously, although I have at least 4 Arduinoes sitting on my desk, I prefer the PIC devices. They are a lot more rugged and reliable. The Arduino may be a nice toy, but if you want a device that is economical and reliable in a realworld control situation the PIC wins hands down.

     
  • kent_twt4

    kent_twt4 - 2016-08-20

    Here is the deal, someone can check me on this. The AVRISP mkII will not do HVSP, the Dragon will. I presume most all ATMEL devices use LVSP unless the RST pin (i.e. MCLR in PIC terms) needs to be used as a digital input pin, just like the PIC. Lucky for us the pk2 and pk3 normaly does PIC HVSP by default.

    My only complaint against the Dragon is all the wires, and of course if a different device is loaded then new wiring diagram needs to be consulted again.

    If the RST fuse doesn't need to be burned, or a device that's been bricked doesn't need rescuing then I prefer the AVRISP mkII.

     
  • Keith

    Keith - 2016-08-20

    Oh... That is way, way above my level of comprehension !!!

    Jings Chris... I'm putting my money with the Dragon and put up with all the wiring configs.

     
  • Chris Roper

    Chris Roper - 2016-08-21

    Well you should find it a usful tool and a reasonable development board.
    You will then, combined with Great Coaw Basic, have the ability to program and test ideas on both PIC and AVR. So I dont think your investment will be a waist of money but you may have so much fun with it that it becomes too time consuming :)

     
  • Keith

    Keith - 2016-08-23

    I'm back again looking for a pointer as to how to progam a hex file into a ATtiny45 using a Dragon programmer Atmel Studio in ISP Mode.

    Atmel Studio can see the device, I can set the fuses, but for the life of me I cannot see how or where to load my .hex file and write it to the device.....

     
  • Keith

    Keith - 2016-08-23

    I think I have done it ... Under the Memories section it allows my load in my .hex and lo and behold the program tab is visible. Jings... Thank heaveans for MicroChip and PicKit

     
  • Keith

    Keith - 2016-08-28

    Still struggling with my ATtiny 861A. The author of the code and the HEX file says the fuse settings are combined in the .HEX file which says to me that I don't need to set any fuses which in a nutshell is a blessing as the fuse section in the device programming is an absolute nightmare.

    However, what I have found is that if I load the .HEX file into Atmel Studio7 it does not amend the fuse settings in the fuse programming section - very confusing.

    Am I right in saying that it is not necessary to do anything with the fuses when it is written into the .HEX file.

    Thank God for GCG and MicroChip as this stuff looks like the work of the Devil or the ramblings of those Italian Ice Cream Men – Just one Arduino !!!

     

    Last edit: Keith 2016-08-28
  • kent_twt4

    kent_twt4 - 2016-08-28

    Is there a link to this project, blog, or? So you know what the high and low fuses are supposed to be? And reading back the fuses doesn't match what they are supposed to be?

    If you have those fuse values, have you tried to separately enter them into their respective boxes in the fuse window? They can be programed there in the High 0x00 and Low 0x00 boxes, as opposed to checking the boxes.

     
  • Keith

    Keith - 2016-08-28

    Hello Kent and thank you for replying. here is a link to the project. His/Her English is pretty good for an Oriental, but I'm sure you will get the jist of what is being described.

    http://elm-chan.org/works/sd20p/report.html

    Once again I am truelly right out of my comfort zone with this but I really want to get this up and running. I have been diddling about with the fuse patterns in the High and Low boxes and 'bricked' all but the last of my 861A's.

    Thanks once again.

    Keith

     
  • kent_twt4

    kent_twt4 - 2016-08-28

    Well it is good thing that you got the Dragon, as it can unbrick your tiny's to live another day :). They describe how to do the HV (high voltage or parallel) programming hookup in Studio /HELP /AVR Dragon. Use that now.

    I would remove the two fuse setting lines from the hex file as described on the web page. Also comment the fuse line of main.c "if you decide to rebuild or alter the original program". So the hex file is now ready to go less the fuses. The fuses need to be programmed first, copy the settings from the main.c file. By the looks of things they will be:

    FUSES = {0xC1, 0xDD, 0xFF}; /* ATtiny861 fuse bytes: Low, High, Extended.
    

    Go ahead and program those fuses after entering. Then go to the memories window and load the hex file up (i.e. the one with the fuses that were removed earlier). Hit the Program button, and you should be good to go?

     
  • Keith

    Keith - 2016-08-28

    Thanks Kent. I will have a look in the morning, my old lamps are starting to dim a bit and my bed is beckoning me.

    I'll get back to you with my results, hopefully with jubilant success.

    Keith

     
  • Keith

    Keith - 2016-08-29

    Well Kent, after spending about 14 hours on this, I write with an enormous smile of sweet success on my face. nearly 3 hours of that was taken up making jumpers and configuring the Dragon HVSP programmer. Now I know what you meant about jumpers but it was all worthwhile as I managed to Un-Brick several tiny's.

    What I did find was that although the fuses were being set in High Mid and Low boxes, it was still necessary to remove the Brown Out option and set the Oscillator to PLL as leaving these as they were would not let the code run.

    I now have the project up and running on the breadboard and I'm really chuffed. Next task is some binary addressing to operate the sound files - This bit is going on a trusty PIC 16F616 with the aid of some GCB coding. Very basic and simplified but something I can understand.

    Many Thanks for all your help and encouragement, it is really appreciated.

     

    Last edit: Keith 2016-08-29
  • Keith

    Keith - 2016-09-25

    @Kent. Hello again, can you please help. I have 'Bricked' my ATtiny85's whilst playing around with the fuse settings and I cannot remember exactly what I did when I 'De-Bricked' the ATtiny861's.

    I have re-read your post on the 28/8/16 and tried to re-locate the information from the Help/AVR Dragon but for the life of me I cannot find the information I need to rejuvenate these little beasts.

     
  • kent_twt4

    kent_twt4 - 2016-09-25

    Atmel Studio/Help/AVR Dragon/Device Connection Sheets. Then find out which one holds the ATtiny85 and use parallel/high voltage serial programming wiring diagram.

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.