I2C Scan

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi All,

   

I'm using the EZ-BLE modules CYBLE-214009-EVAL and CYBLE-014008-EVAL with CY8CKIT-042 PSoC® 4 Pioneer Kits.

   

I'd like to scan for any/all I2C devices connected to my device, similarly to the Arduino project "i2c_scanner" (http://playground.arduino.cc/Main/I2cScanner).

   

Each module has identical code (apart from the I2C address) utilising an SCB Multi-Master-Slave component, when one module is triggered it should scan all I2C addresses and note any successful scans.

   

I've used a modified (with UART printfs for debugging) WriteCommandPacket() function from the SCB_I2cCommMaster code example.

   

So far my methods have involved looking for error codes from WriteCommandPacket() and I2CMasterWriteBuf(), but I've not been successful

   

So my problem is that I don't know the best way to test an I2C address with the aim of determining its presence. My ideal function would be something like:             uint8 TestI2CAddress( uint8 address )              which would return boolean type values( 0u/1u ).

   

Can anyone suggest the best way to achieve my objective please?

   

Thanks,
George

0 Likes
10 Replies
Anonymous
Not applicable

Ok so..
I believe my answer lies in the I2CMasterSendStart function. I had experimented with it before but I'm getting more sensible results now.

   

Still, if anyone has a good solution to this I'm listening!

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

George, give the attached project a try. Use PuTTY @9600bd to display the results. Project probably needs selection of your PSoC chip, this is for a PSoC4-M.

   

 

   

Happy coding

   

Bob

0 Likes
Anonymous
Not applicable

Hi Bob, thanks!

   

I changed the I2C and UART components as they were not compatible with my device, I left all as default apart from I2C changed to Multi-Master-Slave. I'm using a different UART terminal (Termite @ 115.2 kbps) but that shouldn't matter, right?

   

The code runs as expected until is reaches address 8. At this point the programs hangs at I2C_I2CMasterSendStart. I added a few debugging lines to see what was going on, here's the output:

   

[0C]Scanning I2C Addresses...
Sending Start (Address: 0)
Stop sent

   

Sending Start (Address: 1)
Stop sent

   

...

   

Sending Start (Address: 7)
Stop sent

   

Sending Start (Address: 😎

   

 

   

I've tried slave addresses 0x10 and 0x14 but no difference. The I2C bus should work, hardware wise, as I've had other I2C test programs running just fine, it's just two pioneer kits linked together with 4k7 pullups on SDA & SCL.

   

Any thoughts?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Address 8 "smells" like a PSoC slave's default address.

   

Where does the program exactly stop? compile the project with optimization set to "None" and when it hangs, press the halt button and see where in I2C.c it waits for whatever.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I2C_I2C_Master.c
Line 337
while(!I2C_CHECK_INTR_MASTER(I2C_INTR_MASTER_I2C_ACK | ......

   

Something weird going on.. It all looked clear with the logic analyser but I'll check with the scope.

   

Using the code I've been playing with, which is essentially the same, the results are the same. If I start the scan at address 9 it works great.

   

Something about address 8 then. Hey I've got it. that's module's own flippin' address! I forgot to add the "ignore your own address, dummy" line.

   

Thanks Bob!

0 Likes
Anonymous
Not applicable

This highlighted that I2CSlaveSetAddress function wasn't working.

   

For anyone reading this and having issues with this function, ensure it is called after I2C_Start.

ViDv_264506
Level 5
Level 5
50 sign-ins 25 sign-ins 5 solutions authored

Hi, 

   

I have now tested the Bob's I2CScan and for DS1307 on the CY8CKIT-042 .... it works as expected.

   

The 7 bit right justified DS1307 address is scanned as 0x68 which is OK.

   

Viktor

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I am at my wit's end. I have been slaving away trying to get this Pioneer BLE board to talk to this SI7021 sensor. I stumbled across this i2c scanner and thought that my problems would be solved (or at least I would move forward). I run this code and get nothing. The address is supposed to be 0x40. This code runs and never returns anything. The serial port works as it says 'Scanning I2C Addresses". I am connected to the pins labeled 3v3 and ground and SDA on the chip is connected to P3.4 and SCL is connected to P3.5 (for the i2c bus). When I put this sensor on a teensy 3.0 and run the ADAfruit code, I get temperature and humidity. Works like a champ. Connect it to a Pioneer board and nothing. I have tried using the i2cmasterWrite/ReadByte commands to be similar to the arduino wire.write (in a different project) and I cannot get it to talk. That is why I ended up here. I get no response. Can you point out what I am doing wrong? This bus scan code does not 'see' the sensor. (when I put this sensor on the board and load the BLE beacon code, it reports temp and humidity via bluetooth just like a beacon, so I feel it must be code and not hardware)

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Did you configure your Pioneer kit to run at 3.3V using the jumper at J16?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Bob,

   

Yes, the jumper is set at 3v3. I was able to finally get i2cmasterreadbuff working to read my sensor (Si7021) in the project I was working on. If I run this code on my CY8KIT-042-BLE, I get nothing.

0 Likes