Silicon ChipEl Cheapo Modules From Asia - Part 1 - October 2016 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: El cheapo electronics modules - the new standard components
  4. Order Form
  5. Feature: China's Gigantic Telescope: Scanning Deepest Space by Ross Tester
  6. Feature: Implantable Medical Devices by Dr David Maddison
  7. Feature: El Cheapo Modules From Asia - Part 1 by Jim Rowe
  8. Project: Lure & Liquidate Lovelorn Zika Virus Mozzies by John Clarke
  9. Subscriptions
  10. Project: A New Transformer For The Currawong Valve Amplifier by Leo Simpson
  11. Project: Touchscreen Appliance Energy Meter, Pt.3 by Jim Rowe & Nicholas Vinen
  12. Project: Two Micropower LED Flasher Modules by John Clarke
  13. Serviceman's Log: How I got trapped inside my MG by Dave Thompson
  14. Project: Voltage/Current Reference With Touchscreen, Pt.1 by Nicholas Vinen
  15. Project: Micromite Plus Explore 100 Module, Pt.2 by Geoff Graham
  16. Vintage Radio: The valve mantel’s last hurrah: Astor’s DLP 2-valve receiver by Ian Batty
  17. Product Showcase
  18. Market Centre
  19. Notes & Errata: Stereo LED Audio Level/VU Meter (June & July 2016); Touchscreen Appliance Energy Meter (August - October 2016)
  20. Advertising Index
  21. Outer Back Cover

This is only a preview of the October 2016 issue of Silicon Chip.

You can view 39 of the 104 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "El Cheapo Modules From Asia - Part 1":
  • DS3231-based Real Time Clock & Calendar module with mounting hardware (Component, AUD $6.00)
