You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

49 lines
963 B

#include <Arduino.h>
#include <Wire.h>
#include <AT24C32.h>
void AT24C32::begin()
{
Wire.begin();
};
uint8_t AT24C32::read(int address)
{
uint8_t result = 0;
bool read = true;
Wire.beginTransmission(AT24C32_I2C_ADDRESS);
if (Wire.endTransmission() == 0)
{
Wire.beginTransmission(AT24C32_I2C_ADDRESS);
Wire.write(address >> 8);
Wire.write(address & 0xff);
if (Wire.endTransmission() == 0)
{
Wire.requestFrom(AT24C32_I2C_ADDRESS, 1);
while (Wire.available() > 0 && read)
{
result = Wire.read();
read = false;
}
Wire.endTransmission();
}
}
return result;
}
void AT24C32::write(int address, uint8_t data)
{
Wire.beginTransmission(AT24C32_I2C_ADDRESS);
if (Wire.endTransmission() == 0)
{
Wire.beginTransmission(AT24C32_I2C_ADDRESS);
Wire.write(address >> 8);
Wire.write(address & 0xff);
Wire.write(data);
Wire.endTransmission();
delay(20);
}
}