• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

SE/30 (and others) RTC Replacement / Emulator with ATTiny85

pgreenland

Well-known member
I've got a pile of battery damaged SE/30's I've been slowly resurrecting.

One of them needed a new RTC and I wondered if it could be replaced by a microcontroller.

Turns out a few smart cookies had beat me to it and published various versions of firmware for the Atmel ATTiny85 which is a drop-in (ish) replacement for the Apple RTC.

Unfortunately neither of the reproductions I found worked in my SE/30, which appears to use much faster data transfers than the Mac Plus for which (I believe) they were originally designed (250Khz vs 20Khz).

I've had a go at my own drop in replacement, again using the ATTiny85. Re-written from the ground up using their work as inspiration, specifically for the SE/30.

If anyone wanted to have a go with it, I've dropped the source on GitHub: https://github.com/pgreenland/attinyrtc

I've also detailed its inner workings on my blog in case there's interest: https://www.quantulum.co.uk/blog/new-timepiece-for-a-classic-mac-part-1/

By default it's configured to store everything in the ATTiny's EEPROM allowing settings (startup disk in my case) to be preserved without power.
But can be configured to emulate the original RAM only behaviour, relying on the RTC battery to save settings when powered off. Although this is currently untested as none of my Mac's have intact RTC battery circuitry :-(.

Credit to the original MacPlus RTC developers:

https://pastebin.com/baPZ4nN4

Possibly the same @quorten?

https://github.com/quorten/macsehw/blob/master/firmware/rtc/MacRTC.c

If you give it a try, I'd be interested to hear from you and if you make any improvements!

Thanks,

Phil
 

schampango

Member
Hi Phil,
thats sounds awesome. I just ordered some Attiny85 and will be happy to test your work. But it will probably be a few weeks before i get around to it.
 

schampango

Member
Hello Phil,
I have tested it but with me the first SCSI device (all on one zuluSCSI) is not detected automatically and I have to mount it manually with LIDO. With the original RTC this behavior does not occur. Maybe my SE/30 is also broken.
Best regards
Daniel
 

pgreenland

Well-known member
Hello Phil,
I have tested it but with me the first SCSI device (all on one zuluSCSI) is not detected automatically and I have to mount it manually with LIDO. With the original RTC this behavior does not occur. Maybe my SE/30 is also broken.
Best regards
Daniel
Hey Daniel,

Sorry I've taken so long to reply, I either missed or didn't get a notification for your post.

I've not seen any problems with SCSI mounting myself. I've been using a ZuluSCSI too. I did manage to select a drive which didn't exist after swapping SD cards as the startup disk once. That upset the system quite a bit, but it was still happy to boot from floppy after some sort of timeout.

A simple test of the RTC would be to boot the machine, set the time and restart it (reboot it that is, rather than power cycle it). If the time's still there + a while for the reboot you've got some basic comms going.

I used Snooper I believe (would have to fire up my machine to confirm) to test the ATTiny's RTC and PRAM functions. That may be a good port of call if you try it again sometime.

Thanks,

Phil
 
Last edited:

pgreenland

Well-known member
Hi Phil,

Would love to know if these are programmable on a Windows box? Let me know what I may need to do (if you can)
Hey @Lyokian159

I've not tried building on Windows but that would be doable. I can certainly upload a pre-built binary to github if you like, save having to work that bit out.

Flashing an ATTiny from Windows shouldn't be too much trouble, I know of a few different ways of doing it.

You could use a dedicated ICSP programmer if you had one, they're not super expensive to buy. But possibly not worth it if you're not planning on programming a load.

Or you could program via an Arduino with a special sketch to emulate an ICSP programmer.

If you wanted to give it a quick try. A breadboard, few dupoint cables, ATTiny85 and an Arduino acting as a programmer may be the easiest route.

Let me know what you're thinking and we can work out what you'll need.

Thanks,

Phil
 
Hey @Lyokian159

I've not tried building on Windows but that would be doable. I can certainly upload a pre-built binary to github if you like, save having to work that bit out.

Flashing an ATTiny from Windows shouldn't be too much trouble, I know of a few different ways of doing it.

You could use a dedicated ICSP programmer if you had one, they're not super expensive to buy. But possibly not worth it if you're not planning on programming a load.

