Forum > Embedded - AVR
Platform eXtended Library (PXL) to AVR, howto I2C
pascalbythree:
Afther your help at this forum, i want to I2C from my Raspberry to my AVR. Using Asphyre PXL. Can anybody help me out how to use this function ? Need to convert a buffer pointer and buffersize to a Incomming String variable. Because i can not work on pointers myself.
PXL.Boards.RPi.pas
--- 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";}};} ---function TFastSPI.Read(const Buffer: Pointer; const BufferSize: Cardinal): Cardinal;begin Result := Transfer(Buffer, nil, BufferSize);end;
Own 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";}};} ---constructor TApplication.Create;begin FSystemCore := TFastSystemCore.Create; FGPIO := TFastGPIO.Create(FSystemCore); FDataPort := TFastI2C.Create(FGPIO); // I2C Write and slave commands end;
Please help... Greets, Wouter
Dzandaa:
Hi,
I don't know if it is you are waiting for (or even if this is working):
--- 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";}};} --- Str := ''; SetString(Str, PChar( Buffer), BufferSize);
B->
pascalbythree:
I forgot about Github: rpiplc_pas/native/examples/i2c_write_test.lpr
--- 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_write_test; uses sysutils, i2c; var i2cMaster: TI2cMaster; startAddr: uint16 = $38; data: TBytes; i: integer; S:String; begin 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; if i2cMaster.WriteBytes(byte(startAddr), @data[0], Length(data)) then begin WriteLn('Success: WriteBytes'); end else WriteLn('Error: WriteBytes'); i2cMaster.Free;end.
Can somebody help me out changing this code to write the S string through $38 ? Or loop and write a byte ?
--- 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(byte(startAddr), @data[0], Length(data))
in the Unit i2c.pas
--- 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";}};} ---function WriteBytes(address: byte; const data: PByte; size: byte): boolean;
cdbc:
Hi
I think you should be able to do this:
--- 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";}};} ---if i2cMaster.WriteBytes(byte(startAddr), @S[1], Length(S)) thenRegards Benny
pascalbythree:
Yay ! Again in a lucky day!
From PXL on my RPI to FPC on my AVR works fine!
Now i am going to try from AVR to FPC
You all will hear back from me soon!
Navigation
[0] Message Index
[#] Next page