PDA

View Full Version : How to use the DS1307RTC with the teensy audioshield



ifelipeg
05-18-2016, 05:14 PM
Hello, i have been struggling a lot with this problem because the real time clock uses the same ports as the audio board for the communication, sda and scl 19-18 in the teensy.

i decided to use the ic2_t3 library that allows to use the second SCL-SDA ports (29-30), the problem was that the audio.h defined some objects and funtions that were redefined with the ic2_t3.h, what i did was changing the code of the i2c_t3.h and .cpp rewriting:

.h file

Line 803

extern i2c_t3 Wire0;

Line 314

friend void i2c0_isr2(void);

Line 300

extern "C" void i2c0_isr2(void);

.cpp file

Line 1729

i2c_t3 Wire0 = i2c_t3(0); // I2C0

Line 1245

i2c->DMA->attachInterrupt(i2c0_isr2);

I really hope this can help someone.

ifelipeg
05-18-2016, 05:15 PM
So if i want to use the first port i need to begin Wire0 and not Wire :p

ifelipeg
05-18-2016, 05:18 PM
I forgot to say that i modified the DS1307RTC library, initializing with the i2c_t3 library in stead the Wire and replacing all the Wire function with Wire1

MichaelMeissner
05-18-2016, 06:44 PM
Note, i2c is a shared bus. That means you can hook many different things on the bus, as long as each slave has a different address.

On the Audio adapter, the SGTL5000 uses address 0x0A (10 in decimal), and the WM8731 uses address 0x1A (26 in decimal).

Your typical real time clock uses address 0x68 (though I have a DS3231 that also uses addresses in the range 0x50-0x57).

So, all you would need to do is hook up your RTC to SDA, SCL, 3.3v, and ground.

As you've discovered, there are two i2c libraries on the Teensy. You have to use one or the other for the whole application. Since the Audio library uses Wire, that means you have to use Wire for accessing the RTC, and you won't have access to the advanced features of t3_i2c (such as a second i2c port). So, you would have to revert the changes in your library.

Alternatively, note the Teensy 3.0/3.1/3.2 does have their own real time clocks, that you can access without having to use the i2c bus. You would need to power it via a coin cell battery, so it keeps time when the Teensy is powered off. Note, there is no temp. correction in the RTC, like there is in the DS3231, so it may drift a bit, unless you use the temperature sensor in the Teensy to correct for the changes. The Teensy RTC is documented here: http://pjrc.com/teensy/td_libs_Time.html#teensy3.

Note, the Teensy LC does not have a usable RTC (and uses the RTC power pin for another purpose). Given that the audio library does not fully support the Teensy LC, I imagine it isn't an issue in this case.

ifelipeg
05-18-2016, 07:41 PM
Thank you !!!!

Actually the modification that i did was working really bad, thank you again! i'll revise that and then i will come back with good news :D!!!!!

So happy !!!

ifelipeg
05-23-2016, 11:01 PM
Working perfectly with the crystal, thank you.