Or you could program via an Arduino with a special sketch to emulate an ICSP programmer.

If you wanted to give it a quick try. A breadboard, few dupoint cables, ATTiny85 and an Arduino acting as a programmer may be the easiest route.

Let me know what you're thinking and we can work out what you'll need.

Thanks,

Phil
Thanks for the response Phil, it is super appreciated.

Was thinking of getting the SparkFun Tiny AVR programmer.

Based upon the language in the product description I can program it directly in the Arduino IDE.

Do you think I would be able to put your code into the IDE and use this tool to program it directly?

I am absolutely a novice to microcontroller programming. The last time I played with this stuff was using BasicStamps in '06
 

pgreenland

Well-known member
Thanks for the response Phil, it is super appreciated.

Was thinking of getting the SparkFun Tiny AVR programmer.

Based upon the language in the product description I can program it directly in the Arduino IDE.

Do you think I would be able to put your code into the IDE and use this tool to program it directly?

I am absolutely a novice to microcontroller programming. The last time I played with this stuff was using BasicStamps in '06

That looks like the perfect programmer for the job, chip drops straight in, no fiddly connections to make.

The source code was written with the avr-gcc toolchain in mind, which sits under the hood of the Arduino framework. I used it directly, partly because I always do and partly because it does away with the C++ and some user friendliness in exchange for a bit more performance and control. You probably could get it to build in the Arduino IDE by swapping out main for a setup / loop function but I haven't yet tried it I'm afraid.

If you weren't too concerned with building yourself, I've dropped a release on the GitHub page with the programming files from the build, release 1.0.0.

With the ArduinoIDE installed, you'll have access to avrdude, the tool typically used to program AVRs, which supports the SparkFun programmer.

After installing the Windows driver for the programmer.

With the released programming files, you should be able to drop the chip in the programmer, find the avrdude binary and run something similar to the following from a command prompt in the directory containing the release files:

%USERPROFILE%\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17\bin\avrdude.exe -v -c usbtiny -p attiny85 -U flash:w:ATtinyRTC.hex

%USERPROFILE%\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17\bin\avrdude.exe -v -c usbtiny -p attiny85 -U eeprom:w:ATtinyRTC.eep

If the above two go well the chip should be fully programmed, but needs to be configured, via setting the fuse bits. The following command will take care of that.

There's one slightly annoying thing to be aware of. Once the fuse bits have been set the programmer won't be able to reprogram the chip. For the attiny to act as a true drop-in replacement, the fuses are set to re-assign the reset pin used by the programmer to become an extra GPIO pin. This pin is then used to generate a one second reference tick for the mac. The chip is still fully re-usable after this, it just requires what Microchip (Atmel) call high voltage programming. Which involves applying a 12v pulse to the reset pin to get it into a special mode, before instructing it to return the fuse settings to defaults using a special command set. Thereby allowing the standard ICSP programmer like the Sparkfun to work again. I've done this a few times with a 12v supply, an Arduino running a special sketch and a common transistor. Can dig the guide I followed out if you need it.

%USERPROFILE%\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17\bin\avrdude.exe -c usbtiny -p attiny85 -U lfuse:w:0xe1:m -U hfuse:w:0x5f:m -U efuse:w:0xff:m -U lock:w:0xff:m

I've not been able to try the commands above but was able to look up the paths having installed the latest MSI installer version of the Arduino 2.x IDE on a Windows VM....had to dust it off all special like :p

The arguments are straight out of the CMakeLists.txt file in my repo, with the programmer updated for the Sparkfun unit.

If you give it a go and get stuck feel free to drop me a DM, or continue the conversation here.

The code's still slightly experimental, although its been running on my two battery bombed SE30's seemingly ok. I've not had a chance to try it in a machine with a working battery....or a machine with anything resembling a battery holder come to think of it 🙈. I wasn't too bothered by having the correct time when I started the machines up, just wanted all my preferences and startup disk to be preserved. So any settings are stored in the ATTiny's EEPROM, thereby requiring no power....or a battery I'd definitely forget to replace / check on.

Good luck!

Phil
 
That looks like the perfect programmer for the job, chip drops straight in, no fiddly connections to make.

