Forum > Embedded - AVR

LAST GO!: from ccrause / rpiplc_pas to ccrause / fpc-avr

(1/2) > >>

pascalbythree:
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:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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);beginend; procedure ResetHandler;beginend; 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. 

ccrause:

--- Quote from: pascalbythree on October 18, 2023, 06:11:21 pm ---Can anybody adapt the code for me, so it connects ?

--- End quote ---

What error do you get?


--- Quote ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---   for i:=1 to length(S) do   begin       i2cMaster.WriteBytes($18, @S[i], Length(S));   end; 
--- End quote ---
Change this code to:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  i2cMaster.WriteBytes($18, @S[1], Length(S));

pascalbythree:
Yay! that got to work again!, now i am going to try from AVR to RPI, the other way around.

People, you will hear back from me soon !

pascalbythree:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program i2c_read_reg; uses  sysutils, i2c; var  bus: TI2CBus;  i2cMaster: TI2cMaster;  val: byte; begin  bus := TI2CBus(1);   i2cMaster := TI2cMaster.Create;  if not i2cMaster.Initialize(bus) then  begin    writeln('Error opening i2c device: ', bus);    i2cMaster.Free;    Halt(1);  end;    if i2cMaster.ReadBytes($18, PByte(val), 255) then     begin    Writeln(IntToStr(val));  end  else    WriteLn('Error reading');   i2cMaster.Free;end.
Does anybody have code to write values from your AVR to your RPI.

Or, again, must i start the RPI code as slave ? Is it in the examples from RPIPLC_PAS? If not , somebody has code?

Thank you Mr, ccrause, and greets, Wouter van Wegen, PascalByThree



ccrause:

--- Quote from: pascalbythree on October 19, 2023, 11:20:38 am ---Does anybody have code to write values from your AVR to your RPI.

Or, again, must i start the RPI code as slave ? Is it in the examples from RPIPLC_PAS? If not , somebody has code?

--- End quote ---

It isn't clear to me whether there is a method to implement an I2C slave in user mode code. Linux have two slave examples, i2c-slave-testunit and an EEPROM simulator, both implemented as kernel drivers.

The Linux kernel documentation for the I2C slave interface suggests that user space software need to communicate with a kernel mode backend driver. Perhaps the missing piece is a generic slave backend driver where user space slaves can register and receive I2C events via some callback mechanism?

Navigation

[0] Message Index

[#] Next page

Go to full version