Changeset 34c57e8 in avrstuff for EPRoxygen/at29c040.cpp


Ignore:
Timestamp:
Jul 7, 2012, 6:19:53 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
a6ae6ac
Parents:
d09030d
Message:

More work.

  • Power on/off sequence OK
  • Code to read chip ID written, but not working yet...

git-svn-id: svn://pulkomandy.tk/avrstuff@59 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EPRoxygen/at29c040.cpp

    rd09030d r34c57e8  
    11#include "at29c040.h"
     2
     3#include <stdio.h>
     4#include <unistd.h>
     5
     6
     7AT29C040::AT29C040()
     8        : Device()
     9{
     10}
     11
     12void AT29C040::power()
     13{
     14        Device::write(CTRL, 0b10011111 | CTRLmask);
     15        Device::write(VOLT, 0b11001000 | VOLTmask);
     16}
     17
     18void Device::shutdown()
     19{
     20        // All pins of the ROM are put either in high-Z, or 0V when it's not
     21        // possible
     22        Device::write(CTRL, 0x62);
     23        Device::write(VOLT, 0x7F);
     24        outb(port + 2, NONE);
     25}
    226
    327void AT29C040::read(const char* filename)
    428{
     29        if (!checkId()) {
     30                return;
     31        }
    532}
    633
    734void AT29C040::write(const char* filename)
    835{
     36        if (!checkId()) {
     37                return;
     38        }
    939}
    1040
    1141void AT29C040::erase(void)
    1242{
     43        if (!checkId()) {
     44                return;
     45        }
     46
     47        puts("Perfomring chip erase...");
    1348}
     49
     50bool AT29C040::checkId(void)
     51{
     52        // Chip enable
     53        Device::write(CTRL, CTRLmask | CE);
     54                // Address bits low, WE = 1, CE = 0, OE = 1
     55                // TC and TD = 1
     56        Device::write(VOLT, VOLTmask);
     57                // D and A OE = 0
     58                // VPP config ?
     59                // TA, TB, TE, TF = ?
     60
     61        wr16(0x5555, 0xAA);
     62        wr16(0x2AAA, 0x55);
     63        wr16(0x5555, 0x90);
     64
     65        // clear DOE for reading
     66        Device::write(VOLT, DOE | VOLTmask);
     67       
     68        usleep(10000);
     69
     70        // Read the result now
     71        Device::write(ADR0, 0x00);
     72        Device::write(ADR1, 0x00);
     73        Device::write(CTRL, WE | CE | CTRLmask);
     74        uint8_t manufacturer = Device::read();
     75
     76        getchar();
     77
     78        Device::write(CTRL, OE | WE | CE | CTRLmask);
     79        Device::write(ADR0, 0x01);
     80        Device::write(CTRL, WE | CE | CTRLmask);
     81
     82        uint8_t product = Device::read();
     83
     84        // re enable DOE, we are going to write again...
     85        Device::write(CTRL, WE | OE | CE | CTRLmask);
     86        Device::write(VOLT, VOLTmask);
     87
     88        wr16(0x5555, 0xAA);
     89        wr16(0x2AAA, 0x55);
     90        wr16(0x5555, 0xF0);
     91        usleep(10000);
     92
     93        // Chip disable - we're done !
     94        Device::write(CTRL, 0xFF | CTRLmask);
     95       
     96        bool ok = (manufacturer == 0x1F && product == 0xA4);
     97
     98        if (!ok)
     99        {
     100                fprintf(stderr, "Chip ID %X:%X does not match expected %X:%X\n",
     101                        manufacturer, product, 0x1F, 0xA4);
     102        } else {
     103                fprintf(stderr, "AT29C040 detected successfully!\n");
     104        }
     105
     106        return ok;
     107}
Note: See TracChangeset for help on using the changeset viewer.