Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:04 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Multiple I2C devices with MM2

Author Message
LewW
Newbie

Joined: 16/01/2018
Location: Australia
Posts: 15
Posted: 01:28am 12 Sep 2020
Copy link to clipboard 
Print this post

Hi all,

I have noticed that none of the Silicon Chip MM2 projects use multiple IC2 devices.

Specifically, I would like to add the DS3231 RTC to an altimeter using a BMP180.  In fact, I would like to have an RTC in any device both to keep the time and display the time on any Backpack when it's not doing anything else.   This especially comes into focus with the Backpack V3, which provides a home for a DS3231 on the main PCB.

Is it possible to drive both the DS3231 and a sensor such as the BMP180?  Does the native DS3231 support of the MM2 just hijack the I2C in such way that it cannot do anything else?  Or is there perhaps some other limitation of the I2C implementation of the MM2?

I have no doubt that anything is possible by bit banging, but I am not competent to do that sort of thing.  I'm looking for things that can be done straightforwardly using MMBASIC commands.

I would appreciate any clues you may be able to provide.  I would not be all surprised if the answer is already on the Forum somewhere, but I have not been able to find it.  

Maybe I am over-thinking it, and I should just add the DS3231 to my altimeter and see if it works?

Thankyou for reading this,

Lew.
Edited 2020-09-12 11:28 by LewW
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 02:24am 12 Sep 2020
Copy link to clipboard 
Print this post

I2C devices have addresses.
Provided that the addresses don't conflict, you can have as many devices as you wish on the one I2C port.

Some devices have a select pin which allows you to change the address so you can have 2 of the same device on the one port.
The DS3231has a different address to the BMP180 and BME280 so no problems.

BMP085_Address = &H77
BME280_ADDRESS = &H76
DS3231_Address = &H68


On the micromites, if you use the built-in RTC commands, the RTC is only interrogated at startup then the timekeeping is done by the CPU.

You don't have to use the built-in RTC commands. You could roll your own if you want to do more than the standard offering.
I have one configured as an alarm clock, starting the micromite at a preset time then putting it to sleep when the work is done.

Jim
VK7JH
MMedit
 
DaveC166
Regular Member

Joined: 13/09/2012
Location: New Zealand
Posts: 44
Posted: 02:40am 12 Sep 2020
Copy link to clipboard 
Print this post

There is allso the option of using a second I2C port. This is done with a C Function. I had to use this option because   HTU21D temp/humidity sensor modules, I2C address is not changeable. I used two HTU21D's on one MK2 umite.The C function is part of the firmware download and works fine as long as you have 3 spare digitals pins.
 
LewW
Newbie

Joined: 16/01/2018
Location: Australia
Posts: 15
Posted: 03:07am 12 Sep 2020
Copy link to clipboard 
Print this post

Hi Jim,

Thankyou very much for your very quick and helpful reply.  This has been bothering me for quite a while.  I should have posted my question years ago!

I knew that I2C could accommodate multiple devices via their addresses, but since I had never seen any one use two devices with a MM, I thought the MM implementation might have been limited.  It seems that I did GeoffG a disservice.  Sorry Geoff!

OK, I will just try it.  I usually update the time from the RTC every 10 minutes as in the SuperClock, so it will be addressed regularly.  (I also borrow the SuperClockFonts, which are great!)

I probably should try rolling my own I2C commands for the DS3231 - it might be a good way to start growing my skills.  The most ambitious thing I have done so far is just to get the temperature out of it using RTC commands.

Thanks again Jim,

Lew.
(VK2ZIP)
 
LewW
Newbie

Joined: 16/01/2018
Location: Australia
Posts: 15
Posted: 03:22am 12 Sep 2020
Copy link to clipboard 
Print this post

Hi Dave,

Thanks to you also for your reply.  I have now found that C function in my last download.  I think I was aware of it at the time, and that possibly contributed to my impression that the native I2C on the MM2 was limited.  I had not thought of the issue of needing to drive two devices with the same hard-wired addresses.

It is good to get that all into perspective, but I do have one question.  You mentioned the need for 3 digital pins.  The need for two is obvious to me, but what is the third pin used for?

Lew.
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 04:51pm 12 Sep 2020
Copy link to clipboard 
Print this post

  LewW said  Hi all,

I have noticed that none of the Silicon Chip MM2 projects use multiple IC2 devices.

Specifically, I would like to add the DS3231 RTC to an altimeter using a BMP180.  In fact, I would like to have an RTC in any device both to keep the time and display the time on any Backpack when it's not doing anything else.   This especially comes into focus with the Backpack V3, which provides a home for a DS3231 on the main PCB.


same meat, different gravy. A DS3231 and HTU21D happily co-habiting.



As already pointed out, each device has an address and will ignore traffic not for it's own address.
 
IanT

Senior Member

Joined: 29/11/2016
Location: United Kingdom
Posts: 108
Posted: 10:19pm 12 Sep 2020
Copy link to clipboard 
Print this post

Hi Lew,

First the disclaimer - I'm learning this stuff too (and have been for some time I'm afraid) - so I'm not a Guru.

I have a different problem with I2C which involves controlling four I2C slave devices (from a single 170) that share a single unique (e.g. fixed) I2C address. Everything was put on hold for a while, as I puzzled how best to get around this issue but then I discovered I could possibly use an I2C multiplex switch. I think this should work in my case and I've just ordered some small PCBs that have this chip pre-mounted.

This chip is the TI TCA9548A (Low-Voltage 8-Channel I2C Switch) and I think I should be able to hook up my BDLC chips to the MM using one of them. We'll see once I get to actually try it. Anyway - I thought it was worth mentioning that this I2C switch exists and might be helpful in solving some I2C device address problems/conflicts.

Regards,

IanT (MMB White Belt)
 
DaveC166
Regular Member

Joined: 13/09/2012
Location: New Zealand
Posts: 44
Posted: 03:54am 14 Sep 2020
Copy link to clipboard 
Print this post

Sorrt Lew, that was a typo, only two digital pins are needed for the second I2c port
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 06:37am 14 Sep 2020
Copy link to clipboard 
Print this post

Not exactly demo code, but this program reads temperature and humidity from a TI sensor, (I2C) and stores it in EEPROM (I2C).

code
PicomiteVGA PETSCII ROBOTS
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025