Browsing Posts tagged i2c

Adding memory? I forgot. 16/04/13

You’d have thought that with all this learning and fun stuff happening here at Wardian Towers, that as I get further and further into this electronic ‘lark’, first with PIC’s, then I2C, then real time clock counters, then I2C input/output devices, then into iButtons and all the wonders they produce; you’d have thought that it would get easier as time went on.

Scientists do say that the brain is in fact like a giant muscle, and that the more you use it, the easier it gets as it becomes more familiar with cramming it with yet more and more knowledge.

Well, I can report that from this end, it most certainly doesn’t seem to.Before...

But then again, I guess I’m not as young as I used to be, and maybe doing this kind of stuff is really for the twenty-somethings.

But then again, if I was twenty-something again, I’d be either playing on my X-Box, or drooling over a new Porsche, or Armani suit.  BUT, I’ve been there.  Got the T-shirt; read the book.  Boring.  Shallow.

Whatever.

To the right here is the board before I fitted the new memory chip.  The chip itself is a Microchip device called a ’24FC512′.  This denotes it’s from the ’24’ series of serial EEPROM (Electrically Erasable Programmable Read Only Memory) chips, and it will store up to 512 K bits of information.  Note the ‘bits’ bit.  In more user-friendly language, it will store up to 64 K Bytes of 8-bit words. (As we all know, there are 8 bits to a byte.)

The datasheet tells me that I can have up to four of these little guys sat on the same I2C lines, each individually addressable, so I could have up to 256K bytes of information storage on just four chips.

Frightening.

Hooking the thing up was ridiculously easy, and took a matter of minutes -I just had to remember to wire the SDA (data) and SCL (clock) lines properly.  Mix them up and all kinds of exciting and unexpected stuff would happen....After

There’s also a pin which you can either wire up, or even have sat on another output pin from the PIC.  This pin is the ‘Write Protect’ pin.  With it sat at 5-volts, you can read the contents of the chip, but it won’t let you write, while tying the pin to ground gives you unfettered access to everything.  This is a pretty useful feature, and I may well use it if I get the opportunity.

And here is the chip in circuit.  As I said, ridiculously easy to wire up, and you can barely notice any other new components.  They’re there, though.

And so to programming it.

And this is where all the ‘fun‘ started.

I set up an entirely new project in the X-IDE program I use from Microchip so as not to contaminate the other stuff I’ve written.  Okay, doing it this way may take longer, but it gives you a ‘fresh canvas’ to work on, and it prevents great lumps of code being sat in the program for other functions that you will never use in this.  It also focuses the mind on just what you really need in there to get the program running.

For this program, I needed the new RS232 program I’d written the other day so I could actually see in a box on the screen what the processor was putting into the RAM and also what was coming off the RAM.  Yes, I could have done it with simple LED’s already sat on the board, but that would have been pratty.

After several hours, many cups of tea, and of course, ‘consultation chats’ with young Alfie (…He’s a bit ropy on I2C, but learning fast…), I finally nailed it when I realised that you never use the ‘Acknowledge’ pulse when you’re writing to the device, but when you read from it, you must acknowledge every byte apart from the last one where you send a ‘NotAcknowledge’ pulse.

Oh, and to be on the safe side, you need plenty of ‘IdleI2C()’s thrown around, just for good measure.

Again, last night was another late one, but I can report total success.

I can now write data to this chip, switch the whole thing off, have a cup of tea, switch it all back on, and the data is still exactly as I wrote it.

Today, I have other, much less fun stuff to do, and of course Wednesday and Thursday are ‘Plotting’ days.

But I shall return soon to this project -hopefully before I forget everything I’ve done.

Unlike the RAM I’ve just fitted and programmed, unfortunately, I do forget stuff when switched ‘off’.

 

From flashing LED’s…

No photos tonight, I’m afraid.  The camera battery is flat, and anyway, in this light, they probably wouldn’t have come out.

So you’re going to have to take my word for this…

After long, long hours of head scratching, and moments of seeming madness, I’ve finally cracked this i2c lark.

