Changeset a6ae6ac in avrstuff


Ignore:
Timestamp:
Jul 9, 2012, 11:05:43 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
16cf6ff
Parents:
34c57e8
Message:

Still not working...
Added very agressive timing, fixed some potential glitches, but still not enough to even read the device ID !

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

Location:
EPRoxygen
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • EPRoxygen/at29c040.cpp

    r34c57e8 ra6ae6ac  
    1414        Device::write(CTRL, 0b10011111 | CTRLmask);
    1515        Device::write(VOLT, 0b11001000 | VOLTmask);
     16        outb(port + 2, NONE);
    1617}
    1718
     
    2021        // All pins of the ROM are put either in high-Z, or 0V when it's not
    2122        // possible
    22         Device::write(CTRL, 0x62);
    23         Device::write(VOLT, 0x7F);
     23        Device::write(CTRL, 0b01100010);
     24        Device::write(VOLT, 0b01111111);
    2425        outb(port + 2, NONE);
    2526}
     
    5152{
    5253        // Chip enable
    53         Device::write(CTRL, CTRLmask | CE);
     54        Device::write(CTRL, CTRLmask | WE | OE | CE | A17);
    5455                // Address bits low, WE = 1, CE = 0, OE = 1
    5556                // TC and TD = 1
     
    6061
    6162        wr16(0x5555, 0xAA);
    62         wr16(0x2AAA, 0x55);
     63        wr16(0xAAAA, 0x55);
    6364        wr16(0x5555, 0x90);
    6465
     
    7071        // Read the result now
    7172        Device::write(ADR0, 0x00);
    72         Device::write(ADR1, 0x00);
    73         Device::write(CTRL, WE | CE | CTRLmask);
     73                        usleep(1000);
     74        Device::write(ADR1, 0x00 ^ A13);
     75                        usleep(1000);
     76        Device::write(CTRL, WE | A17 | CTRLmask);
     77                        usleep(1000);
    7478        uint8_t manufacturer = Device::read();
    7579
    76         getchar();
    7780
    78         Device::write(CTRL, OE | WE | CE | CTRLmask);
     81        Device::write(CTRL, CE | OE | WE | A17 | CTRLmask);
     82                        usleep(1000);
    7983        Device::write(ADR0, 0x01);
    80         Device::write(CTRL, WE | CE | CTRLmask);
     84                        usleep(1000);
     85        Device::write(CTRL, WE | A17 | CTRLmask);
     86                        usleep(1000);
    8187
    8288        uint8_t product = Device::read();
    8389
     90        Device::write(CTRL, CE | WE | OE | A17 | CTRLmask);
     91                        usleep(1000);
    8492        // re enable DOE, we are going to write again...
    85         Device::write(CTRL, WE | OE | CE | CTRLmask);
    8693        Device::write(VOLT, VOLTmask);
     94                        usleep(1000);
    8795
    8896        wr16(0x5555, 0xAA);
    89         wr16(0x2AAA, 0x55);
     97        wr16(0xAAAA, 0x55);
    9098        wr16(0x5555, 0xF0);
    9199        usleep(10000);
     
    93101        // Chip disable - we're done !
    94102        Device::write(CTRL, 0xFF | CTRLmask);
     103                        usleep(1000);
    95104       
    96105        bool ok = (manufacturer == 0x1F && product == 0xA4);
  • EPRoxygen/at29c040.h

    r34c57e8 ra6ae6ac  
    1717                inline void wr16(uint16_t addr, uint8_t val)
    1818                {
     19                        Device::write(CTRL, A17 | CE | WE | OE | CTRLmask);
     20                        usleep(10000);
     21
     22                        Device::write(ADR1, (addr >> 8) ^ A13);
     23                        usleep(10000);
    1924                        Device::write(ADR0, addr);
    20                         Device::write(ADR1, addr >> 8);
    21 
    22                         Device::write(CTRL, OE | CTRLmask);
     25                        usleep(10000);
    2326
    2427                        Device::write(DATA, val);
     28                        usleep(10000);
     29                        Device::write(CTRL, A17 | OE | CTRLmask);
     30                        usleep(10000);
    2531
    26                         Device::write(CTRL, WE | OE | CTRLmask);
     32printf("W %X %X", addr, val);
     33getchar();
     34                        Device::write(CTRL, A17 | CE | WE | OE | CTRLmask);
     35                        usleep(10000);
    2736                }
    2837
  • EPRoxygen/device.h

    r34c57e8 ra6ae6ac  
    77#include <stdio.h>
    88#include <stdint.h>
     9#include <unistd.h>
    910
    1011// FreeBSD
     
    4243        protected:
    4344                typedef enum {
    44                         NONE =  0b0101, /* Nothing selected */
    45                         NYBLE = 0b0010, /* Read low nyble */
     45                        NONE =  0b0011, /* Nothing selected */
     46                        NYBLE = 0b0100, /* Read low nyble */
    4647                                /* When 0, status reg shows D0.3
    4748                                 * When 1, status reg shows D4.7
    4849                                 */
    49                         CTRL =  0b0011, /* Control reg. */
     50                        CTRL =  0b0101, /* Control reg. */
    5051                                /* b0: A16
    51                                  * b1: /A17
     52                                 * b1: /A17 (A17 is reversed !)
    5253                                 * b2: WE
    5354                                 * b3: A18
     
    7172                                 * b7: VCC enable (1 = power ON)
    7273                                 */
    73                         ADR0 =  0b1011, /* Low address byte A0.7 */
     74                        ADR0 =  0b1101, /* Low address byte A0.7 */
    7475                        DATA =  0b1110, /* Data byte */
    7576                        ADR1 =  0b1111, /* High address byte A8.15 */
     77                                /* A13 is reversed ! (also used as VCC pin in smaller packages)
     78                                 */
    7679                } Register;
     80
     81                static const uint8_t A13 = 1 << 5;
    7782
    7883                typedef enum {
     
    102107                static inline void write(const Register reg, const uint8_t val)
    103108                {
    104                         // The register latches the data only when another register gets
    105                         // selected. If this is a problem, select the NONE reg after
    106                         // writing !
     109                        // To avoid glitches, first set the bits that select the register,
     110                        // then enable the output. And disable the output when we are done
     111                        // while not touching the selected reg. This is the only way to
     112                        // avoid glitches (another reg may be selected long enough for
     113                        // losing some bits)
     114                        outb(port, val);
     115                        usleep(1000);
     116                        outb(port + 2, reg ^ 4);
     117                        usleep(1000);
    107118                        outb(port + 2, reg);
    108                         outb(port, val);
     119                        usleep(1000);
     120                        outb(port + 2, reg ^ 4);
     121                        usleep(1000);
    109122                }
    110123
    111124                static inline uint8_t read()
    112125                {
    113                         uint8_t byte = (inb(port + 1) ^ 0x80) & 0xF0;
     126                        outb(port+2, NYBLE ^ 4);
     127                        usleep(1000);
     128                        uint8_t byte = inb(port + 1) & 0xF0;
    114129
    115130                        outb(port+2, NYBLE);
    116                         byte |= (inb(port + 1) ^ 0x80) >> 4;
    117                         return byte;
     131                        usleep(1000);
     132                        byte |= inb(port + 1) >> 4;
     133printf("R %X", byte ^ 0x88);
     134getchar();
     135                        outb(port+2, NYBLE ^ 4);
     136                        usleep(1000);
     137                        return byte ^ 0x88;
    118138                }
    119139
     140                static int port;
    120141        private:
    121                 static int port;
    122142};
    123143
Note: See TracChangeset for help on using the changeset viewer.