Go Down

Topic: MCP9808 I2C Communication (Read 429 times) previous topic - next topic

GarageGeek

Jul 21, 2018, 02:37 am Last Edit: Jul 21, 2018, 02:40 am by GarageGeek
Hey all,

I've been working on a small battery powered temperature logging device for use when hiking and have run into trouble communicating with my temp sensor.  I'm using a standalone ATMega328P running at 1 MHz on 3.3V that communicates with a MCP9808 temp sensor, DS3231 RTC, and a CAT24C512 EEPROM (512Kb) all via I2C.  This is powered by a single AAA cell via a boost converter.

I have no trouble communicating with the RTC or the EEPROM, but the MCP9808 isn't responding to any calls on the I2C bus.  Here's what I've tried this far:

Verified power and ground
Verified address pins (All GND for 0x18)
Power supply decoupling at the chip (Verified clean with oscilloscope)
Powered from bench power supply without boost converter
SCL and SDA at the pins (Verified with oscilloscope)
1 and 8 MHz internal clocks on the uC
100 & 400 kHz I2C clock (Verified with oscilloscope)
Removed the RTC and EEPROM from the board
Adafruit Library and example code
JChristensen Library and example code
Generic I2C address scanner (Finds RTC and EEPROM but no address for MCP9808)
Replaced the MCP9808 with another

Not one solitary response from the temp sensor.

Schematic is attached.

Thanks in advance for any help.

Koepel

#1
Jul 21, 2018, 08:48 am Last Edit: Jul 21, 2018, 08:49 am by Koepel
If the I2C Scanner can not see the MCP9808, then it is not there.

Do you have an Arduino Uno ? to test the MCP9808. The MCP9808 can run at 3.3V and 5V.
Are you sure that you have genuine MCP9808 chips ? Can you read that number on the chip ?
You replaced the MCP9808 with another, is that other one from the same batch from the same seller ?
Have you done something with the SDA and SCL wires ? They should be short wires and not in a flat ribbon cable.

As you might have noticed, I'm looking for weird causes, because it should work.

Did you know that there is a bootloader which allows to use part of the Flash to store data ? With a small sketch, there might be 10 kbytes to store data.

A few notes about the schematic:

There is no diode from /RESET to VCC.
Do you plan to use /RESET and RX and TX to upload a sketch with a 100 nF capacitor from DTR to /RESET ?
Because of that capacitor, there could be a voltage peak on the /RESET, turning the /RESET in to High Voltage programming mode. That could corrupt the bootloader.

130 ohms for the Led ? Must it really be that bright ? Can you use a extra bright led instead of extra current ?

Running with the internal oscillator might cause trouble for the baudrate and other timing based protocols.

GolamMostafa

#2
Jul 21, 2018, 10:51 am Last Edit: Jul 21, 2018, 02:13 pm by GolamMostafa


We need to understand the meanings of the remarks made by (1) and (2) in the above address table of the EEPROM chip. What is 'device pin configuration?' Which EEPROM will have the address 0x48?

GarageGeek

#3
Jul 21, 2018, 06:43 pm Last Edit: Jul 21, 2018, 06:58 pm by GarageGeek
Are you sure that you have genuine MCP9808 chips ? Can you read that number on the chip ?
You replaced the MCP9808 with another, is that other one from the same batch from the same seller ?
...unbelievable. Well played, sir.  I just looked at the chip under a magnifier...it's got a D2745 on the top line and a 639A3 on the bottom line.  It seems that Digi-Key shipped a DS2745 in a MCP9808 labeled bag.  I feel like an idiot.

I should've been more suspicious about this order because the .1uF 0805 bypass caps I ordered were on the invoice but not in the box so I ghetto bodged through hole caps from my parts bin onto this prototype.  I've never had any trouble with Digi-Key, but this order has been a disaster.

Did you know that there is a bootloader which allows to use part of the Flash to store data ? With a small sketch, there might be 10 kbytes to store data.
I learned about this a while back but had forgot about this option.  This is done via PROGMEM, right?  This version is a prototype and I plan to expand this project to record additional parameters, so I think I'll need additional memory space anyway.  Thanks for the reminder.  I had only considered the onboard EEPROM.

