Soooo…what exactly happened last night?

So, after getting some sleep, I figured I’d update to discuss all the things I figured out.

Firstly, I got my new programmer!

Love the box-art on these things. Kind of makes me wonder how many MIPS my programmer can do (by the way, that’s a Pb-free rainbow cannon).

So, I’m going to go ahead and talk about what I did wrong because I really need to remind myself of this more often. BYPASS CAPS!
(Yes, I drew this on the floor with chalk at about 8am.)
I was having this odd issue where my circuit was working until I disconnected the programmer. It turns out that the programmer produces a little bit of capacitance on the power rails, and disconnecting it removes this. The failure mode was that my LEDs would just light up at random and then freeze.
I made the poor assumption that the programmer was somehow chatting with the chip to make it work and removing it was messing up my code. Because of this, I disabled the External Reset Disable pin (RSTDISBL) which makes my programmer useless, however the code I already had programmed will still run when I power up the chip. Frantic, I tried something different with my second chip and set the debugWIRE Enable. debugWIRE, I later found out, is a protocol by which you can completely control a ATMEGA chip through a single wire. Unfortunately for me, you need a special (expensive) programmer to do this. I don’t have such a programmer, so the chip is essentially useless to me.
I ordered some new chips.
In the future, I’ll try bypass caps earlier. This happens time after time…
Anywho, it works! I2C is a really cool protocol. The whole thing is done with just two wires, so there has to be a lot of coordination as far as when to relinquish control of the bus. Each device must have a unique 7-bit address. The LM75A’s address is 1001XXX where the Xs are set by pulling the A0, A1, and A2 pins high or low. I set mine all low so the address is 1001000. Reading the temperature basically goes like this:
ATMega48A microcontroller on left, LM75A temp sensor on the right.
Alright dudes, let’s do this!
Is there a LM75A in the house that I can write to?
Aiiight, write this down, I wanna look at location 0x0h
Ain’t no thang
Alright, let’s do this again!
Is there a LM75A in the house that I can read from to?
Here’s the first part
Got it
Here’s the second part
Got it, and that better be the last one.
Or… a less colorful version…

So doing this will return two bytes. The temperature is recorded in 2’s compliment. It’s a 11-bit number with the first 8 bits in the higher order byte and the last three in the highest bits in the lower order byte. This number, when multiplied by .125 should result in the current temperature in Celsius. The code that’s now permanently frozen on my micro-controller outputs the high order byte of the temp readout on the Port D LEDs.
(Reading left to right) that’s 00010110. There are three more bits on the low order byte that you can’t see now, but they’re not very significant for rough estimates. Let’s just make them all zero. Let’s see here…
10110000 in decimal would be 176. 176*.125C = 22C or 71.6F which is a totally reasonable temperature.
This thing is really fun to watch too.

One thought on “Soooo…what exactly happened last night?

  1. Pingback: QR Clock | ch00ftech Industries

Leave a Reply

Your email address will not be published. Required fields are marked *