The source code was written with the avr-gcc toolchain in mind, which sits under the hood of the Arduino framework. I used it directly, partly because I always do and partly because it does away with the C++ and some user friendliness in exchange for a bit more performance and control. You probably could get it to build in the Arduino IDE by swapping out main for a setup / loop function but I haven't yet tried it I'm afraid.

If you weren't too concerned with building yourself, I've dropped a release on the GitHub page with the programming files from the build, release 1.0.0.

With the ArduinoIDE installed, you'll have access to avrdude, the tool typically used to program AVRs, which supports the SparkFun programmer.

After installing the Windows driver for the programmer.

With the released programming files, you should be able to drop the chip in the programmer, find the avrdude binary and run something similar to the following from a command prompt in the directory containing the release files:

%USERPROFILE%\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17\bin\avrdude.exe -v -c usbtiny -p attiny85 -U flash:w:ATtinyRTC.hex

%USERPROFILE%\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17\bin\avrdude.exe -v -c usbtiny -p attiny85 -U eeprom:w:ATtinyRTC.eep

If the above two go well the chip should be fully programmed, but needs to be configured, via setting the fuse bits. The following command will take care of that.

There's one slightly annoying thing to be aware of. Once the fuse bits have been set the programmer won't be able to reprogram the chip. For the attiny to act as a true drop-in replacement, the fuses are set to re-assign the reset pin used by the programmer to become an extra GPIO pin. This pin is then used to generate a one second reference tick for the mac. The chip is still fully re-usable after this, it just requires what Microchip (Atmel) call high voltage programming. Which involves applying a 12v pulse to the reset pin to get it into a special mode, before instructing it to return the fuse settings to defaults using a special command set. Thereby allowing the standard ICSP programmer like the Sparkfun to work again. I've done this a few times with a 12v supply, an Arduino running a special sketch and a common transistor. Can dig the guide I followed out if you need it.

%USERPROFILE%\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17\bin\avrdude.exe -c usbtiny -p attiny85 -U lfuse:w:0xe1:m -U hfuse:w:0x5f:m -U efuse:w:0xff:m -U lock:w:0xff:m

I've not been able to try the commands above but was able to look up the paths having installed the latest MSI installer version of the Arduino 2.x IDE on a Windows VM....had to dust it off all special like :p

The arguments are straight out of the CMakeLists.txt file in my repo, with the programmer updated for the Sparkfun unit.

If you give it a go and get stuck feel free to drop me a DM, or continue the conversation here.

The code's still slightly experimental, although its been running on my two battery bombed SE30's seemingly ok. I've not had a chance to try it in a machine with a working battery....or a machine with anything resembling a battery holder come to think of it 🙈. I wasn't too bothered by having the correct time when I started the machines up, just wanted all my preferences and startup disk to be preserved. So any settings are stored in the ATTiny's EEPROM, thereby requiring no power....or a battery I'd definitely forget to replace / check on.

Good luck!

Phil
Hey Phil,
You are a legend.

I have everything on order and will test in my working SE/30 and the bombed one we are building into a Bolle Reloaded board.

Should I avoid putting battery power in the circuit to not damage the chip?
 

pgreenland

Well-known member
Hey Phil,
You are a legend.

I have everything on order and will test in my working SE/30 and the bombed one we are building into a Bolle Reloaded board.

Should I avoid putting battery power in the circuit to not damage the chip?
Nice + Just started the process of gathering the bits for a Bolle Reloaded board myself. After fixing traces on the better of two machine, I decided I'd be chasing them forever on the worse one.

No harm in having the battery in, it may well work just fine, but won't do any harm if it doesn't. The potential issue is that the 3.6v battery which supplies the RTC when the machine is powered off is right on the edge of the recommended supply voltage range for the ATTiny when operating at 16Mhz. I suspect it'll be just fine but you'll be the first to try it with a battery :).
 
We have a booting Reloaded board with the ATTinyRTC!
Waiting on a Battery Holder to make sure it isn't impacted by having the battery installed!
 

trickydee

Member
Hi All,

The clock in my Apple IIGS failed and I traced the issue to the same RTC chip as used in early Macs. While looking for a replacement IC I found this awesome project. So I purchased 2 x Tiny85's and USB programmer of eBay ready to test the ATTinyRC in a IIGS.

