Skip to content
Snippets Groups Projects
Commit f4b31b88 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Add 24LC64 EEPROM driver

parent e7f10247
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,11 @@ ifneq ($(findstring am2320,${drivers}), )
COMMON_FLAGS += -DDRIVER_AM2320
endif
ifneq ($(findstring eeprom24lc64,${drivers}), )
TARGETS += src/driver/eeprom24lc64.cc
COMMON_FLAGS += -DDRIVER_EEPROM24LC64
endif
ifneq ($(findstring max44006,${drivers}), )
TARGETS += src/driver/max44006.cc
COMMON_FLAGS += -DDRIVER_MAX44006
......
#ifndef EEPROM24LC64_H
#define EEPROM24LC64_H
class EEPROM24LC64 {
private:
EEPROM24LC64(const EEPROM24LC64 &copy);
unsigned char const address;
unsigned char txbuf[34];
public:
EEPROM24LC64(unsigned char const addr) : address(addr) {}
void writePage(unsigned short addr, char *buf);
void readPage(unsigned short addr, char *buf);
};
extern EEPROM24LC64 eeprom24lc64;
#endif
......@@ -12,6 +12,9 @@
#ifdef DRIVER_AM2320
#include "driver/am2320.h"
#endif
#ifdef DRIVER_EEPROM24LC64
#include "driver/eeprom24lc64.h"
#endif
#ifdef DRIVER_MAX44009
#include "driver/max44009.h"
#endif
......@@ -40,6 +43,16 @@ void loop(void)
kout.printf_float(max44009.getLux());
kout << endl;
#endif
#ifdef DRIVER_EEPROM24LC64
char buf[33];
static unsigned char page = 0;
eeprom24lc64.writePage(page, "Hello, World! Und so weiter, lol");
arch.delay_ms(10);
eeprom24lc64.readPage(page, buf);
buf[32] = '\0';
kout << "Address " << page << ": " << buf << endl;
page++;
#endif
#ifdef DRIVER_MMSIMPLE
moody.toggleBlue();
#endif
......
#include <stdlib.h>
#include "driver/eeprom24lc64.h"
#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C)
#include "driver/i2c.h"
#else
#include "driver/soft_i2c.h"
#endif
void EEPROM24LC64::readPage(unsigned short addr, char *data)
{
txbuf[0] = addr >> 8;
txbuf[1] = addr & 0x00ff;
i2c.xmit(address, 2, txbuf, 32, (unsigned char *)data);
}
void EEPROM24LC64::writePage(unsigned short addr, char *data)
{
txbuf[0] = addr >> 8;
txbuf[1] = addr & 0x00ff;
for (unsigned char i = 0; i < 32; i++) {
txbuf[i+2] = data[i];
}
i2c.xmit(address, 34, txbuf, 0, NULL);
}
EEPROM24LC64 eeprom24lc64(0x50);
......@@ -140,6 +140,8 @@ signed char SoftI2C::xmit(unsigned char address,
SoftI2C i2c(GPIO::d7, GPIO::d8);
#elif MULTIPASS_ARCH_arduino_nano
SoftI2C i2c(GPIO::pc4, GPIO::pc5);
#elif MULTIPASS_ARCH_blinkenrocket
SoftI2C i2c(GPIO::pc4, GPIO::pc5);
#elif MULTIPASS_ARCH_msp430fr5969lp
SoftI2C i2c(GPIO::p1_6, GPIO::p1_7);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment