I2C 4 U

for bbc micro/electron hardware, peripherals & programming issues (NOT emulators!)
Post Reply
User avatar
KenLowe
Posts: 412
Joined: Mon Oct 18, 2004 4:35 pm
Location: Scotland
Contact:

Re: I2C 4 U

Post by KenLowe » Sun Jul 15, 2018 7:48 pm

MartinB wrote:
Sun Jul 15, 2018 7:15 pm
Nice one Ken, sounds really good - that would presumably be bespoke to a Beeb with the IntegraB present?
This wouldn't need an existing IntegraB.

My original plan was to make a 'new' IntegraB with more modern / lower power components. I have started looking at the I2C RTC as an upgrade solution for the CDP6818E in the original IntegraB. The IntegraB IBOS rom would need to be adapted to read / write to the I2C RTC instead of the CDP6818E. That would be doable, apart from the fact that it's already using most of the available 16k ROM space for all the existing functions - not sure there's space to squeeze in the I2C driver code without having to remove other functionality.

What would be a lot simpler to develop is a stand alone I2C RTC module for the beeb using the same Sheila I/O address space that the IntegraB RTC uses. It would plug into the 6502 socket, and would have the necessary address decoding circuitry. I would also need to create a standalone ROM to interface with the I2C RTC. I might develop something like that.

However, if you're already in the process of developing something similar...

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Sun Jul 15, 2018 8:03 pm

Hey, not at all! - if you have a solution underway then by all means take the lead and I'll stand easy! :D What I'd like to do is, assuming an RTC is present with some E2, is move many of the RAMagic! features across to the I2C rom. So, be my guest - I'll watch and wait with interest.... 8)

(RAMagic! manual attached for reference of objectives.)


RAMagic manual.zip
(25.62 KiB) Downloaded 16 times
Last edited by MartinB on Sun Jul 15, 2018 8:03 pm, edited 1 time in total.

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Sun Jul 15, 2018 8:34 pm

I'll be doing the RAMagic! re-work btw - just need an easily accessible RTC (in the software sense) and a good 20K+ of E2 (which was SRAM with the original RAMagic!). I wanted the (Beeb internal) I2C RTC to need minimal connections to make it more friendly to the masses so I would next have experimented with simply using the User Port PB6 and 7 lines* because I believe that there is then zero chance of interference with other User Port devices. However, if you (Ken) can come up with an alternative cheap and cheerful solution, then I'm all ears... =D> :D

* though only for the internal RTC and associated RAMagic! functions, not for the existing I2C interface and rom commands which continue to use PB0 and CB2.
Last edited by MartinB on Sun Jul 15, 2018 10:05 pm, edited 1 time in total.

User avatar
1024MAK
Posts: 8107
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: I2C 4 U

Post by 1024MAK » Mon Jul 16, 2018 7:33 am

I have seen I2C RTC modules on eBay based on these: Mark

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Mon Jul 16, 2018 7:53 am

The last one is the type I use in this thread and you'll find all the details in the manual. The second, the DS1307, is the most common one on eBay etc. and is fully compatible with the DS3231 in terms of RTC access so if my thoughts for an internal RTC materialise, any recommendation I make will be for either of the those two modules.

Ken is looking at a second implementation method based on a third RTC type which is also compatible with the above two modules. The significance of the built modules over just the RTC chip type is that the modules above also have a 32k serial eeprom device on board which is very useful for 'other stuff' such as my proposed RAMagic! port.

User avatar
Elminster
Posts: 3143
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: I2C 4 U

Post by Elminster » Mon Jul 16, 2018 8:50 am

So while I have RAMagic on the hardware list, which intern links to http://chrisacorns.computinghistory.org ... Magic.html

I never actually owned or used one. The features include (as you are probably aware :wink: )

- PC to BBC Transfer Utility
- Clock/Calendar
- 32KB of Lithium battery backed RAM
- Sideways RAM/ROM functions
- Autoboot functions
- 21 New OS commands - *TIME *DATE *NOW *TBRK *TSET *DSET *MCLR *MROM *MSAVE *MLOAD *MDIR *VSAVE *VLOAD *AUTON *AUTOFF *ACOM *ACOM1 *ACOM2 *ACOM3 *SLEEP *DOSDFS

The first is covered by UPURS, the second is the RTC mentioned here. What from the other features were you looking to added from the orginal feature list ?

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Mon Jul 16, 2018 11:03 am

Wow! You are certainly very attentive Duncan :)

To be honest, dependant on space in the I2C rom, I’d probably aim to port nearly everything because even on the disc transfer front, the RAMagic! *DOSDFS function requires zero cables or hardware, only a PC with a floppy drive (which can even be a portable USB type), a Beeb with a 177x FDC and either a 5.25 or 3.5 floppy drive.

