Recent

Author Topic: From AVR Master to RPIZERO slave, still not working... Using PXL.  (Read 636 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 266
I am back!

Afther working for it on a day everything works fine, to parse strings from a RPI Master using PXL, to a AVR Slave. Using I2C.

Except:

Now i need to do it the other way around,  to send data from my AVR over I2C to my RPI.

This is the code for the RPI:

Code: Pascal  [Select][+][-]
  1. program WVW_PXL_I2C_TEST;
  2.  
  3. uses
  4.   SysUtils, PXL.TypeDef, PXL.Boards.Types, PXL.Sysfs.UART, PXL.Boards.RPi, crt;
  5.  
  6. var    
  7.   SystemCore: TFastSystemCore;
  8.   GPIO: TFastGPIO;
  9.   PortI2C: TFastI2C;
  10.   AddrI2c, RegE: Byte; // Address of the component
  11.   value, i:byte;
  12.   s,S2:String;
  13.   counter: byte;
  14.  
  15. begin
  16.   SystemCore:= TFastSystemCore.Create;
  17.   GPIO:= TFastGPIO.Create(SystemCore);
  18.   PortI2C:= TFastI2C.Create(GPIO);
  19.   AddrI2c:= $18; // Address of my test component
  20.   PortI2C.SetAddress(AddrI2C);
  21.  
  22.     counter := 0;
  23.   repeat
  24.      counter := counter + 1;
  25.          if counter = 255 then counter := 1;
  26.          writeln(counter,  'Begin LOOP');
  27.  
  28.      
  29. //WVW ORIGNAL function ReadByteData(const Command: Byte; out Value: Byte): Boolean; override;
  30. //WVW ORIGNAL function WriteByteData(const Command, Value: Byte): Boolean; override;     
  31.          
  32.             //PortI2C.WriteByteData($18, ord(S[i]));
  33.                 if PortI2C.ReadByteData($18, value) then writeln('Value=',Value,' ', chr(value));
  34.                
  35.                 delay(55);
  36.   until keypressed;      
  37.  
  38.   PortI2C.Free;
  39.   GPIO.Free;
  40.   SystemCore.Free;  
  41. end.
  42.  

This is the code for the AVR Master:

Code: Pascal  [Select][+][-]
  1.  program WVW_AVR_MASTER;
  2.      
  3.     uses
  4.       uart, i2c, delay; {atmega328p}
  5.      
  6.     var
  7.       i2c_master: TI2CMaster;
  8.       i, x: byte;
  9.       c: char;
  10.       counter : byte;
  11.           s:String;
  12.      
  13.     begin
  14.      
  15.        // Initialize UART that is interrupt controlled
  16.        UART_Init1(115200,true);
  17.            uart_transmit('Start!');
  18.            
  19.        s:='[UART TEST STRING]';
  20.          
  21.          
  22.       i2c_master.init(I2C_50kHz);
  23.        
  24.       Counter := 0;
  25.       repeat
  26.            Counter := Counter + 1;
  27.            if counter = 100 then counter := 1;
  28.            uart_transmit(counter);
  29.                    
  30.            i2c_master.start($18, true);
  31.                    
  32.            for i:=1 to length(S) do
  33.                    begin
  34.               i2c_master.writeByte(Ord(S[i]));    
  35.                            delay_ms(1);
  36.                    end;
  37.                    
  38.            i2c_master.stop;        
  39.            uart_transmit('END LOOP');
  40.            delay_ms(5);
  41.                    
  42.       until 1=2;
  43.      
  44.     end.

Can somebody help me out getting this to work ?

Greets, Wouter van Wegen, PascalByThree.


 

TinyPortal © 2005-2018