Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

I2C BUS question

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Thu May 06, 2021 4:45 pm    Post subject: I2C BUS question Reply with quote

Hi,
Before I draw a PCB, I need some clarifications:
I'm going to use config I2Cbus, on port A of a 1284P I would like to know if I can also use the hard I2C bus portC.0 and portC.1
I Think yes but ...
Thank you for your answer
JP :wink:

(BASCOM-AVR version : 2.0.8.3 )

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Thu May 06, 2021 6:55 pm    Post subject: Re: I2C BUS question Reply with quote

Duval JP wrote:
I Think yes but ...

I think no.

The logical side of it: hard TWI, as well as soft I2C use the same commands like I2CStart, I2CWByte a.s.o. , thus to use multiple channels there must be a mechanism to select the proper channel.
Solution for multibus I2C is to set the channel in front of the I2C command(s).
Code:
i2cbus = 1
i2cinit

What channel number would you use to switch to hard I2C?
Hard I2C has no channel number. (XMega plays a special role)
You can't also omit "i2cbus = 1" to switch to hardware, the i2cbus-variable and thus the channel will stay the same until you change it.
See the problem?

You can use soft-I2C for both ports. Additionally you can still use the hard TWI on PortC, but you can not use the hard TWI with Bascom commands.
Means you have to set up all proper routines and control all the hardware registers yourself.
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Fri May 07, 2021 7:56 am    Post subject: Reply with quote

Thanks MWS for your clear answers.

Sometimes I forget to reason logically.

I am going to use for an application 4 sensors that have the same I2C address hence the use of I2Cbus.
But I also need an I2C address for an RTC.
I will try with a breadboard:

3 sensors with the same address and 1 with the same address + the RTC address.

JP

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri May 07, 2021 9:10 am    Post subject: Reply with quote

There are specialized chips for that such of "address conflicts"
If this is only hobby "one or two units" project then use TCA9548A or simillar.
Only if cost of one of the "thousants" piece matter then it is worth to write those routines.
... Or maybe you have a lot of time to spent on your favoured hobby Very Happy
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri May 07, 2021 12:17 pm    Post subject: Reply with quote

Duval JP wrote:
3 sensors with the same address and 1 with the same address + the RTC address.

If you don't want to spare pins, you can give each of the 5 slaves its very own channel, afaics multibus supports 16 channels.


Last edited by MWS on Fri May 07, 2021 12:27 pm; edited 1 time in total
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri May 07, 2021 12:26 pm    Post subject: Reply with quote

EDC wrote:
There are specialized chips for that such of "address conflicts"
If this is only hobby "one or two units" project then use TCA9548A or simillar.
Only if cost of one of the "thousants" piece matter then it is worth to write those routines.
... Or maybe you have a lot of time to spent on your favoured hobby Very Happy

The one and only reason would be, if he runs out of free pins, otherwise the plain solution is to use multibus I2C for everything, as it's most cost- and time-effective.
I see no requirement to use the hard-TWI module for the described setup.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum