Forum > Embedded - AVR

Platform eXtended Library (PXL) to AVR, howto I2C

<< < (2/3) > >>

pascalbythree:
I'm Back!


--- 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";}};} ---Read(const Buffer: Pointer; const BufferSize: Cardinal): Cardinal;
Anybody got a snip to receive values on the RPI from the AVR as Master ?

cdbc:
Hi
Dunno, if you want bytes or string?!? But:
--- 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";}};} ---// string firstvar  Res: cardinal;  S: string;begin {Read(const Buffer: Pointer; const BufferSize: Cardinal): Cardinal;}  setlength(S,1024);  Res:= Read(@S[1],length(S));  setlength(S,Res);  ...end;// or bytesvar   Res: cardinal;  B: TBytes;begin  setlength(B,1024);  Res:= Read(@B[0],length(B));  setlength(B,Res);  ...end; I think that should do the trick...  :D
Regards Benny

pascalbythree:
Benny? It does not seem to connect.

Can you see what i did wrong ?

Grtz...Wouter


AVR side:


--- 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_AVR_SDIE; uses  uart, i2c, delay, simplemath; var  i2c_master: TI2CMaster;  S:String;  i, value:byte;  counter:integer;  const  BAUD_Rate = 115200;   BAUD_SETTING = (((F_CPU + 4*BAUD_Rate) shr 3) div BAUD_Rate) - 1;    //****************************************************************************************************************    function IntToStr(const i: Integer): string;    begin     Str(i, Result);    end;         function StrToInt(const s: string): Integer;    var     code: Integer;    begin     Val(s, Result, code);    end;//****************************************************************************************************************               begin  uart_init1(115200,true);    i2c_master.init(I2C_50kHz);    uart_transmit('Starting up...'#13);    S := 'Hello World!';    i2c_master.start($18, false); //shl 1;    counter := 1;  repeat        counter := counter + 1;        if counter = 254 then counter := 1;    uart_transmit('Counter='+IntToStr(counter)+#10+#13);                        for i:=1 to length(S)-1 do    begin            value := ord(S[i]);        i2c_master.WriteByte(value);            delay_ms(2);                end;                    i2c_master.WriteByte(Ord(#10));        i2c_master.WriteByte(Ord(#13));         delay_ms(2);      until 1=2;    i2c_master.stop;end.

RPI Side:


--- 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_RPI_SIDE; uses  SysUtils, PXL.TypeDef, PXL.Boards.Types, PXL.Sysfs.UART, PXL.Boards.RPi, crt;  var      SystemCore: TFastSystemCore;  GPIO: TFastGPIO;  PortI2C: TFastI2C;  AddrI2c: Byte; // Address of the component  counter: byte;       Res: cardinal;  S: string;  B: TBytes; begin  SystemCore:= TFastSystemCore.Create;  GPIO:= TFastGPIO.Create(SystemCore);  PortI2C:= TFastI2C.Create(GPIO);  AddrI2c:= $18; // Address of my test component  PortI2C.SetAddress(AddrI2C);    counter := 0;  repeat     counter := counter + 1;         if counter = 255 then counter := 1;         writeln('counter='+IntToStr(counter));      setlength(S,1024);     Res := PortI2C.Read(@S[1],length(S));     setlength(S,Res);      writeln('Res=' + IntToStr(res));      writeln('S[1]='   + S[1]);                           writeln('S='   + S);                                             delay(55);  until keypressed;          PortI2C.Free;  GPIO.Free;  SystemCore.Free;  end.

DonAlfredo:
I guess you are using two I2C-masters. And that will never work.
So, the question is: why do you use a I2C-master on the AVR ?

cdbc:
Hi
What DonAlfredo says, he beat me to it and probably knows way more about this than I do  :)
Hmmm, it seems, on one side of the connection you're writing a lump of bytes using:
--- Quote ---i2c_master.WriteByte(value);
--- End quote ---
followed by a CrLf pair, over and over again.
Then on the other side of the connection, you're reading a "string" in one fell swoop?!? It seems to me, that at least you should send and receive the same datatype... Also have you checked, that you can e.g.: send 1 BYTE +crlf and receive 1 BYTE +crlf successfully? Then after this, is it a must, that you send the bytes separate, because your 'read' seems to accept a @buffer --> ? to 1 or more bytes ?
Too many unknowns, for me to figure out, you should have another look at the documentation for your kit.
Regards Benny

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version