Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:56 02 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 : DS3231 woes.

Author Message
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 08:55pm 19 Apr 2021
Copy link to clipboard 
Print this post

Hi everyone,
I am trying to use the 1Hz output ("SQW") from a DS3231 RTC module. I have the module plugged into the sockets on an MM+ E100 board, and intend to trigger a 1Hz interrupt - using the SETPIN instruction for a +ve edge interrupt - on pin 50.
( My MM+ E100 is a V1D, running MMBasic v5.05.03.)

Using MMBasic's I2C instructions :-
     PIN(66)=0
     SETPIN 66,DOUT
     I2C OPEN 100,500                  ' I2C 100KHz, timeout 500ms.
     I2C WRITE &B1101000,0,2,&H0E,&H00    ' I2C Write, Address D0 hex, Option 0, 2 Bytes, 0E and 00 Hex.
     I2C CLOSE                         ' I2C close.

There is a burst of activity on the clock and data lines, but no required o/p.
( The read variable MM.I2C = 0, showing the Write to be successful? )

The code should address the chip's Control register 0E hex, writing all zeros, which should enable the Square wave o/p at 1Hz. I don't get the RTC's SQW pin to output, which is stuck HIGH. I have a 10KOhm pull-up on this open drain pin.

The RTC module has 4.7KOhm pull-ups on SCL and SDA, and the MM+ E100 gets its time and date reliably at switch-on.
I also have an AM2302 Humidity/Temp module and a BMP180 Pressure/Temp module on the I2C bus - both also read reliably.

Please can anyone suggest what I might be missing here ?

With regards, Paul.
Nothing so constant as change.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 09:21pm 19 Apr 2021
Copy link to clipboard 
Print this post

This is code I used a while ago:
 ' rtc as pulse
 dim n, interval, config1
 interval = 30
 RTC GETREG &h0E, config1
 'print bin$(config1,8)
 config1 = config1 and &b11100011
 RTC SETREG &h0E, config1
 setpin 9, dout
 pin(9) = 0
 setpin 10, intl, tick, pullup
 
 do
 loop
 
sub tick
 if n mod interval = 1 then
   pulse 9, 50
   print "*"
 endif
 n = n + 1
end sub


I am sending &b11100011 plus whatever was already set. This is different to your bits.

RTC pulse out connected to pin 10 on the MM
pin 9 on the MM used to output a pulse for the CRO to monitor.

You may need to change the pins to suit the Exp100

Jim
VK7JH
MMedit
 
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 10:37pm 19 Apr 2021
Copy link to clipboard 
Print this post

Hi TassyJim,
Many thanks for your code. I patched the GETREG/SETREG section into mine - but without success unfortunately. The commented PRINT bin$(config1,8) reports 00000000 - as expected from the spec.

I have a GUI LED onscreen, which flashes via the interrupt call on pin 50. This works - as proved by shorting pin 50 to 0V.

With regards, Paul.
Nothing so constant as change.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 01:59am 20 Apr 2021
Copy link to clipboard 
Print this post

Hi Bowden_P
Here is what I got from a "fresh" RTC module.

> rtc gettime :? time$
11:45:03
> RTC GETREG &h0E, config1 : print bin$(config1,8)
00011100
>
Put that value for config1 in the second half of TassyJim's code and see what happens. If the magic smoke doesn't escape let me know, I could use the 1 pps o/p too.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 02:09am 20 Apr 2021
Copy link to clipboard 
Print this post

I can confirm that pin-50 on the E100 board, is directly connected to the RTC module SQW pin, so once you get the register bits set correctly, that pin should indeed be the pin getting pulsed, so you have the correct pin.

Keep us posted.  It's been a LONG time since I used the SQW output on one of those RTC modules, but I know I did used to use that feature, and would have just set address &h0E to zero with RTC SETREG &h0E, 0 - which simply sets all eight bits to zero, then it should enable the SQW output, but as I say - its been years since I played with the 1Hz output on those modules.
Smoke makes things work. When the smoke gets out, it stops!
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 03:41am 20 Apr 2021
Copy link to clipboard 
Print this post

Yes of course, I'm as thick as two planks. Adding the numbers:-

> ? bin$((&b00011100 and &b11100011),8)
00000000
>

