Recent

Author Topic: Extra beginners help with memory addresses I2C on RPI3 and FPC-AVR  (Read 4340 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
Code: Pascal  [Select][+][-]
  1.   //***************** WVW I2C ********************************
  2.   SystemCore:= TFastSystemCore.Create;
  3.   GPIO:= TFastGPIO.Create(SystemCore);
  4.   PortI2C:= TFastI2C.Create(GPIO);
  5.   AddrI2c:= $1E; // Address of my test component
  6.   PortI2C.SetAddress(AddrI2C);
  7.   //*************************************************


Code: Pascal  [Select][+][-]
  1.   //******************* WVW I2C ****************************
  2.   RegE:= Hex2Dec('78'); // I use a TEdit to load the register
  3.   Val := random(255);
  4.   if (val>ord('a')) and (val<ord('z')) then
  5.   begin
  6.      Writeln('VAL = '+IntToStr(Val)+' - '+chr(val));
  7.      PortI2C.WriteByteData(RegE, val);
  8.   end;
  9.   //*******************************************************

Jow FPC engineers!
Can anybody help with trying the right memory adresses for:

AddrI2c:= $1E;

RegE:= Hex2Dec('78');

I am trying to I2C and i need ultra simple replies to get it to work
Greetz Wouter!

PS aftherwards i need to work on my FPC-AVR code, to also set up the right addresses there also.
« Last Edit: December 13, 2021, 01:06:49 pm by pascalbythree »

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
Re: Extra beginners help with memory addresses I2C on RPI3 and FPC-AVR
« Reply #1 on: December 13, 2021, 02:29:18 pm »
Code: Pascal  [Select][+][-]
  1. program WVW_BURN;
  2.  
  3. uses
  4.   uart, i2c, delay; {atmega328p}
  5.  
  6. var
  7.   i2c_master: TI2CMaster;
  8.   x: byte;
  9.   c: char;
  10.   counter : byte;
  11.  
  12. begin
  13.  
  14.    // Initialize UART that is interrupt controlled
  15.    UART_Init1(9600,true);
  16.    uart_transmit('WVW UART TEST STRING  ');
  17.      
  18.      
  19.   i2c_master.init(I2C_100kHz);
  20.    
  21.   Counter := 0;
  22.   repeat
  23.        Counter := Counter + 1;
  24.        if counter = 100 then counter := 1;
  25.        uart_transmit('Inside MAIN loop'#10#13);
  26.        uart_transmit('Counter = ');  uart_transmit(counter); uart_transmit(#10#13);      
  27.      
  28.        i2c_master.start($1E, true);    
  29.        i2c_master.readByte(x, false);    
  30.        i2c_master.stop;        
  31.              
  32.        uart_transmit('I2C Vallue = '); uart_transmit(x);  uart_transmit(#10#13);        
  33.        
  34.        uart_transmit(#10#13);      
  35.        
  36.        delay_ms(55);
  37.              
  38.   until false;
  39.  
  40. end.


This is the code for the AVR side. Can anybody screen what to change? to make them connect.

This is the I2C unit at the AVR side:

Code: Pascal  [Select][+][-]
  1. unit i2c;
  2.  
  3. interface
  4.  
  5. uses atmega328p;
  6.  
  7. type
  8.   { TI2CMaster }
  9.   TI2CMaster = object
  10.     retVal: byte;
  11.     procedure init(bitRate: byte);
  12.     // Address should be left adjusted 7-bit value
  13.     function start(address: byte; readTransaction: boolean): boolean;
  14.     function readByte( data: byte; ack: boolean): boolean;
  15.     function writeByte(data: byte): boolean;
  16.     function stop: boolean;
  17.   end;
  18.  
« Last Edit: December 13, 2021, 02:38:46 pm by pascalbythree »

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Extra beginners help with memory addresses I2C on RPI3 and FPC-AVR
« Reply #2 on: December 14, 2021, 11:54:11 am »
Seems you have on both sides a I²C master implemented?

 

TinyPortal © 2005-2018