Saturday’s missive was all about how I’d managed to write data down the i2c bus.

As it turns out, this was the easy part.  Apparently, even my cat could have done it, if he’d been bothered.

Getting i2c to receive coherently and on time is apparently quite a big beef amongst the electronics fraternity, and Microchip -the makers of the PIC’s I’m using, haven’t done themselves many favours. Briefly, the way they’ve implemented it is, well, decidedly pratty.

A very long and boring story shorter, but just suffice to say I’ve now got the little board you saw on Saturday not only flashing the LED’s if I want to, but I’ve whacked on an RTCC (Real Time Clock Counter) onto the i2c bus too.

The input/output chip and the clock are quite happily sat on the same two lines (SCL and SDA if you’re that bothered), because they have different i2c addresses.  Before you talk to a chip, you have to give it the right address, which kind of makes sense.

SO, I’ve now got that same board, and you’ll remember it has those four displays left over on it.  Well, these are now coded up so the display simply reads minutes and seconds from the RTCC.  I haven’t set the clock properly, so the numbers are pretty meaningless, but the fact is that even if I completely unplug the board to switch it off, this little clock keeps on ticking -in much the same way as your PC clocks does when you power it down at night.

So, when I come to switch it on again, not only has the clock advanced, but it’s advanced properly to show the correct minutes and seconds that it was when it was on previously.

I guess I’m not explaining this very well, I guess I’m a little tired, but I’ll get some proper photos tomorrow to explain.

Hells, I may even set the clock properly so it shows the correct time!

The next job will be to work with that little input/output chip to get it to input, rather than simply lighting LED’s.

This shouldn’t be quite as difficult as today’s marathon effort, but I have the added ‘fun factor’ of having to set it up so that a button press will interrupt the processor.  This will then send out a command to find out just which button was pressed.

Why?

Well, this vastly saves on processor time.  Rather than the processor having to ‘poll’ the inputs every few milliseconds, and all the bother that entails, this way, it’ll only do something when it’s interrupted.

There’s even a possibility of being able to ‘wake’ the processor from ‘sleep mode’ with a button press.  This then does away with a whopping great on/off switch -it’ll just be a button press to turn on.  …Maybe, we’ll see…

I guess it all sounds dead simple, but take it from me -it’s not!

This is One Tired Wardo, signing off!

Ladies and Gentlemen…

…And cats.

At about midday today, there was great jubilation here at Wardian Towers.

Yup, you guessed it.  I got a couple of LED’s to light.Two LED's.

‘No Big Deal,’ you may think.  ‘Surely, a switch and a battery would achieve the same thing?’

And you’d be dead right.  ‘Why use microprocessors and the ‘C’ programming language, when all you need is a switch?’

Ah, but there lies the rub.

Those two humble (…but very, very bright…) LED’s are being controlled by the black chip just down and to the right of them.  For the more technically minded, it’s a Microchip MCP23008e i2c input/output chip.

However, the key bit of that information is ‘i2c’.

After what seems like years of half-heartedly trying to ‘get into’ i2c, then giving up, I’ve now finally achieved i2c communication across two chips in the programming language ‘C’.

Even though I’d studied it extensively with Bang & Olufsen many years ago, I’d never built and programmed an i2c system from scratch until this lunchtime.And the other two lit!

The proof here is to the left.  I changed one byte of information sent to the MCP23008, and the other two LED’s are now lit.

Okay, not earth-shattering in itself, but you may remember my excitement all those years ago when I got my first ever LED to light when programmed from a PIC?

The same feeling, but better.

These four little LED’s now pave the way for the really fun stuff as I whack the RTCC (Real Time Clock Counter) into it. This will then tell the PIC the exact time and date whenever it switches on.  This paves the way for ‘workouts’ on the bike to be correctly time and date stamped, so I’ll know just how much was put in, or taken out, of the battery over a given period.

Then, I’ve got the excitement of adding the cute little LCD display panel that also runs from i2c.  Different chip, but same protocol.

So, you can see, Dear Reader, things at Wardian Towers are moving forward.

…Even if the weather isn’t!


SEO Powered By SEOPressor