Tried it and now have 1Hz o/p.

> RTC SETREG &h0E, 0 'for 1Hz SQW
>
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 03:52am 20 Apr 2021
Copy link to clipboard 
Print this post

Does the RTC module have the square-wave pin actually wired?
I have some modules that I have had to add a jumper to get the output.

I don't have an Exp100 so not sure which module it normally uses.

Jim
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 08:45am 20 Apr 2021
Copy link to clipboard 
Print this post

YAY!  

Well done, phil99.  

@ Jim: THIS is the module that the E100 uses, less the right-angled pin-header.
Smoke makes things work. When the smoke gets out, it stops!
 
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 04:19pm 20 Apr 2021
Copy link to clipboard 
Print this post

Hi everyone,
Many thanks for all your replies. There's an ancient saying dating back to the dawn of electronics that "Things TEND to work better when they're plugged in.", and this is a related failure - full marks to TassyJim. I had checked continuity from the module SQW pin to the PIC, and indeed had my 'scope connected to the same module pin. I guess you have spotted my error now - not checking continuity right up to the chip's actual pin 3. It's not connected on this module!

Patching in the connection has the 1Hz outputting now.

Sad to say I bought 2 modules together some time back - they look remarkably similar, but the other as yet unused one DOES have the SQW connection! Just sod's law I guess, that I picked out the one I did.

I'll play with the I2C or SETREG ways of addressing the DS3231, to see if they both work - hopefully they both do.

Many thanks again for your interest and replies - I'm relieved it's now working, Paul.
Nothing so constant as change.
 
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 04:45pm 20 Apr 2021
Copy link to clipboard 
Print this post

Hi everyone,
I can confirm that either the GETREG/SETREG or I2C commands work for this module - as you would expect! It's just a bit more bother when reading, to use 4 x I2C commands than the single GETREG one!

All the best, Paul.
Nothing so constant as change.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 09:02pm 20 Apr 2021
Copy link to clipboard 
Print this post

  Bowden_P said  
Sad to say I bought 2 modules together some time back - they look remarkably similar, but the other as yet unused one DOES have the SQW connection! Just sod's law I guess, that I picked out the one I did.

The joys of eBay shopping!
VK7JH
MMedit
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 01:33am 21 Apr 2021
Copy link to clipboard 
Print this post

If you ever need to get back to 'Factory Fresh' here is the lot.

> for N=&H00 to &H12 : rtc getreg N,M% : ? N,hex$(N,2),M%,hex$(M%,2),bin$(M%,8) :next
Address DATA
0      00       48     30      00110000
1      01       57     39      00111001
2      02       16     10      00010000
3      03       4      04      00000100
4      04       33     21      00100001
5      05       4      04      00000100
6      06       33     21      00100001
7      07       0      00      00000000
8      08       253    FD      11111101
9      09       255    FF      11111111
10     0A       255    FF      11111111
11     0B       255    FF      11111111
12     0C       254    FE      11111110
13     0D       255    FF      11111111
14     0E       28     1C      00011100        <set this one to 0 for 1Hz
15     0F       139    8B      10001011
16     10       0      00      00000000
17     11       11     0B      00001011
18     12       64     40      01000000
 
Bowden_P
Senior Member

Joined: 20/03/2019
Location: United Kingdom
Posts: 162
Posted: 04:33pm 21 Apr 2021
Copy link to clipboard 
Print this post

Hi Phil99,
Thanks for the listing and output. I have pasted it into a file, and am keeping it with the datasheet for future reference.

This device is the first I2C bus one I have tried using own-written code with, so am pleased to have gotten over that "hurdle", albeit simple, although the cause of the problem wasn't with me at all!!

The other devices on the bus are an AM2302 Humidity/Temp module and a BMP180 Pressure/Temp module, but for those two I "lifted" the code from other sources, so didn't learn too much from them.

Quite some time back I looked at both SPI and I2C for a multi-micro assembler-coded project - up to some 30 micros could be catered for - and chose SPI as it appeared simpler than I2C. However, realizing that each micro might need its own CS line, I instead opted for an address-based comms scheme, and really ended up with a sort of "I2C-over-SPI" protocol!

It was a good coding challenge!

With regards, Paul.
Nothing so constant as change.
 
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