Main Menu

Secondary Menu

Author Options:

I2C to SPI BASIC code conversion? Answered

Hello all. Pretty daft and most likely simple sollution to those who know what they are doing I'm sure. I am building a 132 LED clock (60 for seconds, 60 for minutes and 12 for hours). I'm using a Picaxe 28X2 and will most likely be using 3 MAX7221's to display the LED's, 1 each for the hours, minutes and seconds. I'm currentlty using a DS1307 RTC module to keep time. Exposition over!

My question is, I am using open source code from a guy who made a clock using Pic 28X1, MAX7221 and DS1305 displaying on four 7-segment displays. now the differences between the Pic's with regard to coding I can handle, although I do have a 28X1. The fact that the DS1305 and 1307 use SPI and I2C respectively means that the differences between comms protocols are confusing the hell out of me.

Now please forgive the length of this question. Basically, I need some pointers as to whether it would be better to try and convert the code to use I2C for the RTC and stick with SPI for the MAX or should I just buy a DS1305 at almost £6 per chip and make my life a bit easier? I have already tried using the code with my 1307 but the 7-seg display I have just stays on the No2.

As for the differences in display type...well I'll come to that once I get the timing working.

If I've left anything out or you need more information then please let me know.

And the code is far too long to be pasted here I'm affraid and the file I originally got it from had converted it into word which pushed all the lines together. That was a fun few hours sorting that out! Thanks in advance

Discussions

I would imagine that the software you are converting uses sub routines to talk to the DS & MAX appropriately. Ive never used the Picaxe but I would also imagine that it has comparable commands for both SPI and I2C. Converting the software wouldn't be too much of an issue if this were the case.

Finding the relevant subroutines and / or function calls and replacing them with the correct commands should be straight forward enough but be aware that your schematic will need changing too.

Both chips will currently sit on the same SPI bus and have different select lines. If you change the DS to I2C you will need to remove it from the SPI bus, disconnect the SS lines and wire it onto the Picaxe I2C bus.

indeed you are correct that it uses subs to get the time and then display the time. I have started to replace the code for the DS1307 but I'm now having a problem I've experianced a few times in that the DS1307 returns constant variables of 255 ($FF) for the hours, minutes and seconds. This is the 3rd time its done this and I've previously had to use 2 different fixes to solve of (neither of which are working now)

And this is why I come here first. Straight to the point answers without having to ask for code, data sheets, what it's being used for. Thanks you, I shall have another look at the code and go though itThanks again