first publish

Dependents:   eeprom_test eeprom_test MCP3204_test

24LC1025.cpp

Committer:
sashida_h
Date:
2019-11-20
Revision:
0:8047024a08c2
Child:
1:41cf2e3bb7f3

File content as of revision 0:8047024a08c2:

#include "24LC1025.h"
// 24LC64 の書き込み、読み込みテスト

//I2C  i2c(p9, p10); //p9: data, p10: clock

I2CEEprom::I2CEEprom():I2C(PB_7,PB_6)
{
  addr = 0xA0;
}
I2CEEprom::I2CEEprom(PinName data, PinName clock, int address):I2C(data, clock)
{
  addr = address;
}

void I2CEEprom::write(unsigned int address,  unsigned char data)
{
    start();
    ((I2C*)this)->write(addr);
    ((I2C*)this)->write((address>>8));
    ((I2C*)this)->write(address);
    ((I2C*)this)->write(data);
    stop();
}

unsigned char I2CEEprom::read(unsigned int address)
{
    unsigned char x;
    start();
    ((I2C*)this)->write(addr);
    ((I2C*)this)->write((address>>8));
    ((I2C*)this)->write(address);
    start();
    ((I2C*)this)->write(addr+1);
    x = ((I2C*)this)->read(0);
    stop();
    return x;
}