is there some on-line examples somewhere on how to interface to devices (RTC, sensors) and EEPROM from a FreePascal program?Start here: https://wiki.freepascal.org/Lazarus_on_Raspberry_Pi
I would like to know if there is a way to read more data than one byte per operation.If there is no ready to use library providing such high level feature, then you have to get out of your developer comfort zone, dig into the world of electronics and learn the craft of reading datasheets. For example, if your i2c eeprom device is 24LCxx family (other families are sometimes quite different), then you find datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/I2C%20Serial%20EE%20Family%20Data%20Sheet%2021930C.pdf) for it on the net and try to understand as much as you can. For the question you have, you search for the supported features and see what is of interest. Datasheet says that Byte Write, Page Write, Current Address Read, Random Read and Sequential Read I2C operations (functions) are available. So, for the most optimal block read/write you should use these 24LCxx internal I2C functions. For sub optimal block read/write you could forget all said, and just use a simple loop to read/write individual bytes. Since I2C protocol is byte based anyway, my wild guess is that in best case optimized read/write is about 2 times faster. If you can live without such speed then you can happily get away with suboptimal simple read/write loop. If speed is important, then you should also check what is the highest speed that your I2C eeprom chip supports and then initialize your I2C channel to that speed. You will agree that reading something with 100kbits/s is not he same as reading it with 400 Kbit/s, 1Mbit/s or 3,2 Mbit/s.
If there is no ready to use library providing such high level feature, then you have to get out of your developer comfort zone, dig into the world of electronics and learn the craft of reading datasheets.Thanks for the pointers, but the problem I have is that I cannot get my head around the operating system interface in this case.
@BosseB: You can use the pascalio lib. The usage is easier to understand than the code you posted.Thanks, could you specify how I can find pascalio. Googling it draws a blank for me...
By the way, be careful with the address, some datasheets talk about the 7-bit address, which is the first 7 bit of a byte, others talk about the 8-bit address which contains the least significant bit for the direction (read/write). So your $50 could be a $A0 or a $28 as well.
As avra said, you have to check the datasheet on how to access the chip. Normally you read (write) a byte or word out of (into) a register. The sequence then is something like slave-adress/register-address/data with start/stop conditions and acknowledge in certain order in between. A library like pascalio provides functions for that certain sequence already. E.g. WriteRegByte(aRegAddress, aData);
The chip may offer a continuous reading of the eeprom data (sending the address only once), but then you have to understand the protokoll, so its easier to do it "bytewise" with the library function (calling it for each byte you want to read). In the end its only a question of speed.
@avra,QuoteIf there is no ready to use library providing such high level feature, then you have to get out of your developer comfort zone, dig into the world of electronics and learn the craft of reading datasheets.Thanks for the pointers, but the problem I have is that I cannot get my head around the operating system interface in this case.
What do you mean by "usual trick"?@avra,QuoteIf there is no ready to use library providing such high level feature, then you have to get out of your developer comfort zone, dig into the world of electronics and learn the craft of reading datasheets.Thanks for the pointers, but the problem I have is that I cannot get my head around the operating system interface in this case.
Bo, are you doing your usual trick of not reading all the messages posted in response to your query? I gave you an example of the low-level OS interface several days ago- did you read it?
Then I don't get it why don't you try out any of the microcontroller like libraries mentioned in the RPi wiki page? It should be much closer to your PIC experience then BaseUnix.QuoteIf there is no ready to use library providing such high level feature, then you have to get out of your developer comfort zone, dig into the world of electronics and learn the craft of reading datasheets.Thanks for the pointers, but the problem I have is that I cannot get my head around the operating system interface in this case.
I have done a fair bit of embedded microcontroller development (Microchip PIC) including interfacing the I2C EEPROM devices.
Thanks, could you specify how I can find pascalio. Googling it draws a blank for me...Here's the link:
Because on Linux the I/O is owned by the operating system as I understand it. On a PIC or AVR one can pretty much do whatever on the pins without having to invoke the OS.Then I don't get it why don't you try out any of the microcontroller like libraries mentioned in the RPi wiki page? It should be much closer to your PIC experience then BaseUnix.QuoteIf there is no ready to use library providing such high level feature, then you have to get out of your developer comfort zone, dig into the world of electronics and learn the craft of reading datasheets.Thanks for the pointers, but the problem I have is that I cannot get my head around the operating system interface in this case.
I have done a fair bit of embedded microcontroller development (Microchip PIC) including interfacing the I2C EEPROM devices.
If you know what you are doing or if you use a proper library for your work, and you do not need nanosecond bit banging or some other hard core real time, then there is not much difference.Because on Linux the I/O is owned by the operating system as I understand it. On a PIC or AVR one can pretty much do whatever on the pins without having to invoke the OS.Then I don't get it why don't you try out any of the microcontroller like libraries mentioned in the RPi wiki page? It should be much closer to your PIC experience then BaseUnix.QuoteIf there is no ready to use library providing such high level feature, then you have to get out of your developer comfort zone, dig into the world of electronics and learn the craft of reading datasheets.Thanks for the pointers, but the problem I have is that I cannot get my head around the operating system interface in this case.
I have done a fair bit of embedded microcontroller development (Microchip PIC) including interfacing the I2C EEPROM devices.
I have just connected my EEPROM to the RPi and verified it appears on address $50.With rpi_hal (https://github.com/rudiratlos/rpi-hal) library for example (mentioned on wiki page I talked earlier), the core code without initialization would look something like this:
So now I will have to make a small test program with min overhead to test this.
Well done. Can you throw any light on why you appeared to be getting erroneous results from i2cdump?Well, I do not know the command i2cdump very well myself but I found it existed on my system (probably part of some i2c tools).
MarkMLl