Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:54 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 : Sharing I2C with the RTC (PicoMite)

Author Message
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2950
Posted: 10:15am 05 Jul 2022
Copy link to clipboard 
Print this post

Hi all,

My current design I am working on, (now onto its 3rd revision) has the RTC and a BMP180 pressure sensor sharing the same I2C pins.

The BMP180 works fine when the SYSTEM I2C is disabled but of course the RTC won’t respond to RTC GETTIME etc.

Does anyone have any routines that can access the RTC chip (a DS3231) without having to use SYSTEM I2C (and built in commands) to Read and Write time and date to and from the RTC?

The other I2C port is being used for a serial device (ESP8266-Mini).

I see that Peter has just released a beta test of bitbanging serial on any pin so this is one possibility, I can move the ESP over to a bit banged pair but I would need to do another set of PCBs to implement it.

Just thinking of a software solution,

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 10:45am 05 Jul 2022
Copy link to clipboard 
Print this post

It should be able to use SYSTEM I2C, I think, but you can't use I2C OPEN and I2C CLOSE commands. It should also have a different address to the RTC.
Edited 2022-07-05 20:49 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 11:17am 05 Jul 2022
Copy link to clipboard 
Print this post

Hi Mick and Mick,

On the picomite VGA I have

OPTION SYSTEM I2C GP14,GP15
OPTION RTC AUTO ENABLE

And I can read (from the same GP14/GP15 pins) a TI HDC2080 (temperature/humidity sensor).

So it seems the I2C port can be used for other devices.

You do NOT duplicate SETPIN sda,scl,I2C2 becuase these already have been set by the OPTION SYSTEM I2C.
You do not have to I2C2 OPEN speed,timeout

You only write and read, as if all above has already happened (which it has by the OPTION setting).

I2C2 WRITE xxx,x,x,x,x
I2C2 READ  xxx,x,x,x

Good luck...

Volhout

P.S. DO NOT CLOSE THE I2C port....you loose the RTC. also...
Edited 2022-07-05 21:19 by Volhout
PicomiteVGA PETSCII ROBOTS
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2950
Posted: 11:31am 05 Jul 2022
Copy link to clipboard 
Print this post

Hi All,

Thank you Mick (the other Mick) and Volhout, of course I was trying to open the I2C I will try the bmp tomorrow without trying to open it.

Kind Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 12:35pm 05 Jul 2022
Copy link to clipboard 
Print this post

Hi Mick - all good your end?

I belive that your original query is moot following the posts above, but just to answer your original raw-access code, found this in the original library. It's for a 1307 so you might need to tweak addresses or something and it was for the origial maximite so there will be language tweaks required but it'll give you the drift:

http://www.fruitoftheshed.com/MMBasic.DS1307-Real-Time-Clock-part-of-the-original-MMBasic-library.ashx
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2950
Posted: 12:52pm 05 Jul 2022
Copy link to clipboard 
Print this post

Thank you Capn,

I did a search but there were several zillion pages and I knew there would be some code before RTC became a part of the language.

But as you say it may now be a moot point as it looks like I was approaching it incorrectly.

I will keep you all updated on the results.

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2950
Posted: 11:10pm 05 Jul 2022
Copy link to clipboard 
Print this post

GDay All,

I can report you are indeed correct, I can access the BMP180 whilst still having the SYSTEM I2C setting.




Note that this was some old code written by AndrewG for the F4 (I didnt change the print string) but what I am happy about is that the BMP180 reads perfectly.

Thank you all for the quick response and leading me along the correct path.

Kind Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 11:26pm 05 Jul 2022
Copy link to clipboard 
Print this post

Can you post your code, Mick--or a link to Andrew's? I've just run across a BMP180 module, and this may be a good time to try it out.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 871
Posted: 10:51am 06 Jul 2022
Copy link to clipboard 
Print this post

Hi Lizby,
I've just noticed this and will reply fully tomorrow. It is based on TasyJim's code .

Cheers,

Andrew
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2950
Posted: 12:44am 07 Jul 2022
Copy link to clipboard 
Print this post

