Hi everyone,
I have a question for the VM guys -- I'm planning on using an I2C bus on my next autonomous robot, and the Squeak machine I'm going to use (www.gumstix.com) has a hardware I2C interface, with a driver for it in Linux. As far as I can tell, the I2C port looks just like another device in Linux, so I'm hoping I can just use the serial port with a different com port #.
Any thoughts?
Later, Jon
-------------------------------------------------------------- Jon Hylands Jon@huv.com http://www.huv.com/jon
Project: Micro Seeker (Micro Autonomous Underwater Vehicle) http://www.huv.com
"Jon" == Jon Hylands jon@huv.com writes:
Jon> As far as I can tell, the I2C port looks just like another device Jon> in Linux, so I'm hoping I can just use the serial port with a Jon> different com port #.
This is the way to use it. You will use different ioctl though, for example to tell your i2c driver which device you want to talk to.
Sam
On Wednesday 27 October 2004 8:45 am, Jon Hylands wrote:
I have a question for the VM guys -- I'm planning on using an I2C bus on my next autonomous robot, and the Squeak machine I'm going to use (www.gumstix.com) has a hardware I2C interface, with a driver for it in Linux. As far as I can tell, the I2C port looks just like another device in Linux, so I'm hoping I can just use the serial port with a different com port #.
Any thoughts?
Yes. It won't work. You'll have to use FFI or write a plugin.
I'd probably try using FFI first and only write a plugin if you absolutely *have* to.
For one thing, the i2c doesn't look like serial, because of the address/data separation (each i2c message has an address and a direction), the master/slave separation, and the concept of messages.
I wrote a Linux kernel driver for an i2c interface, and also a Perl module for i2c on Linux at one point. Using the 'net as my backup device since I can't find it on my system any more, I find:
http://perlmonks.thepen.com/99568.html
It appears to concentrate on SMBus, which is a protocol on top of I2C that smart batteries, etc. use. But it might be enlightening if you can stand the Perl. Just substitute the non-smbus functions for the smbus ones I used.
It's easiest to look at the files in linux-whatever/Documentation/i2c/ if you want to do this stuff. Just download the corresponding kernel source file.
The most useful is Documentation/i2c/dev-interface because it outlines what the i2c-dev module provides as the interface for the /dev/i2c* devices. It even gives a complete userspace example in C.
That's what I worked from to do the Perl driver.
Note that it helps to have a digital storage scope, or at least a microcontroller set up to dump i2c bus information to a serial port.
On Wednesday 27 October 2004 8:45 am, Jon Hylands wrote:
Hi everyone,
I have a question for the VM guys -- I'm planning on using an I2C bus on my next autonomous robot, and the Squeak machine I'm going to use (www.gumstix.com) has a hardware I2C interface, with a driver for it in Linux. As far as I can tell, the I2C port looks just like another device in Linux, so I'm hoping I can just use the serial port with a different com port #.
Ah yes, I remember some more...
You can use open/close/read/write/ioctl
However, I don't know if we have an interface to ioctl (this would be a good thing to have, though!). Perhaps it's in OSProcess. Or you could use FFI.
From the Documentation/i2c/dev-interface file:
Usually, i2c devices are controlled by a kernel driver. But it is also possible to access all devices on an adapter from userspace, through the /dev interface. You need to load module i2c-dev for this.
Each registered i2c adapter gets a number, counting from 0. You can examine /proc/bus/i2c to see what number corresponds to which adapter. I2C device files are character device files with major device number 89 and a minor device number corresponding to the number assigned as explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ..., i2c-10, ...). All 256 minor device numbers are reserved for i2c.
[snip C example]
The following IOCTLs are defined and fully supported (see also i2c-dev.h and i2c.h):
ioctl(file,I2C_SLAVE,long addr) Change slave address. The address is passed in the 7 lower bits of the argument (except for 10 bit addresses, passed in the 10 lower bits in this case).
ioctl(file,I2C_TENBIT,long select) Selects ten bit addresses if select not equals 0, selects normal 7 bit addresses if select equals 0. Default 0.
ioctl(file,I2C_PEC,long select) Selects SMBus PEC (packet error checking) generation and verification if select not equals 0, disables if select equals 0. Default 0. Used only for SMBus transactions.
ioctl(file,I2C_FUNCS,unsigned long *funcs) Gets the adapter functionality and puts it in *funcs.
ioctl(file,I2C_RDWR,struct i2c_ioctl_rdwr_data *msgset)
Do combined read/write transaction without stop in between. The argument is a pointer to a struct i2c_ioctl_rdwr_data {
struct i2c_msg *msgs; /* ptr to array of simple messages */ int nmsgs; /* number of messages to exchange */ }
The msgs[] themselves contain further pointers into data buffers. The function will write or read data to or from that buffers depending on whether the I2C_M_RD flag is set in a particular message or not. The slave address and whether to use ten bit address mode has to be set in each message, overriding the values set with the above ioctl's.
Other values are NOT supported at this moment, except for I2C_SMBUS, which you should never directly call; instead, use the access functions below.
You can do plain i2c transactions by using read(2) and write(2) calls. You do not need to pass the address byte; instead, set it through ioctl I2C_SLAVE before you try to access the device.
On Oct 29, 2004, at 1:57 PM, Ned Konz wrote:
On Wednesday 27 October 2004 8:45 am, Jon Hylands wrote:
Hi everyone,
I have a question for the VM guys -- I'm planning on using an I2C bus on my next autonomous robot, and the Squeak machine I'm going to use (www.gumstix.com) has a hardware I2C interface, with a driver for it in Linux. As far as I can tell, the I2C port looks just like another device in Linux, so I'm hoping I can just use the serial port with a different com port #.
Ah yes, I remember some more...
You can use open/close/read/write/ioctl
However, I don't know if we have an interface to ioctl (this would be a good thing to have, though!). Perhaps it's in OSProcess. Or you could use FFI.
I believe an interface to ioctl, open/read/write is in the extended serial port support found on squeak map.
-- ======================================================================== === John M. McIntosh johnmci@smalltalkconsulting.com 1-800-477-2659 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com ======================================================================== ===
Hi Jon,
I send you a library made by students in University of Caen, for the project SqueakBot (an educative robotic plateform in Squeak). We use an i2c module called supermec connected to the parallel port, maybe this library could help you. However the parallel and serial port will soon disappear, I think, replaced by usb port, and we are thinking on a solution based on usb<->i2c interface...
Regards, Samir
http://www.planete-sciences.org/robot/ressources/produits/supermec/supermec.... (with electronic schema)
http://www.squeaksource.com/SqueakBot/ (code available soon !)
"Jon" == Jon Hylands jon@huv.com writes:
Jon> Hi everyone,
Jon> I have a question for the VM guys -- I'm planning on using an Jon> I2C bus on my next autonomous robot, and the Squeak machine Jon> I'm going to use (www.gumstix.com) has a hardware I2C Jon> interface, with a driver for it in Linux. As far as I can Jon> tell, the I2C port looks just like another device in Linux, Jon> so I'm hoping I can just use the serial port with a different Jon> com port #.
Jon> Any thoughts?
Jon> Later, Jon
squeak-dev@lists.squeakfoundation.org