All the other RAMagic! functions are either clock tools or sideways ram/rom facilities and its only the latter that wouldn’t directly read across because of the RTC module having eeprom and not sram.

User avatar
Elminster
Posts: 3143
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: I2C 4 U

Post by Elminster » Mon Jul 16, 2018 1:08 pm

MartinB wrote:
Mon Jul 16, 2018 11:03 am
Wow! You are certainly very attentive Duncan :)
I have to try and keep on top of things or i get way behind the 'shiny' curve.

That all makes sense. Does that mean th new version will be called ROMagic?

torrind
Posts: 82
Joined: Fri Dec 01, 2017 4:57 pm
Location: Bristol
Contact:

Re: I2C 4 U

Post by torrind » Mon Jul 16, 2018 9:22 pm

Hi Martin et al.

I'm trying to get a ZS-042 DS3231 RTC module working on my BEEB using Martins I2C ROM. As per the screenshot, I do get an ack from the unit but I'm unable to run the basic programs to display the clock or temp graph. The clock just displays 0:0:0 and doesn't move. I appear to get no response from the unit.

Any ideas how I can test it? or what I'm doing wrong please? :)

Thanks,

Darren
Attachments
image1.jpeg

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Mon Jul 16, 2018 10:25 pm

Hello. Firstly, in the clock test program, immediately after each of the three lines with an I2C star command, can you insert another line as follows....

IF ?&67<>0 THEN PRINT”I2C COMMS ERROR”

This will tell us if the I2C device is supposedly acknowledging the commands as understood and executed.


That RTC gadget also has an independent 32k eeprom on board so in case your clock chip is faulty, can you try the following program (also from my I2C manual) which performs a read/write test of the eeprom....

Code: Select all

10 FORA%=0TO&7FFF
20  H%=(A%/256)AND&FF
30  L%=(A%AND&FF)
40  *I2CTXB 57 H%;
50  *I2CTXB FF L%;
60  *I2CTXB FF A%
65  :
70  *I2CTXB 57 H%;
80  *I2CTXB FF L%;
90  *I2CRXB 57 D%
100  PRINT~A%,~D%
110  IFD%<>(A%AND&FF)THEN PRINT "Error":STOP
120 NEXT

If you see no error messages with either of the two programs, can you then boot your Beeb without a 2P - I’ve never actually tested the I2C rom with a second processor and off the top of my head, I’ve not really thought about whether the programs are 2P compatible.



*** IMPORTANT ***

As an aside, regarding this DS3231 module (and maybe other similar RTC modules), please all look at the following thread which warns about a possible danger associated with the battery charging circuit......

https://forum.arduino.cc/index.php?topic=278270.0



The summary message seems to be that the charging circuit should be disabled.


.
Last edited by MartinB on Tue Jul 17, 2018 6:25 am, edited 5 times in total.

User avatar
Elminster
Posts: 3143
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: I2C 4 U

Post by Elminster » Tue Jul 17, 2018 8:37 am

Way of the exploding battery. Ouch.

edit: that post above, near the end, links back to a blog post which is pretty interesting as well. Namely https://thecavepearlproject.org/2014/05 ... from-ebay/
Last edited by Elminster on Tue Jul 17, 2018 10:59 am, edited 1 time in total.

User avatar
1024MAK
Posts: 8107
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: I2C 4 U

Post by 1024MAK » Tue Jul 17, 2018 1:18 pm

When using the RTC chips from Maxim, this is my general advice:

The datasheet from Maxim is clear in showing how to connect a primary cell/battery (non-rechargeable). The positive connection of the cell/battery should only be connected to the chip pin identified as VBAT. There should be no other connections to the cell/battery positive terminal. Normally, a CR2032 will last around ten years.

The datasheet does not give any guidance on using a secondary cell/battery. But cell/battery manufacturers should provide the required information for the charging characteristics of their cells/batteries.

As a CR2032 will have a long live in this circuit application, I don't recommend using a secondary cell/battery (rechargeable).

However, there should not be a problem if you want to use a super-capacitor. Just ensure that the super-capacitor you use is rated at 5.5V DC.

Now to the module from China. Let's just say that the king of cheap is not going to go to the expense of providing a specific charge control chip for a Li-ion cell (such as a LIR2032) in a very low cost module. Using a charging circuit of a silicon diode and series resistor is fine for Ni-Cad and NIMH 3.6V batteries. But not for Li-ion cells. Firstly, the 5V rail can go up to 5.25V and be within the specification. And the voltage drop of a silicon diode falls as the current reduces. So if the supply is actually 5.25V and the forward voltage of the silicon diode is actually 0.6V, the voltage across the Li-ion cell could rise to 4.65V. This is nearly half a volt over the maximum recommended charging voltage (which is 4.20V maximum)...

So yes, if you are going to use a CR2032 cell, please do either cut the track or remove the resistor or the diode.

