I explore the MMB MX4 and want make some write-read operation on the EEPROM 24AA01 (12C).
I want write a real variable (in fact is ADC result) in EEPROM and be able to read back. For the write operation i have use the "in line" function lo,hi,higher and highest but for read back, those function dosent exist. Normally, with 8 bit PIC, i use the ORG trick (4 byte var sharing the same memory space than a real var) but i cant use it with a 32 bit memory PIC... so i have try this :
Code: Select all
function EEPROM_24AA01_Read(EEAddr : byte) : byte; // adapted from example for lv-P32MX v6
begin
I2C1_Start(); // issue I2C start signal
I2C1_Write(0xA0); // send byte via I2C (device address + W)
I2C1_Write(EEAddr); // send byte (data address)
I2C1_Restart(); // issue I2C signal repeated start
I2C1_Write(0xA1); // send byte (device address + R)
result := I2C1_Read(1); // Read the data (NO acknowledge)
I2C1_Stop();
delay_ms(5); // small delay between read action if serial
end;
procedure B_read_eepromClick();
var tempo2 : real;
var temp_byte : byte ;
begin
for i := 3 downto 0 do // real = 4 byte = 4 adress
case i of // operation on bit to transfert the 4 bytes in one real
3 :
begin // highest
temp_byte := EEPROM_24AA01_Read(i);
for j := 31 downto 24 do
begin
kk := j - 24;
tempo2.j := temp_byte.kk ; <<<<-----compiler error msg....
end;
end;
2 :
begin //higher
temp_byte := EEPROM_24AA01_Read(i);
for j := 23 downto 16 do
begin
kk := j - 16
tempo2.j := temp_byte.kk ;
end;
end;
1:
begin // hi
temp_byte := EEPROM_24AA01_Read(i);
for j := 15 downto 8 do
begin
kk : j - 8
tempo2.j := temp_byte.kk ;
end;
end;
0:
begin //lo
temp_byte := EEPROM_24AA01_Read(i);
for j := 7 downto 0 do
tempo2.j := temp_byte.j ;
end;
end; // end case
end;
Code: Select all
129 341 Operator "shl" not applicable to these operands "1" temp_sensor_events_code.mpas
Thx for any hlp