tessel / t2-firmware

Firmware for Tessel 2's SAMD21 coprocessor and related SoC code
Other
95 stars 32 forks source link

Get i2c address #235

Open rwaldron opened 7 years ago

rwaldron commented 7 years ago

Originally filed here: https://github.com/tessel/t2-cli/issues/1257

@opkiler22789:

Hello, Is there any way to get i2c address? In the likeness of i2c_scanner?

rwaldron commented 7 years ago

There is no way to scan i2c addresses in the manner that i2c_scanner does, but I'm wondering if provide a similar (possibly simpler) alternative? I'm going to put together a rough sketch this week.

HipsterBrown commented 7 years ago

Is this something that would mostly happen on the SAMD21 (the C firmware) with event messages back to the SoC (Node.js firmware)?

rwaldron commented 7 years ago

Yes, that's correct. The JS API would just be a wrapper around some command that is sent to SAMD21, the command would do whatever test is necessary on the SAMD21 and respond with the outcome.

fivdi commented 7 years ago

Would it not be possible to loop over all I2C addresses calling i2cConfig and then i2cReadOnce for each address. After calling i2cReadOnce, wait for either an error to be emitted indicating that there is no device at the address or an event to be emitted indicating that a there is a device at the address.

This is probably a bit of hack and it may leave state.i2c full of junk that's not needed. Reading information from a device may also have unwanted side effects on the device. On the other hand it might work!

It's probably of little help, but i2c-bus has scan and scanSync methods that use the SMBus Receive Byte protocol to scan for devices. The Linux i2cdetect -y -r <bus-number> command also uses the SMBus Receive Byte protocol to scan for devices.

rwaldron commented 7 years ago

@fivdi the JS runs on the mediatek mt7620n and communicates with the samd21 via domain socket. The entire i2c stack exists on samd21 and there is presently no response produced when a program attempts to write (via a message sent over the socket) to a non-existent i2c peripheral address.

const tessel = require('tessel');

const txb = new Buffer([0xff]);
const i2c = new tessel.port.A.I2C(0x01);

i2c.transfer(txb, 1, (error, data) => {
  // Never executed, because no response ever occurs. 
});
rwaldron commented 7 years ago

https://github.com/tessel/t2-firmware/blob/master/firmware/port.c#L454-L460