Ankündigung

Einklappen
Keine Ankündigung bisher.

Starting SAMD21G18 & EEPROM

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    Starting SAMD21G18 & EEPROM

    Hello Konnekting folks,

    I have been messing around with Konnekting for a while now.
    Always with an Arduino Leonardo or Micro Pro.
    But I ran into memory issues because of all the things I wanted to do on one board.
    I read that the SAMD21G18 chip would suit me better (got myself an Adafruit Feather M0).

    I quickly learned that the SAMD21G18 doesn't have EEPROM so I got myself a EEPROM chip (PFC8582).
    And it seems to be working with some small writing and reading.

    But what are the steps to get it working with Konnekting? What code needs to be added or changed?

    Is it enough to add the following?

    Within SETUP
    Code:
    #ifdef __SAMD21G18A__
        Wire.begin();
        Konnekting.setMemoryReadFunc(&readMemory);
        Konnekting.setMemoryWriteFunc(&writeMemory);
        Konnekting.setMemoryUpdateFunc(&updateMemory);
        Konnekting.setMemoryCommitFunc(&commitMemory);
    #endif

    And seperate ...
    Code:
    // Arduino Zero has no "real" internal EEPROM,
    // so we can use an external I2C EEPROM.
    // For that we need to include Arduino's Wire.h
    #ifdef __SAMD21G18A__
    #include <Wire.h>
    
    // Example for 24AA02E64 I2C EEPROM
    int readMemory(int index) {
        byte rdata = 0xFF;
    
        Wire.beginTransmission(0x50);
        Wire.write((int) (index));
        Wire.endTransmission();
    
        Wire.requestFrom(0x50, 1);
    
        if (Wire.available()) {
            rdata = Wire.read();
        }
    
        return rdata;
    }
    
    void writeMemory(int index, int val) {
        Wire.beginTransmission(0x50);
        Wire.write((int) (index));
        Wire.write(val);
        Wire.endTransmission();
    
        delay(5); //is it needed?!
    }
    
    void updateMemory(int index, int val) {
        if (readMemory(index) != val) {
            writeMemory(index, val);
        }
    }
    
    void commitMemory() {
        // this is useful if using flash memory to reduce write cycles
        // EEPROM needs no commit, so this function is intentionally left blank
    }
    #endif
    Zuletzt geändert von RobinL; 21.09.2018, 21:47.

    #2
    Hi,
    first of all, please use the newest Konnekting Library (beta4b).
    you have to use a code for your EEPROM (external library or direct access via wire)
    Example (for beta4b): https://github.com/KONNEKTING/Konnek...PROM_24AA256.h

    It is also possible to use internal Flash with emulated EEPROM section:
    in this case download via Arduino IDE Library Manager: FlashStorage library and add this to you sketch:
    Code:
    #include "FlashAsEEPROM.h"
    #define EEPROM_EMULATION_SIZE 2048
    
    
    byte readMemory(int index) {
        return EEPROM.read(index);
    }
    
    void writeMemory(int index, byte val) {
        EEPROM.write(index, val);
    }
    
    void updateMemory(int index, byte val) {
        if (EEPROM.read(index) != val) {
            EEPROM.write(index, val);
        }
    }
    
    void commitMemory() {
        EEPROM.commit();
    }
    and this to setup():
    Code:
        Konnekting.setMemoryReadFunc(&readMemory);
        Konnekting.setMemoryWriteFunc(&writeMemory);
        Konnekting.setMemoryUpdateFunc(&updateMemory);
        Konnekting.setMemoryCommitFunc(&commitMemory);

    Kommentar


      #3


      Yep, I was still using beta 4.
      If everything was just as easy.
      At last can you tell me what the difference between Demosketch and Demosketch without pins is?

      Kommentar


        #4
        DemoSketch needs one LED pin and one Interrupt Pin dir ProgButton. DemoSketch without pin doesn't need any of that

        Kommentar

        Lädt...
        X