Recent

Author Topic: Right i2C adress for example code fpc-avr/src/examples/i2c/i2ctest.pp  (Read 1090 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 266
Does anoybody kow what value to change for:

Code: Pascal  [Select][+][-]
  1. const
  2.   DS1307 = $68;

in     fpc-avr/src/examples/i2c/i2ctest.pp

With the I2C scan results as in attachment?

Greet, Wouter van Wegen, PascalByThree

Or is $68 always the right value?

Code: Pascal  [Select][+][-]
  1. procedure readDS1307;
  2. var
  3.   s, m, h: byte;
  4. begin  
  5.   i2c_master.init(I2C_100kHz);
  6.   i2c_master.start($68, I2C_ReadMode);
  7.   i2c_master.readByte(s, true);
  8.   i2c_master.readByte(m, true);
  9.   i2c_master.readByte(h, true);
  10.   i2c_master.stop;
  11.  
  12.   uart.uart_transmit('***********************'+#10+#13);
  13.   uart.uart_transmit('S: '+IntToStr(s)+#10+#13);
  14.   uart.uart_transmit('M: '+IntToStr(m)+#10+#13);
  15.   uart.uart_transmit('H: '+IntToStr(h)+#10+#13);
  16.   uart.uart_transmit('***********************'+#10+#13);
  17. end;
  18.  

The example code form FPC-AVR on Github is not working yet.

Can somebody help me debugging this stripped code?  It only displays 105 seen in this attachment.

IMG_1464_SNAP.jpg
is the fpc-avr/src/examples/i2cscan/i2cscan.pp example application result.

This is all because i am still working on the digital part of my LI-ION charger, with 4 ports on it.  Going to expand it with  relais en a nice display, temperature sensor, digital ammeter, AVR!, rotary encoder, and offcource a real time clock.

PS: The analog part is just working fine already.
« Last Edit: October 14, 2023, 08:17:06 pm by pascalbythree »

ccrause

  • Hero Member
  • *****
  • Posts: 988
Re: Right i2C adress for example code fpc-avr/src/examples/i2c/i2ctest.pp
« Reply #1 on: October 15, 2023, 08:06:29 am »
Code: Pascal  [Select][+][-]
  1. const
  2.   DS1307 = $68;

This is a mistake in the example, the address should be left adjusted as per the comment in the i2c library:
Code: Pascal  [Select][+][-]
  1.     // Address should be left adjusted 7-bit value
  2.     function start(address: byte; readTransaction: boolean): boolean;

The example has been updated with the corrected address.

Quote
With the I2C scan results as in attachment?
The address reported by i2cscan should be shifted left by one bit (multiplied by 2) for use with the i2c library, as can be seen how the address is tested and displayed in the i2c_scan procedure of the i2cscan example:
Code: Pascal  [Select][+][-]
  1. if i2c_master.start(addr shl 1, true) then
  2. begin
  3.   uart_transmit_hex(addr);
  4.   uart_transmit(' ');
  5. end

pascalbythree

  • Sr. Member
  • ****
  • Posts: 266
Re: Right i2C adress for example code fpc-avr/src/examples/i2c/i2ctest.pp
« Reply #2 on: October 15, 2023, 02:23:16 pm »
Yay! It got to work! thank you for your time, you will probably hear from me back soon.


 

TinyPortal © 2005-2018