M0+ I2C Problems - Can't Get RTC Working

I cannot get any RTC example code working on any M0+.

I have tried:

Feather M0 Breakout
Sparkfun SAMD21 Mini Breakout
My personal board that I'm trying to build up and debug. (Which was just migrated from a 328P and worked flawlessly.)

1.6.4, 1.6.5, 1.6.8, 1.6.9
Win7pro, Win10, Mac 10.6.8, Yosemite

DS1307
MCP79412

Time libraries
TimeLib libraries
RTClib libraries
MCP79412RTC library by JChristensen

Scoped the SCL and SDA pins at the RTC, they are getting a good, clean square edged signal
4.7K pullups are in place (have also tried 10K as spec'd by MCP79412 datasheet @ 100kHz)

"Manual" reading from the MCP79412 using basic I2C commands (reading the ID from the chip I get all 0xFF)

Is there any known weirdness with I2C and the M0+ hardware?

Any ideas of where to look next?

Hi there,

You can fìnd an example of I2C working with Arduino ZERO here:

https://www.picotech.com/support/topic24371.html

Complete sketch available there. The above is for Arduino ZERO from Arduino c.c. with IDE 1.6.7 by Arduino c.c.

If, on the contrary, you have an Arduino M0 from Arduino.org, then please consider you are working with a different bootloader, the IDE is 1.7.8 or later, by Arduino .org. In this case please look here first:

Cheers!

Grazie glovisol!

I haven't got it solved yet, but your post and links gave me an idea.

I found a TMP102 (I2C temperature sensor) breakout board and put it on the I2C bus and tested it. Works like a champ. So, my problems lay within the RTC code or the RTC footprint/hardware on my board. But, at the very least, now I can confirm that I2C is working on my hardware.

I'm using the Adafruit bootloader which appears to be the standard .cc Zero bootloader.

It appears to be a library issue with the M0+.

The standard Time, TimeLib and DS1307RTC libraries are not compatible with the M0. I've gotten a DS1307 working with Adafruit's RTClib.

Anyone know if the Time/TimeLib libraries have been ported yet for the M0+?

Hi,

I do not understand which Arduino are you working on..... If it is marked "M0" or "M0 PRO" then you have a device by Arduino.org. with an Arduino.org bootloader and you might have comp. problems. Also please specify which IDE are you using.

It is not an "Arduino" product. It is an ATSAMD21G18 board of my design. The bootloader is the Adafruit version from here. I believe it is based on the standard Atmel bootloader?

These are the boards I have tried:

I cannot get any RTC example code working on any M0+.

I have tried:

Feather M0 Breakout
Sparkfun SAMD21 Mini Breakout
My personal board that I'm trying to build up and debug. (Which was just migrated from a 328P and worked flawlessly.)

I am using the .cc 1.6.8 IDE.

The latest developments are:

I've got the DS1307 working, but only with the Adafruit RTClib library. (I know the 1307 is a 5V part.) If I use any of the DS1307RTC or Time libraries and examples, the code will hang at the first I2C write. Also, I've compared the object files for the compiled Wire libraries and they're identical between both the working and non-working code.

I found it.

The examples weren't calling Wire.begin() before their first I2C write command.

Once I put a Wire.begin(); in the setup of any example that didn't work, it become functional.

Well, it looks like the difference between the working and non-working code is where the RTC class is instantiated.

The working code, the Adafruit RTClib and ds1307 sketch, explicitly instantiates an RTC prior to setup.

RTC_DS1307 rtc;

All of the non-working code relies on an instance of an RTC that was created in the DS1307RTC.cpp:

extern DS1307RTC RTC;

The interesting thing is, if I try to create a different instance of DS1307RTC in the ReadTest example sketch, the sketch will flash but there won't be any serial port to connect to.

The examples weren't calling Wire.begin() before their first I2C write command.

  1. Wire.h and Wire. begin() were present on the sketch I proposed as example.

  2. The SAMD21 processor is extremely flexible and all pins can be multiplexer controlled. You will find many examples of this, written by MartinL, here:

cheers!

Hi glovisol,

I couldn't find a link to a sketch or any code in the link that you provided to your Picolog project. I only saw a .plw file?

But that is here nor there now. The big question is why are the DS1307 and Time libraries broken on the Zero? I suspect it has something to do with when/where the RTC is instantiated. Unfortunately, I don't have smarts (or the time at this point) to try to figure it out.

I had seen the thread regarding muxing PWM to desired pins while I was designing the current board. That was part of the reason I was less than diligent about sticking to Arduino native pin functionality. I figured it would be fairly easy to move things about behind the scenes. I could probably muddle through reassigning PWM functionality based upon the thread, but my skill wouldn't allow me to translate that knowledge/experience into moving analogs around. In the end, I'll go with a patch on the prototype PCB and another revision to the design.

Thanks again for your time and ideas.

John

Hi John,

Hate to leave loose ends. I enclose the I2C Sketch, which you can find, with more info here:

https://www.picotech.com/support/topic24301.html

If you read the entire series: ARDUINO ZERO AS BUFFER/ISOLATOR FOR PICOLOG DA LOGGERS, from 1 to 6, you will probably find many replies (and solutions) to your problems.

sketch_Universal_Translator_8_I2C.ino (10.7 KB)