My last topic got a little confused by the code. And i did quit with the PXL library.
For last go!: How to go from ccrause Raspberry I2C example application to ccrause AVR example application.
From Master to Slave
Can anybody adapt the code for me, so it connects ?
PS: Afther this i also need to go backwards, from my AVR to my raspberry.
Greets, Wouter van Wegen, PascalByThree
RPI code:
program wvw_i2c_write_test;
uses
sysutils, i2c;
var
i2cMaster: TI2cMaster;
i: integer;
S:String;
begin
// Starting RPI I2C master
S := 'Hello World!';
i2cMaster := TI2cMaster.Create;
if not i2cMaster.Initialize(i2c_1) then
begin
WriteLn('Error opening i2c device i2c_1');
i2cMaster.Free;
Halt(1);
end;
for i:=1 to length(S) do
begin
i2cMaster.WriteBytes($18, @S[i], Length(S));
end;
i2cMaster.Free;
end.
The AVR Code:
program i2cslavedemo;
uses
uart, i2cslave_unit, delay;
const
BAUD_Rate = 19200;
BAUD_SETTING = (((F_CPU + 4*BAUD_Rate) shr 3) div BAUD_Rate) - 1;
var
counter: byte;
procedure DataReceivedHandler(data: byte; ACK: boolean);
begin
uart_transmit('data=');
uart_transmit(chr(data));
uart_transmit(#10);
uart_transmit(#13);
end;
procedure DataRequestHandler(out data: byte; out ACK: boolean);
begin
end;
procedure ResetHandler;
begin
end;
begin
uart_init(BAUD_SETTING);
uart_transmit('Starting AVR I2C slave');
counter := 0;
i2cslave_listen($18, @DataReceivedHandler, @DataRequestHandler, @ResetHandler);
repeat
delay_ms(100);
uart_transmit('.');
uart_transmit(#10);
uart_transmit(#13);
until false;
end.