After a bit of a struggle installing the tooling, I managed to compile the code (then I saw you already supplied a binary on your GitHub @pgreenland :) )

Unfortunately though I have now hit a roadblock as I cannot seem to workout how to program the Tiny85, neither windows or Mac detect either of the 85's in the USB programmer. After a bit of reading I am suspecting that I need a USB Bootloader loading on the 85's first ? would this be the case?

Any help appreciated.

R
 

Phipli

Well-known member
Hi All,

The clock in my Apple IIGS failed and I traced the issue to the same RTC chip as used in early Macs. While looking for a replacement IC I found this awesome project. So I purchased 2 x Tiny85's and USB programmer of eBay ready to test the ATTinyRC in a IIGS.

After a bit of a struggle installing the tooling, I managed to compile the code (then I saw you already supplied a binary on your GitHub @pgreenland :) )

Unfortunately though I have now hit a roadblock as I cannot seem to workout how to program the Tiny85, neither windows or Mac detect either of the 85's in the USB programmer. After a bit of reading I am suspecting that I need a USB Bootloader loading on the 85's first ? would this be the case?

Any help appreciated.

R
What programmer are you using?

Do you own any arduinos? Or a TL866?
 

trickydee

Member
Hi @Phipli

I purchased this board from eBay :


The only other boards I have are NodeMcu V3 ESP8266 's.
I did see a number of article on using an Arduino to program the board using ISP. Which is the best option here? Arduino or a TL866?
I did need an excuse to buy a TL866 as I wanted to burn some eproms :)
 

Phipli

Well-known member
Hi @Phipli

I purchased this board from eBay :


The only other boards I have are NodeMcu V3 ESP8266 's.
I did see a number of article on using an Arduino to program the board using ISP. Which is the best option here? Arduino or a TL866?
I did need an excuse to buy a TL866 as I wanted to burn some eproms :)
Arduino is cheaper, but if you want a TL866 anyway, perhaps it is an opertunity.

Make sure you find a How To guide before you buy, I haven't programmed an ATT85 in mine, I have USBISPs I use.

You may need to set the fuses as well as program the binary.
 

pgreenland

Well-known member
@trickydee I've been using the a T48, a slightly updated version of the TL866 I think. I bought it with the exact same excuse as you - programming some GALs and EEPROMs for a Bolle SE/30 replacement logic board. It programs the ATTiny's just fine too.

You're right in that the ebay programmer would require a special bootloader on the ATTiny. It's less a programmer and more a breakout board for the USB...cool nonetheless.

I used a USBasp originally which work pretty good - USBasp Programmer cable & adapter FW V1.06 USB AVR ok with 2560 TPI ATTINY

An Arduino can emulate a programmer and I've used them successfully for this in the past, but it can be quite a faff.

I'd go with either a USBasp or TL866.

@Phipli is spot on in that there's two parts to programming the ATTiny. The firmware itself, which it sounds like you've managed to build ok and the fuses. They're configuration flags for the microcontroller which in this case configure it to run from its internal clock and repurpose the reset pin of the MCU as a general purpose output, which can then be used as part of the communication with the mac.

