Recent

Author Topic: Other version of github: fpc-avr/src/library/i2cslave_unit.pas  (Read 1151 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 261
Long time ago:
Does anybody have a version of the i2c slave unit on github to send bytes from slave to master ? maybe a blocking variant ?
without re-firing the i2c stack.
Greets, Wouter van Wegen

TRon

  • Hero Member
  • *****
  • Posts: 2930
Re: Other version of github: fpc-avr/src/library/i2cslave_unit.pas
« Reply #1 on: June 18, 2024, 10:59:55 am »
Does anybody have a version of the i2c slave unit on github to send bytes from slave to master ? maybe a blocking variant ?
You mean this one ?

BTW: I believe this is your 4th or 5th attempt to start defying master-slave logic so I am starting to wonder if you understand the master-slave concept. A master is the one who determines what is going to happen and while the communication itself might be bi-directional a slave has no business to start a conversation unless you specifically reverse the roles. How these roles can be setup/changed depends on the used hardware and software.

You can somewhat get around that by letting the master poll the slaves requesting for information, e.g. the master that constantly asks "talk to me if you got something to do for me".
« Last Edit: June 18, 2024, 12:01:54 pm by TRon »

pascalbythree

  • Sr. Member
  • ****
  • Posts: 261
Re: Other version of github: fpc-avr/src/library/i2cslave_unit.pas
« Reply #2 on: June 19, 2024, 11:48:16 am »
Can you compile this with FPC 3.3.1 for AVR ?

ccrause

  • Hero Member
  • *****
  • Posts: 921
Re: Other version of github: fpc-avr/src/library/i2cslave_unit.pas
« Reply #3 on: June 19, 2024, 12:30:54 pm »
Can you compile this with FPC 3.3.1 for AVR ?
No. First sentence from project readme:
Quote
This program is written for Turbo Pascal 3 for CP/M

MarkMLl

  • Hero Member
  • *****
  • Posts: 7123
Re: Other version of github: fpc-avr/src/library/i2cslave_unit.pas
« Reply #4 on: June 19, 2024, 12:32:24 pm »
Can you compile this with FPC 3.3.1 for AVR ?

Have you read the datasheets for the chips being used? Are your hardware skills sufficient to connect those chips to the other devices you're using?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

pascalbythree

  • Sr. Member
  • ****
  • Posts: 261
Re: Other version of github: fpc-avr/src/library/i2cslave_unit.pas
« Reply #5 on: June 20, 2024, 02:02:10 pm »
reformulation:

So is possible at all to write bytes from a AVR SLAVE to a AVR or RPI Master ? without refire the i2c stack?

so without this principle? :



Code: Pascal  [Select][+][-]
  1.     begin
  2.       i2cslave_listen(thisaddress, ...);
  3.       repeat
  4.         // Perform routine tasks here while waiting for either an I2C message
  5.         // or something to to transmit to other controller
  6.      
  7.         if (something important to transmit to other controller) then
  8.         begin
  9.           i2cslave_stop;
  10.           i2c_master.init(I2C_50kHz);
  11.           if i2c_master.start(otheraddress, I2C_WriteMode) then
  12.           begin
  13.             i2c_master.writeByte(x);
  14.             i2c_master.stop;
  15.           end;
  16.           i2cslave_listen(thisaddress, ...);
  17.         end;
  18.       until false;
  19.     end.
« Last Edit: June 20, 2024, 02:06:57 pm by pascalbythree »

MarkMLl

  • Hero Member
  • *****
  • Posts: 7123
Re: Other version of github: fpc-avr/src/library/i2cslave_unit.pas
« Reply #6 on: June 20, 2024, 03:29:22 pm »
So is possible at all to write bytes from a AVR SLAVE to a AVR or RPI Master ? without refire the i2c stack?

No.

The master can ask for a byte or a message of known length, but the slave cannot proffer one unsolicited.

This is exactly the same as a pure poll/select discipline as implemented by many mainframe systems.

It is very much not the same as e.g. SCSI or IEEE-488 (GPIB, or HP-IB for old-timers), where any device ("host") on the bus can take control.

Also there is no broadcast facility, and each slave on the bus usually responds to a single hardwired address. **

If you want a device which only has slave hardware to behave as a master, then you will have to bitbang it or add additional chips. For the details you will need to refer to the relevant datasheets: something which the rest of us have noticed you are extremely reluctant to do.

** Added: I want to qualify that, in the interest of fairness and accuracy. If you buy a sensor chip of some sort, then its I2C address will usually be "designed into" the chip although it might bring some signals out to allow one of several predefined addresses to be selected. Hence, as an example, the translator described at https://hackaday.com/2024/04/05/extenders-and-translators-for-your-i2c-toolkit/ . If you have something programmable like an AVR chip, then the slave address will normally be set in an internal register.

I want to further add that I have done a certain amount of I2C and SPI interfacing using the kernel facilities of the RPi and PC. The latter case obviously required an extra (USB-connected) chip with appropriate kernel support.

MarkMLl
« Last Edit: June 20, 2024, 03:47:18 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

pascalbythree

  • Sr. Member
  • ****
  • Posts: 261
Re: Other version of github: fpc-avr/src/library/i2cslave_unit.pas
« Reply #7 on: June 20, 2024, 05:44:57 pm »
Thank you very much, then i am continuing like this.

 

TinyPortal © 2005-2018