first commit
This commit is contained in:
35
dev/eep.cpp
Normal file
35
dev/eep.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "i2c.h"
|
||||
|
||||
#include "eep.h"
|
||||
|
||||
static const unsigned char EEP_Addr = 0x50; // AT24C256
|
||||
|
||||
static inline short Rev16(short v)
|
||||
{
|
||||
asm("REV16 %1, %0" : "=r" (v) : "r" (v)); // v = v<<8 | v>>8;
|
||||
return v;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void EEP_Init() // AT24C256
|
||||
{
|
||||
I2C1_Init();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void EEP_Read(unsigned short Addr, void* Data, unsigned short Size)
|
||||
{
|
||||
Addr=Rev16(Addr);
|
||||
I2C1_Write(EEP_Addr, &Addr, 2);
|
||||
I2C1_Read(EEP_Addr, Data, Size);
|
||||
I2C1_Stop();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void EEP_Write(unsigned short Addr, const void* Data, unsigned short Size)
|
||||
{
|
||||
Addr=Rev16(Addr);
|
||||
I2C1_Write2(EEP_Addr, &Addr, 2, Data, Size);
|
||||
I2C1_Stop();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
Reference in New Issue
Block a user