Instructables

I2C to SPI BASIC code conversion?

 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.

 Here is the link to the clock schematic:

http://tech-tut.com/wp-content/uploads/2008/08/real_time_clock_advanced_schematic.pdf
 
 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

G4224T7 months ago

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.

LED Maestro (author)  G4224T7 months ago
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)

This might be a hint for me to just get the DS1305

Receiving 0xFF sounds like it could be a default return value from your Picaxe I2C routine, although as I mentioned I haven't used it so I'm not sure.

Have you remembered to reset the DS before reading from it?

Write 0xD0 to it to put it into write mode
Write 0x00 to it to set its start register to zero
Issue a Repeated Start command to finish but keep comms open.
Write 0xD1 to it to put it into read mode

Each subsequent byte read should then return Sec, Min, Hr, WeekDay, Day, Month, Year.

Hope it helps.

steveastrouk7 months ago

Its a question of identifying what the i2c calls do and translating them. The 7221 is pretty forgiving. Just remember to turn it on as your first instruction

LED Maestro (author)  steveastrouk7 months ago
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 it
Thanks again
rickharris7 months ago

Your will get a far better response in the Picaxe forum.

http://www.picaxeforum.co.uk/forum.php

LED Maestro (author)  rickharris7 months ago
Yeah I know but I've had mixed experiances with the forum that's why I prefer to ask here first. But thanks, I will post my question there too.