The TL866 may (haven't been able to confirm) support high voltage programming for the ATTiny. This is required if you want to program the chip a second time. Once the fuses have been set and reset line repurposed the standard programmers aren't able to talk to it anymore. You need a high voltage programmer, which zaps the reset pin with a high voltage, forcing the chip into one of its programming modes.

The drop in ATTiny replacement hasn't got all that many miles on it unfortunately. Would be great to hear how you get on using it in your IIGS.

Phil
 

trickydee

Member
Thanks you both for the replies.

@pgreenland - Yes I saw the requirement around the high voltage programmer, I don't expect that I will reprogram once I get the code loaded.Even if the chip is not accurate it will be better than the non-functioning unit previously in the machine - where only the pram worked the clock had no 1sec pulse at all.
One final question before I purchase a T48 or TL866 - do I need any adapters to fit the tiny85 into the programmer ? - do you use a breadboard ? or will it's pins reach?

R
 

pgreenland

Well-known member
Thanks you both for the replies.

@pgreenland - Yes I saw the requirement around the high voltage programmer, I don't expect that I will reprogram once I get the code loaded.Even if the chip is not accurate it will be better than the non-functioning unit previously in the machine - where only the pram worked the clock had no 1sec pulse at all.
One final question before I purchase a T48 or TL866 - do I need any adapters to fit the tiny85 into the programmer ? - do you use a breadboard ? or will it's pins reach?

R
If you're using the PDIP-8 package (that drops straight into mac) they fit in the ZIF socket on the programmer just fine.

I've just tried it with the T48 (which might also be known as the TL866 Plus or TL866-3G), it reprogrammed my old chip just fine, so must be using the high voltage programming.

Screenshot 2023-10-01 at 12.32.09.png

With the hex file loaded, the above shows the settings for the fuses (config). When hitting the prog button I always untick the lock bit programming. They can be used to lock out any future programming, which we don't want.

If / when you get that far you may want to build the code on this branch instead of the master: https://github.com/pgreenland/attinyrtc/tree/startup_issue_clock_storing

I've got two clock projects, this drop in replacement and a slightly more accurate (uses an external crystal for better time keeping, and dedicated hardware to help with the communication) module based one. I'm currently in the progress of debugging an issue someone found with the module based one, which may affect the single chip version too. The problem found was the mac sometimes doesn't boot, it pretends that it cant find its startup disk. Unfortunately the one time I was able to reproduce it in like 50 tries, I didn't have anything hooked up to capture the problem. The branch adds a delay at startup, which covers the initial hardware reset period. While also making a slight tweak to how often the current time is written back to the EEPROM. I'm waiting to hear back from him if this solves the issue, although its a bit of a shot in the dark until I capture the cause.

Will try the freshly flashed tweaked version of the software in one of my macs in a bit....just to make sure I haven't broken anything.

Thanks,

Phil
 

trickydee

Member
I have an update. Good and Bad news.

I purchased a T48 programmer from Amazon, in anticipation of its arrival I soldered a DIP8 socket to my IIGS board ready to add in the tiny85.
I completed the soldering I thought I'd just try the original Apple 3440042B chip in the socket - and it worked !!! The clock seconds had started counting (previously the chip would only store pram contents and no signal on clock pins), so there must have been a dry joint on the chip originally.

The programmer arrived the next day, so I programmed the latest version of the tiny85 code using your instructions @pgreenland. I replaced the original clock chip with the tiny85 and the IIGS clock did not work, nor did the pram config store.
also tried the original code that I compiled no joy. I checked the fuse settings, verified the code and tried a different tiny85 they all look good.
The only unknown is it there is an issue with either the two tiny's or the programmer. Or maybe the lower clock / bus speed of the IIGS isnt' compatible in the same way that Mac's are.

Any thoughts?
 

pgreenland

Well-known member
Nice one.....I spent ages....like weeks trying to track down a problem with one of my machines. Turned out to be a dry joint 🙈 .

I'm not too familiar with the IIGS. There are several (at least one or two others) RTC emulator projects out there. I tried these on my machines are first before realising the SE/30's RTC interfaces runs significantly faster than the older machines. Having said the ATTiny code should (although I haven't tested) be happy running at the slower speed of the older machines. If anything the SE/30 is right on the edge of what I was able to do timing wise for the SE/30, slower should be better.

If you wanted to get it working / add another machine to the we've tried it on these and it seems to work list that would be awesome.

Testing wise for the ATTiny itself, I've got an Arduino sketch, which implements the host side of the communication, aka pretends to be the mac. It can read, write and verify all the PRAM as well as check the clock output is within spec. It should run on any Arduino, and would just need a few pullup resistors and wires between the ATTiny and the Arduino. Can add the code to the repo with some notes if you were interested in trying.

The only thing that springs to mind as maybe causing an issue. There's a timeout mechanism in the chip that you might be triggering. Although this is unlikely, I think its set to multiple seconds. If a transfer takes too long, the chip abandons it. This was to support battery powered operation, for folks with a good battery socket but bad RTC. Although I think I worked out that the ATTiny would likely use too much power. The timeout is there as powering down looks to the chip like a transfer request.

Let me know,

Thanks,

Phil
 
Top