A few notes about the schematic:

There is no diode from /RESET to VCC.
Do you plan to use /RESET and RX and TX to upload a sketch with a 100 nF capacitor from DTR to /RESET ?
Because of that capacitor, there could be a voltage peak on the /RESET, turning the /RESET in to High Voltage programming mode. That could corrupt the bootloader.
I upload my programs with an AVR ISP Mk2 via an AVR ISP header on the board, so all I've ever needed to do was include the 10k resistor to allow the ISP to pull RESET low for programming. The RX and TX pins connect to an external Serial-USB FTDI adapter that I use to download the data into a .csv file and chart in Excel.  Do I need a diode or cap here?!?  Never used this in the past and I don't use the software reset.


130 ohms for the Led ? Must it really be that bright ? Can you use a extra bright led instead of extra current ?
Valid point.  I've had trouble seeing LED's in the bright sunlight while I'm hiking, so I kept the current high.  Extra bright LED vs high current would be a wise tradeoff.  Because this is battery powered and meant to run for over a week, I only allow the LED to blink when data has been recorded and when selected by turning a DIP switch on.  I use this to see if it's still alive while on the trail 4 or 5 days in.

Running with the internal oscillator might cause trouble for the baudrate and other timing based protocols.
Hmmm.  Hadn't considered this.  Is this because the internal oscillators just aren't as precise?

So far, I've recorded date and time stamps every 5 minuets for about 10 days and was able to download from the EEPROM to a laptop with no trouble at any selected baud rate.  Maybe I'm lucky.

Would you recommend an external oscillator when using timing based protocols in general?  How would this impact the power consumption?  I'm trying to keep this running at 1 MHz for power saving reasons.


Thanks so much for the inputs!  I hadn't considered much of what you've pointed out and I really enjoy expanding my understanding.

Board layout attached for review.  Photos were too large to attach.

GarageGeek

We need to understand the meanings of the remarks made by (1) and (2) in the above address table of the EEPROM chip. What is 'device pin configuration?' Which EEPROM will have the address 0x48?
I understand this to be that chips are a default address 0011XXX, where X is configurable as 1 or 0.  I'm using 0011000 (0x18).

The second option is only available as factory requested addresses.

Koepel

You don't need a diode, when you are not using the DTR via 100nF to /RESET to upload a sketch.

If it works, use the internal oscillator.
That oscillator can be tuned with the OSCCAL register. I had soldered an ATmega8 once, using the internal oscillator, and it turned out to have the wrong timing with freezing temperatures. So I made a formula that changes OSCCAL according to the temperature :o

PROGMEM is to store constants in Flash memory.
You can read the Arduino reference about PROGMEM and the Nick Gammon Tutorial and you know almost everything about PROGMEM.

I was talking about a special bootloader that enables to write the Flash during runtime: https://hackaday.com/2015/07/03/arduinos-and-other-avrs-write-to-own-flash/. It is fun that it is possible. You have an external EEPROM, so you don't need it.

Nick Gammon wrote a nice tutorial about power: https://www.gammon.com.au/power
Did you know that 1 MHz does not need to be energy efficient ? because the code takes a long time to execute. Perhaps running at 8 MHz and going into sleep after that uses less power.


GarageGeek

If it works, use the internal oscillator.
That oscillator can be tuned with the OSCCAL register. I had soldered an ATmega8 once, using the internal oscillator, and it turned out to have the wrong timing with freezing temperatures. So I made a formula that changes OSCCAL according to the temperature :o
Nice!  I'll keep that option in mind.  I haven't done any testing at temperature extremes yet.  I think I may add an 8 MHz external oscillator to version 2, if for nothing else than testing it out.

PROGMEM is to store constants in Flash memory.
You can read the Arduino reference about PROGMEM and the Nick Gammon Tutorial and you know almost everything about PROGMEM.