Hi Lizby, All,

As I said it was code I got from AndrewG and he has stated he got it from TassyJim and he stated..... (I was going to say he got it from Johnny Walker.. Ohh I just did say that.   )

Anyway here is the code I used
'MMEDIT!!! Basic Version = ARmite_H7_5.05.03
'MMEDIT!!! Port = COM4:115200:10,300
'MMEDIT!!! Device = ARmite_H7_5.05.03
 ' Barometer for PicoMuP.BAS
 '
 ' Loosly based on Barometer v16.BAS but cut right down
 
 RTC gettime
 
 Dim String Version = "1"
 dim Integer Flag
 
 ' BMP180 specific
 Dim BMPData(2)  ' setup and store data from BMP180
 Dim cal(11)     ' calibration data array
 oss = 0         ' over sampling (0 to 3)
 ' start of 11 BP calibration values
 BMP180calMEM = &HAA   '
 BMP180address = &H77  ' BMP180 address
 BMP180control = &HF4  ' BMP180 control register
 BMP180temp = &H2E     ' BMP180 temperature command
 BMP180pres = &H34     ' BMP180 pressure command
 BMP180pres = BMP180pres + oss*&H40  ' adjust command for oversampling
 BMP180reading = &HF6  ' register for results of reading
 
 ' Start the program
 CLS

 ' Not used when SYSTEM I2C enabled   SetPin gp2,gp3,I2C2

 Text MM.HRes/2, MM.VRes/2 - 20, "Barometer for PicoMuP v"+ Version, CM, 4, 1, RGB(white)
 print "Barometer for PicoMuP v"; Version; " started at "; Time$
 
 ' enable I2C2. Use slower speeds for long leads
' Not used when SYSTEM I2C enabled  I2C2 OPEN 400, 200
 Pause 20                ' Let it catch its breath
 z = calibrate_bmp180()  ' Extract calibration constants, "z" is not used itself but it invokes calibration
 Pause 1000              ' initial one second pause (required)
 
 '  VAR Restore ' Restores the saved parameters (DisplayNbr, ZoomLev, Temp_Upper, Temp_Lower, tdst and TZ)
 
 Atmos = Cint(pressure(oss)/100)
 print Atmos ;" at ";Time$
 Flag = 0
 
 '  'MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM Main program loop start it on a zero second
 Do
   If Not Flag And Mid$(TIME$, 7, 2) = "00" then  'A new Minute
     Flag = 1
     Atmos = Cint(pressure(oss)/100)
     print Atmos ;" at ";Time$
   End If
   If Mid$(TIME$, 7, 2) = "01" Then Flag = 0
 Loop
 '  'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
 'End
 '
 '''''''''''''''''''''''''
 
Function calibrate_bmp180()
 ' extract bmp180 calibration constants
 Local n, calMEM
 calMEM= BMP180calMEM
 For n = 1 To 11
   ' first calibration location
   I2C2 WRITE BMP180address, 0, 1, calMEM
   Pause 1
   I2C2 READ BMP180address, 0, 2, BMPData(0)
   cal(n) = BMPData(0)*256 + BMPData(1)
   If n < 4 Or n > 6 Then
     ' need to convert some to signed numbers
     If (cal(n) > 32767) Then
       cal(n) = cal(n) - 65536
     EndIf
   EndIf
   Pause 1
   ' advance to the next calibration location
   calMEM = calMEM + 2
 Next n
End Function
 
Function temperature()
 ' returns the temperature in degrees C to one decimal place
 Local UT, x1, x2, b5
 I2C2 WRITE BMP180address, 0, 2, BMP180control, BMP180temp
 Pause 5
 I2C2 WRITE BMP180address, 0, 1, BMP180reading
 I2C2 READ BMP180address, 0, 2, BMPData(0)
 UT = BMPData(0)*256 + BMPData(1)
 'calculate true temperature
 x1= Int( (UT-cal(6))*cal(5)/32768)
 x2=Int( cal(10)*2048/(x1+cal(11)))
 b5=x1+x2
 temperature = Int((b5+8)/16)/10