I have already ordered a module that uses DS3231. I will investigate mine when I get time.

Mark

User avatar
Elminster
Posts: 3143
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: I2C 4 U

Post by Elminster » Tue Jul 17, 2018 3:23 pm

MartinB wrote:
Sun Jul 15, 2018 8:03 pm
Hey, not at all! - if you have a solution underway then by all means take the lead and I'll stand easy! :D What I'd like to do is, assuming an RTC is present with some E2, is move many of the RAMagic! features across to the I2C rom. So, be my guest - I'll watch and wait with interest.... 8)
I dont think you mentioned how you intend to attach the RTC to the machine without using the Userport, I am assuming this is under your (figerative) hat for now. But just wondered if the board would be connected as is, or some sort of custom hardware would be knocked up. In case of the later then the battery circuit could be 'fixed'. But if the former it doesnt look that hard to remove the SMD diode (with tweezer and a magnifying device anyway, oh and a (de)soldering iron).

User avatar
1024MAK
Posts: 8107
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: I2C 4 U

Post by 1024MAK » Tue Jul 17, 2018 4:06 pm

Removing the resistor is easier, just put a soldering iron bit (a 3mm to 5mm chisel bit) nearly touching one side of the resistor, apply solder between the tip and each pad of the resistor, then use the iron to "flick" the resistor off the board... if needed, clean up any solder. Then clean the board with IPA.

I've checked the ZX-042 DS3231SN eBay module that I received about 11 days ago (bought from ai_smart) and it has the same charging circuit as described in the link that Martin provided up thread. Same diode, same 200 ohm resistor (marked 201).

Mark

torrind
Posts: 82
Joined: Fri Dec 01, 2017 4:57 pm
Location: Bristol
Contact:

Re: I2C 4 U

Post by torrind » Tue Jul 17, 2018 8:00 pm

Hi Martin - The first thing I did before anything else was to disable the 2nd processor - Hey presto it works!!

Shame it can't work with a second processor though.

Thanks for your advice always appreciated!

Just need to sort out the battery charge circuit issue!

Darren

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Tue Jul 17, 2018 9:00 pm

Shame it can't work with a second processor though.
Actually, I think the I2C rom does effectively work with a 2P (for example *I2CQUERY is fine) but what won’t (can’t) work is my trick of writing I2C parameters directly to BASIC’s integer variables. This is because, perhaps obviously, BASIC itself is a sideways rom resident in the I/O processor (the Beeb) and therefore it’s workspace when operating with a 2P present, i.e. specifically the integer variable memory, is in the ‘wrong place’ with respect to how my rom accesses the % variables. This could I guess be fixed but I’m spinning far too many plates in the short term so it’ll go on a list of potential update candidates :)

User avatar
Elminster
Posts: 3143
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: I2C 4 U

Post by Elminster » Tue Jul 17, 2018 9:04 pm

Tut tut, not following the programming guide lines to work with tube. As punishment you must invent two thing before sunrise.

Reminds me, when looked at i2c did you also look at spi devices?

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Tue Jul 17, 2018 9:09 pm

To be fair, I did follow the guidelines for the Tube, just not for the relationship between languages and a 2P. However, because my % variable trick massively increases the accessibility of the I2C fun, I bowed down to my pathological need to be a rule-breaker....🤪

Yes, I looked at SPI but preferred I2C for many reasons that are far too lengthy to explain here... :wink:



.
Last edited by MartinB on Tue Jul 17, 2018 9:28 pm, edited 2 times in total.

torrind
Posts: 82
Joined: Fri Dec 01, 2017 4:57 pm
Location: Bristol
Contact:

Re: I2C 4 U

Post by torrind » Tue Jul 17, 2018 10:12 pm

Thanks for the explanation Martin - I actually understood that!

JGH has competition now! :lol:

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Tue Jul 17, 2018 11:03 pm

No worries Darren.... 8)

Duncan wrote:edit: that post above, near the end, links back to a blog post which is pretty interesting as well.

Just read it and yes, as you say, a fascinating read and very relevant to our own RTC antics! :D

and wrote:I dont think you mentioned how you intend to attach the RTC to the machine without using the Userport, I am assuming this is under your (figerative) hat for now. But just wondered if the board would be connected as is, or some sort of custom hardware would be knocked up.

No, I didn’t because I’m not actually sure yet myself :). I’d really rather not invoke any new hardware because that then detracts from the quick’n’easy and cheap’n’cheerfulness of ‘the I2C project’. For software bitbanging purposes (yes, that’s what’s going on behind the scenes again), the I2C gadgets do need to sit on some latched lines such as the 6522 so I’m still looking at a passive parasite fit but choosing lines that won’t inadvertently trigger an RTC awakening. Could even perhaps switch the RTC to sit on the Port A side of the User VIA since that otherwise gets little use and a careful choice of lines could guarantee the correct behaviour... :-k
Last edited by MartinB on Tue Jul 17, 2018 11:19 pm, edited 1 time in total.