I was talking about a special bootloader that enables to write the Flash during runtime: https://hackaday.com/2015/07/03/arduinos-and-other-avrs-write-to-own-flash/. It is fun that it is possible. You have an external EEPROM, so you don't need it.
Ohhh!  I see the difference now.  I'll also keep this in mind for a future option when I just need a little more memory.

Nick Gammon wrote a nice tutorial about power: https://www.gammon.com.au/power
Did you know that 1 MHz does not need to be energy efficient? because the code takes a long time to execute. Perhaps running at 8 MHz and going into sleep after that uses less power.
This was excellent read.  Guess I'll have to do some testing!

Thanks again for the insight.  Do you have any suggestions/critiques for the board layout I've posted above?  I'm a pure hobbyist, so I'd appreciate any advice.

Koepel

Do you have any suggestions/critiques for the board layout I've posted above?
No, you could start a new topic for that.

GolamMostafa

Thanks again for the insight.  Do you have any suggestions/critiques for the board layout I've posted above?  I'm a pure hobbyist, so I'd appreciate any advice.
1. The Battery polarity is shown wrong. It should be reversed. Also, there is no circuit designation for the Battery like E1 or B1 or something else. It would be nice to have the EMF of the Battery shown.

2. I always print the voltage rating of C1/C2 in the schematic. This helps to avoid mistake when I build the board as 10 uF capacitors come at various ratings.

3. If you are using 32-pin ATmega328, then the GND pins are: 5, 3, and 21. What is in your schematic: 3*2, 21.

4. If you are using 32-pin ATmega328, then the 5V  pins are: 4, 16, and 18. What is in your schematic: 4*2, 18.

5.  I would recommend to add micro RESET switch in parallel with C4. This will help to diagnose the board in the future (if it malfunctions for some reasons).

6.  You have not given the PCB layout of your board; we could see the organization of your chips around the MCU. It is very important to have optimum orientation/organization of the chips of the board to avoid unnecessary generation of noise signals.

7.  Few inconsistencies in the symbols of your schematic like:
(MOSI>: it could be (MOSI)
(SDA} : it could be (SDA)

Thanks for inviting critiques.

GarageGeek

1. The Battery polarity is shown wrong. It should be reversed. Also, there is no circuit designation for the Battery like E1 or B1 or something else. It would be nice to have the EMF of the Battery shown.

2. I always print the voltage rating of C1/C2 in the schematic. This helps to avoid mistake when I build the board as 10 uF capacitors come at various ratings.
Done.  Must've been sleepy when I placed the battery. :o

3. If you are using 32-pin ATmega328, then the GND pins are: 5, 3, and 21. What is in your schematic: 3*2, 21.

4. If you are using 32-pin ATmega328, then the 5V  pins are: 4, 16, and 18. What is in your schematic: 4*2, 18.
This seems to be the way Eagle displays multiple connections.    <First Pin>*<Number of Pins>

Confirmed here: https://electronics.stackexchange.com/questions/254483/eagle-multiple-pads-to-one-pin

Also, I believe Vcc connects to pins 4 & 6 (not 16).


5.  I would recommend to add micro RESET switch in parallel with C4. This will help to diagnose the board in the future (if it malfunctions for some reasons).
I typically add a reset switch, however, for this project I've simply soldered a short breadboard wire to the board that I use to pull RESET down.  Just as easy as a switch, but temporary in nature so it can be removed.

6.  You have not given the PCB layout of your board; we could see the organization of your chips around the MCU. It is very important to have optimum orientation/organization of the chips of the board to avoid unnecessary generation of noise signals.
Board layout posted in post #3.  Sorry, I should've posted them all together but didn't think about it until later.

7.  Few inconsistencies in the symbols of your schematic like:
(MOSI>: it could be (MOSI)
(SDA} : it could be (SDA)
I think the low resolution .gif file made a few things appear wonkey.  All names are in parentheses.

Thanks for the inputs!



Since this has evolved outside the lane of this thread, I'll wrap this one up and post under the proper thread at a later time.

Thanks again to all.  What a wonderful resource.


Go Up