Articles in this series:
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • A Gesture Recognition Module (March 2022)
  • A Gesture Recognition Module (March 2022)
  • Air Quality Sensors (May 2022)
  • Air Quality Sensors (May 2022)
  • MOS Air Quality Sensors (June 2022)
  • MOS Air Quality Sensors (June 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Heart Rate Sensor Module (February 2023)
  • Heart Rate Sensor Module (February 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • VL6180X Rangefinding Module (July 2023)
  • VL6180X Rangefinding Module (July 2023)
  • pH Meter Module (September 2023)
  • pH Meter Module (September 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 1-24V USB Power Supply (October 2024)
  • 1-24V USB Power Supply (October 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
Items relevant to "Lure & Liquidate Lovelorn Zika Virus Mozzies":
  • Mosquito Lure PCB [25110161] (AUD $5.00)
  • PIC12F675-I/P programmed for the Mosquito Lure [2511016A.HEX] (Programmed Microcontroller, AUD $10.00)
  • Mosquito Lure SMD parts: TPA2005D1DGNR (MSOP-8) Class-D 1.45W amplifier IC and microUSB socket (Component, AUD $7.50)
  • Firmware (ASM and HEX) files for the Mosquito Lure [2511016A.HEX] (Software, Free)
  • Mosquito Lure PCB pattern (PDF download) [25110161] (Free)
  • Mosquito Lure trap details, cutting diagrams and panels (PDF download) (Panel Artwork, Free)
Items relevant to "A New Transformer For The Currawong Valve Amplifier":
  • Currawong 2 x 10W Stereo Valve Amplifier main PCB [01111141] (AUD $55.00)
  • Currawong Remote Control PCB [01111144] (AUD $5.00)
  • PIC16F88-I/P programmed for the Currawong Remote Volume Control [0111114A.HEX] (Programmed Microcontroller, AUD $15.00)
  • Front & rear panels for the Currawong 2 x 10W Stereo Valve Amplifier [01111142/3] (PCB, AUD $30.00)
  • Currawong 2 x 10W Stereo Valve Amplifier acrylic top cover (PCB, AUD $30.00)
  • Currawong 2 x 10W Stereo Valve Amplifier top cover cutting diagram (Software, Free)
  • Firmware and source code for the Currawong Remote Volume Control [0111114A.HEX] (Software, Free)
  • Currawong 2 x 10W Stereo Valve Amplifier main PCB pattern [01111141] (Free)
  • Currawong 2 x 10W Stereo Valve Amplifier panel artwork (PDF download) (Free)
Articles in this series:
  • Currawong Stereo Valve Amplifier: A Preview (October 2014)
  • Currawong Stereo Valve Amplifier: A Preview (October 2014)
  • Currawong 2 x 10W Stereo Valve Amplifier, Pt.1 (November 2014)
  • Currawong 2 x 10W Stereo Valve Amplifier, Pt.1 (November 2014)
  • Currawong 2 x 10W Stereo Valve Amplifier, Pt.2 (December 2014)
  • Currawong 2 x 10W Stereo Valve Amplifier, Pt.2 (December 2014)
  • The Currawong 2 x 10W Stereo Valve Amplifier, Pt.3 (January 2015)
  • The Currawong 2 x 10W Stereo Valve Amplifier, Pt.3 (January 2015)
  • Modifying the Currawong Amplifier: Is It Worthwhile? (March 2015)
  • Modifying the Currawong Amplifier: Is It Worthwhile? (March 2015)
  • A New Transformer For The Currawong Valve Amplifier (October 2016)
  • A New Transformer For The Currawong Valve Amplifier (October 2016)
Items relevant to "Touchscreen Appliance Energy Meter, Pt.3":
  • Touchscreen Appliance Energy Meter PCB [04116061 RevI] (AUD $15.00)
  • PIC32MX170F256B-50I/SP programmed for the Micromite-based Touchscreen Energy Meter v1.01 [0411606A.hex] (Programmed Microcontroller, AUD $15.00)
  • CP2102-based USB/TTL serial converter with microUSB socket and 6-pin right-angle header (Component, AUD $5.00)
  • CP2102-based USB/TTL serial converter with microUSB socket and 6-pin right-angle header (clone version) (Component, AUD $3.00)
  • DS3231-based Real Time Clock & Calendar module with mounting hardware (Component, AUD $6.00)
  • ACS718 20A isolated current monitor (Component, AUD $15.00)
  • Firmware (HEX) file and BASIC source code for the Micromite-based Touchscreen Appliance Energy Meter [v1.01] (Software, Free)
  • Touchscreen Appliance Energy Meter PCB pettern (PDF download) [04116061 RevG] (PCB Pattern, Free)
  • Touchscreen Appliance Energy Meter lid panel artwork (PDF download) (Free)
Articles in this series:
  • Touchscreen-Controlled Energy Meter, Pt.1 (August 2016)
  • Touchscreen-Controlled Energy Meter, Pt.1 (August 2016)
  • Touchscreen Appliance Energy Meter, Pt.2 (September 2016)
  • Touchscreen Appliance Energy Meter, Pt.2 (September 2016)
  • Touchscreen Appliance Energy Meter, Pt.3 (October 2016)
  • Touchscreen Appliance Energy Meter, Pt.3 (October 2016)
Items relevant to "Two Micropower LED Flasher Modules":
  • Micropower LED Flasher PCB [16109161] (AUD $5.00)
  • Mini Micropower LED Flasher PCB [16109162] (AUD $2.50)
  • PIC12F675-I/P programmed for the Micropower LED Flasher [1610916A.HEX] (Programmed Microcontroller, AUD $10.00)
  • Firmware (ASM and HEX) files for the Micropower LED Flasher [1610916A.HEX] (Software, Free)
  • Micropower LED Flasher PCB patterns (PDF download) [16109161/2] (Free)
Items relevant to "Voltage/Current Reference With Touchscreen, Pt.1":
  • Touchscreen Voltage/Current Reference PCB [04110161] (AUD $12.50)
  • PIC32MX170F256B-50I/SP programmed for the Micromite-based Touchscreen Voltage/Current Reference v1.00 [0411016A.HEX] (Programmed Microcontroller, AUD $15.00)
  • Short Form Kit for the Touchscreen Voltage/Current Reference (Component, AUD $120.00)
  • Translucent Blue UB1 Lid for the Precision Voltage & Current Reference with Touchscreen Control (PCB, AUD $10.00)
  • Firmware (HEX) file and BASIC source code for the Micromite-based Touchscreen Voltage/Current Reference v1.00 [0411016A.HEX] (Software, Free)
  • Touchscreen Voltage/Current Reference PCB pattern (PDF download) [04110161] (Free)
Articles in this series:
  • Voltage/Current Reference With Touchscreen, Pt.1 (October 2016)
  • Voltage/Current Reference With Touchscreen, Pt.1 (October 2016)
  • Voltage/Current Reference With Touchscreen, Pt.2 (December 2016)
  • Voltage/Current Reference With Touchscreen, Pt.2 (December 2016)
Items relevant to "Micromite Plus Explore 100 Module, Pt.2":
  • Micromite Plus Explore 100 PCB [07109161 RevC] (AUD $15.00)
  • PIC32MX470F512L-120/PF programmed for the Micromite Plus (Programmed Microcontroller, AUD $25.00)
  • CP2102-based USB/TTL serial converter with microUSB socket and 6-pin right-angle header (Component, AUD $5.00)
  • CP2102-based USB/TTL serial converter with microUSB socket and 6-pin right-angle header (clone version) (Component, AUD $3.00)
  • DS3231-based Real Time Clock & Calendar module with mounting hardware (Component, AUD $6.00)
  • MCP120-270GI/TO Supply Supervisor IC (TO-92) (Component, AUD $2.00)
  • Short Form Kit for the Micromite Plus Explore 100 (Component, AUD $75.00)
  • Firmware (HEX) file and documents for the Micromite Mk.2 and Micromite Plus (Software, Free)
  • Micromite Plus Explore 100 PCB pattern (PDF download) [07109161 RevC] (Free)
Articles in this series:
  • Micromite Plus Explore 100 With Touchscreen, Pt.1 (September 2016)
  • Micromite Plus Explore 100 With Touchscreen, Pt.1 (September 2016)
  • Micromite Plus Explore 100 Module, Pt.2 (October 2016)
  • Micromite Plus Explore 100 Module, Pt.2 (October 2016)

Purchase a printed copy of this issue for $10.00.

Low Cost Asian Electronic Modules Now they are just standard components! This is the first of a series of small articles which will help you take full advantage of the wide range of handy pre-built electronic modules that are now available from Asia. In this article, we review the DS3231 real time clock (RTC) module. I F YOU’VE been reading Silicon Chip for a while now, you'll have noticed that small electronic modules have been creeping into our projects and the reader circuits published in Circuit Notebook. These are not just Micromite, Arduino or Raspberry Pi boards either but really small and low cost modules including real time clocks/calendars (RTC), USB-to-UART serial “bridges”, UHF data transmitters and receivers, DDS signal generators, OLED/LCD panels, touch-screen TFT LCDs, temperature/humidity sensors, microSD card interfaces and many more. They seem to be breeding like rabbits! Many of these modules have sprung into life initially as “peripherals” for baby micros like the Arduino (ie, shields) and Raspberry Pi. But most of them have a lot of other applications in circuits and designs using standard TTL or CMOS ICs, and even in designs using olde-worlde discrete transistors. But the really big advantage of this new generation of pre-built modules is that most of them are surprisingly low in cost. In fact, with many of them, you'll find that the cost of a complete 32  Silicon Chip Pt.1: By JIM ROWE module is much less than the price you'd pay for the main IC chip used in them. A prime example is the popular real time clock/calendar module using Maxim's very accurate DS3231 RTC chip — plus a 24C32 4KB EEPROM, in most cases. Although the module is usually advertised as intended to be used with an Arduino, it has a standard I²C (“Inter-IC”) interface and can actually be used with most other micros (we used it with the Micromite in our Touchscreen Super Clock and Appliance Energy Meter projects, for example), as well as in a host of other designs. So that's the rationale behind this series of articles on the new “el cheapo” modules. They're readily available, often have many applications and they're usually much cheaper than building up the same circuits for yourself. As a result, they've now reached the status of being just standard circuit components. The Electronic Modules As Components or “EMAC” revolution has begun! Let's start the ball rolling by taking a look at real time clock/calendar modules. RTC modules Probably the first low-cost RTC modules to appear were those based on the Philips/NXP PCF8563 chip, a low-power 8-pin CMOS device which has an I²C interface but needs an external 32.768kHz crystal. Modules based on the PCF8563 are still available at low cost from eBay or AliExpress, but they tend to be less popular than modules based on one of two newer Maxim chips: either the DS1307 or the DS3231. Like the PCF8563, the DS1307 needs an external 32kHz crystal. However, it does have a built-in power sense circuit which switches to a backup battery when it detects a power failure. It also has 56 bytes of internal non-volatile SRAM and a standard I²C interface, making it compatible with just about every type of microcontroller module such as the Arduino or the Micromite. It does have one shortcoming, though: the time-keeping accuracy is inclined to drift a little with temsiliconchip.com.au perature and so it can vary by a few minutes a month. Clock/calendar modules using the DS1307 tend to cost more than those using the PCF8563, but they often include extras like a DS18B20 temperature sensor and a 24C32 serial EEPROM (32Kbits = 4KB). This makes them quite attractive for applications where extreme accuracy isn't too critical. But modules based on the DS3231 chip are currently the most popular, partly because the DS3231 has an onchip temperature-compensated crystal oscillator and crystal. It also includes an internal temperature-compensated voltage reference and comparator, both to maintain its own supply voltage and to automatically switch to a backup supply when necessary. These features allow it to provide significantly higher timekeeping accuracy: better than ±2ppm between 0 and 40°C, or ±2 minutes per year for a temperature range of -40°C to +85°C. Its single shortcoming compared with the DS1307 is that it lacks the internal non-volatile SRAM. Despite the advantages offered by the DS3231, modules using it tend to cost no more than those based on the DS1307 or the PCF8563. And this applies for modules like the one shown in the pictures, which also includes a 24C32 serial EEPROM. As mentioned earlier, this is the RTC module that has been used in a number of recent projects like the Touchscreen Super Clock, the Appliance Energy Meter and the Micromite Explore 100, so it's the one we'll now concentrate on. DS3231 RTC As shown in the circuit diagram of Fig.1, there isn't a great deal in this module apart from the DS3231 chip itself (IC1), its 3.6V backup battery and the 24C32 serial EEPROM (IC2). We'll discuss the rest of the components and circuitry shortly after we've looked at what's inside the DS3231. Its compact 16-pin small outline (SO) SMD package contains an I²C data bus interface, address decoding for the 18 internal time, date and control registers, a temperature sensor and a power control circuit which can swing over to the backup battery when the supply voltage (VCC) fails. Its block diagram is shown in Fig.2. siliconchip.com.au 100nF 4x 4.7k CON1 32k 16 SQW 15 SCL 4 SDA 3 VCC 1 GND 10 F D1 1N4148 2 Vcc VBAT SCL SDA 1k 200 A A K K LED1 14 IC1 DS3231 RST 3.6V LI-ION BATTERY INT/SQW 32kHz NC 5–12 GND 13 (RECHARGEABLE) CON2 SCL SDA NOTE: I2C SLAVE ADDRESS FOR DS3231 IS D0 (HEX) FOR WRITING, D1 (HEX) FOR READING VCC 8 5 6 Vdd SDA SCL IC2 24C32 Vss 4 NC A2 A1 A0 7 GND 4x 4.7k 3 2 1 (TO SET SLAVE ADDRESS OF IC2) A0 A1 A2 I C SLAVE ADDRESSES (HEX) FOR 24C32 EEPROM 2 MSD (FIXED) A2 A1 A0 WRITE READ A 1 1 1 AE AF A 1 1 0 AC AD A 1 0 1 AA AB A 1 0 0 A8 A9 A 0 1 1 A6 A7 A 0 1 0 A4 A5 A 0 0 1 A2 A3 A 0 0 0 A0 A1 DEFAULT ADDRESS (NO LINKS ON PADS FOR A0, A1 OR A2) 24C32 ADDRESS BYTE FORMAT 1 0 1 FIXED 0 A2 A1 A0 R W SET BY LINKS Fig.1: complete circuit for the DS3231-based RTC module. Both CON1 and CON2 provide serial bus and power connections, allowing extra devices to be connected. Note that the I2C bus should have only one set of pull-up resistors. Then there's a complete temperature-compensated 32.768kHz crystal oscillator (TCXO), followed by a frequency divider chain and all of the time (seconds/minutes/hours), date (day of week, day of month, month and year), alarm, status and control registers. Finally, there's reset circuitry plus output buffers for both the 32kHz TCXO oscillator and the square wave output when it's enabled. Note that since the module tracks the date as well as the time, it is more correctly described as a real time clock & calendar (RTCC) module but we'll stick with the more common RTC term. As well as the time and date registers, the DS3231 also provides two time-of-day alarm functions which are programmable via two sets of dedicated registers. These can generate an interrupt output signal via pin 3 (INT-bar/ SQW), for feeding directly back to a micro. When pin 3 is not being used to provide this alarm interrupt function, it can be used to provide square wave timing signals derived from the 32kHz TCXO. The square waves can be programmed for one of four frequencies: 1Hz, 1.024kHz, 4.096kHz or 8.192kHz. These are in addition to the 32.768kHz signal made available at pin 1. All of the DS3231's function settings, along with the initial time and date, can be programmed using the I²C bus to write into the appropriate internal registers. Then the time, date and status can be subsequently obtained by using the I²C bus to read from the same registers. Pins 15 & 16 of the device are used for the I²C bus connections: pin 15 for the SDA serial data line and pin 16 for the SCL serial clock line. On the module shown, these are both October 2016  33 32kHz X1 OSCILLATOR AND CAPACITOR ARRAY N CONTROL LOGIC/ DIVIDER X2 SQUARE-WAVE BUFFER; INT/SQW CONTROL 1Hz VCC VBAT TEMPERATURE SENSOR POWER CONTROL GND INT/SQW N ALARM, STATUS, AND CONTROL REGISTERS 1Hz CLOCK AND CALENDAR REGISTERS SCL SDA I2C INTERFACE AND ADDRESS REGISTER DECODE USER BUFFER (7 BYTES) VCC sistors by default, which gives IC2 a slave address of AE/AF hex (AEh for writing, AFh for reading). But it also provides three pairs of pads on the PCB so that any of the three address pins can be pulled low (to ground) by soldering across the A0, A1 or A2 pads. This allows the slave address of IC2 to be set to any of the eight possible values, as shown. So since the slave address of IC1 (the DS3231) is fixed at D0/1 hex (D0 for writing, D1 for reading), there is no conflict. In fact, the main reason for changing the slave address of IC2 via the wire links would be to avoid a conflict with any other devices that may be attached to the I²C bus. How it's used DS3231 VOLTAGE REFERENCE; DEBOUNCE CIRCUIT; PUSHBUTTON RESET RST N Fig.2: block diagram for the DS3231. A comparator monitors both VCC and VBAT and the DS3231 is powered from whichever is higher. The oscillator is automatically temperature-compensated for accuracy. provided with surface-mount 4.7kΩ pull-up resistors to VCC, as are pin 1, the 32.768kHz output and pin 3, the INT-bar/squarewave output. (The latter two pins are open-drain outputs, so they need the external pull-up resistors.) That's probably about all you need to know about the DS3231 itself, apart from the way that pin 14 (VBAT) is used for the connection to the 3.6V lithiumion rechargeable backup battery. In the module shown here, diode D1 and its series 200Ω resistor are used to maintain the battery charge when VCC is connected to the module. LED1 and its series 1kΩ resistor are used to provide a power-on indicator. We'll have more to say about battery options later. Note the two I/O headers, labelled in Fig.1 as CON1 and CON2. CON1 provides pins for both the 32kHz and SQW/INT-bar outputs as well as the SCL/SDA/VCC/GND bus connections, while CON2 provides only the latter four connections, essentially to allow daisy-chaining further devices to the I²C bus - additional memory chips, for example. Now let's look at IC2, the 24C32 serial EEPROM chip which is something of a bonus. The 24C32 is a 4KB (32Kb) device, with a standard I²C serial interface. In this module, the SDA line (pin 5) and SCL line (pin 6) are connected in parallel with those for IC1, to the module's SDA and SCL lines at both CON1 and CON2. To allow IC2 to be addressed by the micro without conflicting with commands or data sent to or received from IC1, it has a different slave address on the I²C bus. In fact, it can have any of eight different slave addresses, as set by the voltage levels of pins 1, 2 and 3 (labelled A0, A1 and A2). As shown in Fig.1, the module pulls all three pins up to VCC via the 4.7kΩ re- Rear view of the DS3231 module showing the 3.6V Li-ion backup battery (pin 14) which powers the real time clock when the supply voltage (VCC) fails. 34  Silicon Chip Since both the DS3231 and 24C32 devices on the module are intended for use via the I²C bus, this makes it easy to use with any micro or other system provided with at least one I²C interface. (Even if you don’t have such an interface, you can use two GPIO pins in “bit banging” mode, but that’s outside the scope of this article.) For example, to use it with an Arduino Uno or similar all you need to do is connect the SCL line on the module to the AD5/SCL pin on the Arduino, the SDA line to the AD4/SDA pin, the VCC pin to the +5V pin and the GND pin to one of the Arduino's GND pins. It's just as easy with the Micromite. In this case, the SCL pin connects to pin 17 on the Micromite's main I/O pin strip, while the SDA pin connects to pin 18 next to it. Then the VCC and GND pins connect to the +5V pin and GND pins on the same pin strip. Programming either chip on the module should also be fairly straightforward, because of the I2C interfacing. The main thing to remember is that I2C transactions always begin with a control byte sent by the master (the micro), specifying the address of the slave device it wishes to communicate with and whether it wants to write to or read from the device. So, for example, the control byte to initiate a write operation to one of the registers in the DS3231 would be D0h, while the control byte to read from one of the addresses in the 24C32 would be AFh (assuming it's at the default address on your module). After the slave device sends back an "ACK" or acknowledge indication siliconchip.com.au (to show that it's present and ready for a transaction), the micro then sends the address of the register or memory location in the device that it wants to write data to or read it from. Then when this has been acknowledged, the actual write or read transactions can take place. If this sounds a bit complicated, you'll be relieved to hear that if you're using one of the popular micros like the Arduino or Micromite, you probably don't need to worry about this yourself. That's because this has usually been taken care of in small code libraries, with functions specifically written for I²C data communications. In the case of the Micromite, in fact, I²C communication is handled by the MMBASIC interpreter. For example, if are using an Arduino, the Arduino IDE application already includes a "Wire" library, providing about nine different functions for passing data between the micro and an I²C device. Similarly, if you're using a Micromite, you'll find that Geoff Graham's MMBASIC already includes functions like RTC SETTIME, RTC GETTIME, RTC SETREG and RTC GETREG spe- siliconchip.com.au cifically for talking to the DS1307 or DS3231 RTC devices. And there are other functions like I2C OPEN, I2C WRITE, I2C READ and I2C CLOSE for data transactions with other I2C devices (like the 24C32 EEPROM chip in the current module). Finally, there's also an automatic variable called MM.I2C, which can be read after any I2C transaction to find out the result status. So all in all, the RTC module shown with its DS3231 clock/calendar chip (and bonus 24C32 EEPROM chip) is relatively easy to use, and exceptional value for money. Below is a link to a useful web tutorial by John Boxall of tronixlabs, explaining how to use either the DS1307 or DS3231 RTC modules with an Arduino: http://tronixlabs.com.au/news/ tutorial-using-ds1307-and-ds3231realtime-clock-modules-with-arduino Silicon Chip has two versions of the DS3231 RTC module available via our on-line shop. Both come with mounting hardware; four 6mm M2 Nylon screws and two 10mm M2 tapped spacers, and one comes with an LIR2032 rechargeable cell already installed. You can view them at www. siliconchip.com.au/Shop/7 Note 1: the version supplied with no cell is designed to use a rechargeable cell. You can use a CR2032 (or similar) lithium button cell but in this case, you MUST remove the on-board SMD diode to prevent the battery from being charged. See the Super Clock article in the July 2016 issue for more details. Note 2: as this module has onboard pull-up resistors for the I²C bus, you may need to remove them, or avoid fitting pull-up resistors on the master, for it to share a bus with other SC peripherals. October 2016  35