User avatar
Elminster
Posts: 3143
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: I2C 4 U

Post by Elminster » Sat Jul 21, 2018 1:54 am

As per other post, Electron back in the land of the living, so I hacked off the diode, seems to work. Still knew the time when I turned it back on. So I now eagerly await the RTCRAMagic solution.
Last edited by Elminster on Sat Jul 21, 2018 1:55 am, edited 1 time in total.

User avatar
KenLowe
Posts: 412
Joined: Mon Oct 18, 2004 4:35 pm
Location: Scotland
Contact:

Re: I2C 4 U

Post by KenLowe » Sat Jul 21, 2018 8:09 am

MartinB wrote:
Sun Jul 15, 2018 8:03 pm
Hey, not at all! - if you have a solution underway then by all means take the lead and I'll stand easy! :D
Please don't wait for me to complete this. My time is limited, and I can only work on my projects intermittently :(. Perhaps by this time next year...

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Sat Jul 21, 2018 12:05 pm

No worries Ken, I’ll pursue my train of thought anyway and see what that brings 😎

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Thu Jul 26, 2018 5:48 am

I’ve just about finished testing of the V2 I2C rom so I’ll be posting that in the next couple days.

I previously wrote:A major v1 to v2 up-issue because in addition to the one bug-fix, I’ve done some significant code re-work and the I2C link now runs about 25% faster.
In fact, testing the outturn rom on real hardware (a Beeb), the I2C clock speed during reads and writes has actually increased by almost exactly 50%. For the nerdy and because pictures are more interesting than words, the scope shots below below reveal that we have gone from a nominal 13KHz I2C clock to a nominal 20KHz.....

I2C V1 Clock Freq.png
I2C V1 Clock Freq.png (7.01 KiB) Viewed 671 times

I2C V2 Clock Freq.png
I2C V2 Clock Freq.png (7.3 KiB) Viewed 671 times


This clock speed increase won't necessarily always translate to a 50% increase in overall I2C data throughput because in creating the entire I2C protocol via software bit-banging, there are other overheads associated with the serialisation of data. However, during tasks involving a high volume of data transfer such as writing to eeprom, the speed increase will be significant.... :D =D>


.
Last edited by MartinB on Thu Jul 26, 2018 5:49 am, edited 1 time in total.

User avatar
Elminster
Posts: 3143
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: I2C 4 U

Post by Elminster » Thu Jul 26, 2018 7:26 am

Did I miss a new feature list? Or was this ‘just’ a code rewrite? I won’t have time till break it till next week anyway.

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Thu Jul 26, 2018 9:12 am

No, there are no new ‘features’ in the v2.0 I2C rom. It’s purpose, other than fixing the only known bug, was a rewrite/restructuring exercise to fundamentally improve the clock speed and hence the I2C performance. This amounts to me removing much of my initial cautious granularity from the v1 code now that we have a proven and reliable system in place. Once v2.0 is ‘out there’ and users are happy, I’ll start adding more functions such as some of the RAMagic! features.

torrind
Posts: 82
Joined: Fri Dec 01, 2017 4:57 pm
Location: Bristol
Contact:

Re: I2C 4 U

Post by torrind » Thu Jul 26, 2018 8:37 pm

Great work as always Martin! Well done. =D>

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Fri Jul 27, 2018 12:04 pm

Thanks Darren 8)

Definitely finished all the testing now but it's surprising how much work there is to actually release a rom to a good standard - I've got to make and test Beeb and Elk versions (a necessary separation in the case of this particular rom), there's an update to the manual associated with the fixed bug and then there's the images and finally the zips to post. It's definitely not a two-minute job but hey ho, it's all in hand.... :)

(Ken - your blank line leader suggestion for *HELP is in there too!)

User avatar
KenLowe
Posts: 412
Joined: Mon Oct 18, 2004 4:35 pm
Location: Scotland
Contact:

Re: I2C 4 U

Post by KenLowe » Fri Jul 27, 2018 1:42 pm

:D You’re a star! Great piece of software. Let me know if I can help with testing.

User avatar
MartinB
Posts: 5025
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: I2C 4 U

Post by MartinB » Fri Jul 27, 2018 8:07 pm

Thanks for the kind offer Ken but (cue famous last words) I’m reasonably confident that it’s good to go because we already have a great selection of proven I2C gadgets and accompanying software ditties for testing purposes.

That said, I will of course look to you and my other ‘followers’ to give v2 a good workout as soon as I publish... =D> 8)


.
Last edited by MartinB on Fri Jul 27, 2018 8:09 pm, edited 1 time in total.

Post Reply