connecting multiple sensors on I2C

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

cross mob
Anonymous
Not applicable

Hello everyone: I am working on a project in which I want to use two accelerometers on a PSOC4 BLE. I worked with an example where an I2C is connected a single accelerometer. I want to add another accelerometer. Could anyone point to me a PSOC example that could help me understand how to connect multiple sensors on an I2C. I read about I2C bus and about master/slave concept, but did not understand a lot.

   

It would be great if you could also answer following question:

   

1. when should I use master I2C and when a slave I2C?

   

2. is it possible to have two I2C each with one accelerometer connected to four pins on PSOC? right now I have one I2C with SCL going in pin 3[5] and SDA going in pin 3[4].

   

Thanks you in advance:

   

Apoorva

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

and  name them slave? Not name but configure as master. And usually, as hli pointed out, you will need only one I2C component for both slaves. Do not assign pins to the sda and scl lines and build the project, the fitter will assign the correct pins.

   

 

   

Bob

View solution in original post

0 Likes
11 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

As long as your accelerometer supports assigning different addresses to different devices (usually by pin configuration), you can do this. If not, you need two different I2C ports (which works when your device has two I2C modules)

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

1. when should I use master I2C and when a slave I2C?

   

Usually a sensor is an I2C slave, so the PSoC will act as master.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thank you for replying Hli and Bob. Do you know if there is such an example in PSOC?

   

@Hli: how do I know that a board has multiple I2C ports such as CYBLE-022001. I searched but failed because i lack the right knowledge. and how do do i know which pins can be assigned to I2C?

   

@Bob: I would like to use PSOC as master and two accelerometers as slave. Now, do i drop multiple I2C icons on psoc creator workspace and  name them slave?

   

 

   

thank you again. apoorva

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

and  name them slave? Not name but configure as master. And usually, as hli pointed out, you will need only one I2C component for both slaves. Do not assign pins to the sda and scl lines and build the project, the fitter will assign the correct pins.

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Look at the data sheet for your device, it should state that. Or just place a second I2C component and try to compile.

Anonymous
Not applicable

Thank you so much Hli and Bob for your prompt reply. I now try what you suggested.

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

Hli and Bob. could you please have a look at my project. I added two I2C which thrown an error "two many clocks allocated for SBC" followed another error "maximu number of SBC" exceeded. What will the work around for that?

   

Thanks,

   

Apoorva

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

In Creator on the very right side is a tab named "Resource meter". This shows that you are trying to use 3 of only 2 available SCBs.

   

There is no need for 2 I2C masters, you can address up to ~100 slaves. The MPU6050 allows for setting the slave address, so you can address each module individually.

   

 

   

Bob

Anonymous
Not applicable

Thank you Bob, thats very helpful. Could you also point me to an example where an I2C is used for addressing 2 or more slaves. I went through a PSOC document on  I2C bus, and I hope I will understand better if I see an example.

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

This is too easy for creating an eyample:

   

The API I2C_MasterWriteBuf(SlaveAddress,DataPtr,Count,I2C_MODE_COMPLETE_XFER); (see I2C datasheet) contains the slave address (which is a value between 1 and 126). Look into the sensor's datasheet for the basic 7-bit address.

   

 

   

Bob

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

This is too easy for creating an example:

   

The API I2C_MasterWriteBuf(SlaveAddress,DataPtr,Count,I2C_MODE_COMPLETE_XFER); (see I2C datasheet) contains the slave address (which is a value between 1 and 126). Look into the sensor's datasheet for the basic 7-bit address.

   

 

   

Bob