Hello,
I'm looking to write some code that will scan the i2c bus for devices. From what I understand from existing i2cspy implementations, you:
So I'm still learning the libraries provided by processor expert, and attempted to do this with the select slave method and receive block, so it would look like:
LDD_TDeviceData iic_handle = CI2C1_Init( &flags );
for( byte addr = 0x10; addr < 0x70; addr++ ) {
printf("S: %02x ", addr);
while( CI2C1_SelectSlaveDevice( iic_handle, LDD_I2C_ADDRTYPE_7BITS, addr ) != ERR_OK );
CI2C1_MasterSendBlock( iic_handle, NULL, 0, LDD_I2C_SEND_STOP );
while( flag == 0 );
// ...
}
Where the flags variable is set by an interrupt event, and would be checked later to see what kind of event it was. I also tried this using the non-LDD "Internal I2C" device, and found that it had a nice event for SCL Timeout, which doesn't appear to be present in the LDD version.
Has anyone tried doing something like this before? I'm going to see if I can access more fine grained control over the device by looking at the generated code and the Technical manual for the device family, but wanted to know if anyone else had tried this first.
Thanks
Accidentally posted half the message instead of the whole thing
Solved! Go to Solution.
Hi Stephen,
Yes, that's what's happening.
I have attached you an example project (with the generated sources) for the FRDM-KL25Z. The function is in ScanDevices() which calls I2C2_ScanDevice().
The project is on GitHub too: mcuoneclipse/Examples/FRDM-KL25Z/Freedom_I2CSpy at master · ErichStyger/mcuoneclipse · GitHub
I hope this helps,
Erich
I'm using that I2CSpy to scan the bus for 'unknown' devices, or to verify the I2C device address.
http://mcuoneclipse.com/2012/12/23/csi-crime-scene-investigation-with-i2cspy-and-freedom-board/
Erich
Hi Erich,
Thank you for the reply, and that's a really great post!
So after a little searching through your repo, I found this snippet:
https://github.com/ErichStyger/McuOnEclipse_PEx/blob/master/Drivers/sw/GenericI2C.drv#L1086
Which seems to be responsible for the actual check on an address. So from what I can tell, it:
Is this roughly what is happening? I haven't looked at the events file yet, its a little difficult to navigate the (*.drv) file with the PEx markup. Of course it is really cool that the PEx beans are able to make the code as flexible as it is.
Hi Stephen,
Yes, that's what's happening.
I have attached you an example project (with the generated sources) for the FRDM-KL25Z. The function is in ScanDevices() which calls I2C2_ScanDevice().
The project is on GitHub too: mcuoneclipse/Examples/FRDM-KL25Z/Freedom_I2CSpy at master · ErichStyger/mcuoneclipse · GitHub
I hope this helps,
Erich