End Function  'temperature()
 
Function pressure(oss)
 ' atmospheric pressure in inches of mercury
 Local UT, UP, x1, x2, x3, b5, b6, b7, pres, p
 pres = BMP180pres + oss * &H40
 I2C2 WRITE BMP180address, 0, 2, BMP180control, BMP180temp
 Pause 5
 I2C2 WRITE BMP180address, 0, 1, BMP180reading
 I2C2 READ BMP180address, 0, 2, BMPData(0)
 UT = BMPData(0) * 256 + BMPData(1)
 I2C2 WRITE BMP180address, 0, 2, BMP180control, pres
 ' different oversampling requires different reading times
 If (oss = 0) Then
   ' ulta low power
   Pause 5
 ElseIf (oss = 1) Then
   ' standard
   Pause 8
 ElseIf (oss = 2) Then
   ' high resolution
   Pause 14
 Else
   ' ulta high resolution
   Pause 26
 EndIf
 I2C2 WRITE BMP180address, 0, 1, BMP180reading
 I2C2 READ BMP180address, 0, 2, BMPData(0)
 UP = BMPData(0) * 256 + BMPData(1)
 I2C2 WRITE BMP180address, 0, 1, BMP180reading+2
 I2C2 READ BMP180address, 0, 1, BMPData(0)
 UP = (UP * 256 + BMPData(0)) / 2^(8 - oss)
 ' calculate true temperature
 x1 = Int((UT - cal(6)) * cal(5) / 32768)
 x2 = Int(cal(10) * 2048 / (x1 + cal(11)))
 b5 = x1 + x2
 t = Int((b5 + 8) / 16) / 10
 ' calculate true atmospheric pressure
 b6 = b5 - 4000
 x1 = Int((cal(8) * (b6 * b6 / 4096)) / 2048)
 x2 = Int(cal(2) * b6 / 2048)
 x3 = x1 + x2
 b3 = Int(((cal(1) * 4 + x3) * 2^oss + 2) / 4)
 x1 = Int(cal(3) * b6 / 8192)
 x2 = Int((cal(7) * (b6 * b6 / 4096)) / 65536)
 x3 = Int(((x1 + x2) + 2) / 4)
 b4 = Int(cal(4) * x3 / 32768 + cal(4))
 b7 = Int((UP - b3) * (50000 / 2^oss))
 p = Int((b7 * 2) / b4)
 x1 = Int(Int(p / 256) * Int(p / 256))
 x1 = Int((x1 * 3038) / 65536)
 x2 = Int((-7357 * p) / 65536)
 pressure = Int(p + (x1 + x2 + 3791) / 16)
End Function


In my case (for my new board I am working on) we are using I2C2 on Pico Pins GP2 and GP3. It responds to RTC GETTIME with no issues either

Kind Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 12:54am 07 Jul 2022
Copy link to clipboard 
Print this post

Thank you, Mick. Late now, and I probably won't get to it until tomorrow.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 871
Posted: 07:23am 07 Jul 2022
Copy link to clipboard 
Print this post

Lizby,
Mick kindly agreed to forward the code to you because, after I pressed the go button, I realised that I don't have a BMP180 to test any changes on. (Jackie and I are living in a hotel for a few more weeks and I have few of my mites or tools).

I'm happy to answer any questions etc and welcome any suggestions.
All the clever bits of the code are Jim's and all the crappy bits are mine (plus some of the later from Mick).

Cheers,

Andrew
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 07:30am 07 Jul 2022
Copy link to clipboard 
Print this post

If I have done anything 'clever' it's because "I stand on the shoulders of giants", to paraphrase a well known quote.

The code was written before we had integers in the toolbox hence the copious use of INTs.
The code is the same for the BMP085

Jim
VK7JH
MMedit
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2950
Posted: 07:31am 07 Jul 2022
Copy link to clipboard 
Print this post

Hi All,

  Andrew_G said  all the crappy bits are mine (plus some of the later from Mick).


Andrew, You meant EXTRA CRAPPY parts are Micks.

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
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