how to program an external EEPROM

by EEdy on Sat Oct 26, 2013 3:59 pm

I bought a USBtinyISP programmer from adafruit. I know how to program microcontrollers, but how do I program external EEPROM (like AT25320 ) using the USBtinyISP?

Thanks
EEdy
 
Posts: 20
Joined: Mon Jun 03, 2013 10:06 pm

Re: how to program an external EEPROM

by adafruit_support_mike on Sun Oct 27, 2013 2:25 am

Hmm.. interesting question. I don't know if it's even possible to program a AT25320 with an ISP.

The AT25320 is an SPI device, and while an ISP uses SPI to program a microcontroller, the signals the programmer generates are tailored to the uC in question. To program an AT25320, you'd need the READ and WRITE commands listed in its datasheet.

If you want a piece of dedicated hardware to do the job, the Bus Pirate would be more the tool you need: http://www.adafruit.com/products/237 . Its whole purpose is to translate commands from your computer into messages in various protocols (SPI among them).

You don't really need that though.. any Arduino can do the job. The ATmega328 has built-in hardware to support SPI communication, so it can read and write data to the AT25320 all by itself. A Trinket would be able to handle the communication, but might not be able to hold all the information you want to write into the EEPROM.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 9037
Joined: Thu Feb 11, 2010 1:51 pm

Re: how to program an external EEPROM

by DIY on Sun Oct 27, 2013 11:47 pm

I just found that you can use the USBtinyISP to input image into the external EEPROM on the SpokePOV kit, just wondering how you did that?
DIY
 
Posts: 1
Joined: Sun Oct 27, 2013 11:43 am

Re: how to program an external EEPROM

by EEdy on Mon Oct 28, 2013 2:07 pm

yea, i wonder how they manage to store image into EEPROM using USBtinyISP
EEdy
 
Posts: 20
Joined: Mon Jun 03, 2013 10:06 pm

Re: how to program an external EEPROM

by adafruit_support_mike on Tue Oct 29, 2013 1:17 am

Okay, I dug through the tutorials a little and found that you can use the USBtinyISP as a generic SPI interface. You have to look at the file usbtiny.c in the avrdude source code to really see what's going on though:

The generic SPI interface is implemented this way:

Code: Select all | TOGGLE FULL SIZE
/* Send a 4-byte SPI command to the USBtinyISP for execution
   This procedure is used by higher-level Avrdude procedures */
static int usbtiny_cmd(PROGRAMMER * pgm, unsigned char cmd[4], unsigned char res[4])
{
  int nbytes;

  // Make sure its empty so we don't read previous calls if it fails
  memset(res, '\0', 4 );

  nbytes = usb_in( pgm, USBTINY_SPI,
         (cmd[1] << 8) | cmd[0],  // convert to 16-bit words
         (cmd[3] << 8) | cmd[2],  //  "
         res, 4, 8 * PDATA(pgm)->sck_period );
  if (nbytes < 0)
    return -1;
  check_retries(pgm, "SPI command");
  if (verbose > 1) {
    // print out the data we sent and received
    fprintf(stderr, "CMD: [%02x %02x %02x %02x] [%02x %02x %02x %02x]\n",
       cmd[0], cmd[1], cmd[2], cmd[3],
       res[0], res[1], res[2], res[3] );
  }
  return ((nbytes == 4) &&      // should have read 4 bytes
     res[2] == cmd[1]);              // AVR's do a delayed-echo thing
}

It's not quite bit-banging the SPI connection, but it's close.

There are more highly optimized read/write routines for programming entire pages of an AVR's memory, but that code seems to be AVR-specific.

So.. while it is possible to program an EEPROM using just the USPtinyISP, I stand by my previous statement that the job would be easier with an Arduino or Bus Pirate.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 9037
Joined: Thu Feb 11, 2010 1:51 pm