Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ISL1208_HelloWorld
Revision 4:42dc07f9ffb3, committed 2013-11-12
- Comitter:
- neilt6
- Date:
- Tue Nov 12 17:15:20 2013 +0000
- Parent:
- 3:115e4dacfe07
- Child:
- 5:d67ac8351c76
- Commit message:
- open() no longer configures the oscillator
Changed in this revision
| ISL1208.cpp | Show annotated file Show diff for this revision Revisions of this file |
| ISL1208.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ISL1208.cpp Thu Nov 07 18:21:19 2013 +0000
+++ b/ISL1208.cpp Tue Nov 12 17:15:20 2013 +0000
@@ -22,19 +22,13 @@
m_I2C.frequency(400000);
}
-bool ISL1208::open(OscillatorMode mode)
+bool ISL1208::open()
{
//Probe for the ISL1208 using a Zero Length Transfer
if (!m_I2C.write(m_ADDR, NULL, 0)) {
//Read the current status register
char sr = read8(REG_CTL_SR);
- //Configure the oscillator mode
- if (mode == OSCILLATOR_CRYSTAL)
- sr &= ~(1 << 6);
- else
- sr |= (1 << 6);
-
//Disable auto reset for BAT and ALM bits
sr &= ~(1 << 7);
@@ -171,6 +165,33 @@
write8(REG_CTL_SR, value);
}
+ISL1208::OscillatorMode ISL1208::oscillatorMode()
+{
+ //Read the 8-bit register value
+ char value = read8(REG_CTL_SR);
+
+ //Return the status of the XTOSCB bit
+ if (value & (1 << 6))
+ return OSCILLATOR_EXTERNAL;
+ else
+ return OSCILLATOR_CRYSTAL;
+}
+
+void ISL1208::oscillatorMode(OscillatorMode mode)
+{
+ //Read the current 8-bit register value
+ char value = read8(REG_CTL_SR);
+
+ //Set or clear the XTOSCB bit
+ if (mode == OSCILLATOR_EXTERNAL)
+ value |= (1 << 6);
+ else
+ value &= ~(1 << 6);
+
+ //Write the value back out
+ write8(REG_CTL_SR, value);
+}
+
ISL1208::OutputFrequency ISL1208::foutFrequency()
{
//Read the 8-bit register value
--- a/ISL1208.h Thu Nov 07 18:21:19 2013 +0000
+++ b/ISL1208.h Tue Nov 12 17:15:20 2013 +0000
@@ -32,9 +32,12 @@
* int main()
* {
* //Try to open the ISL1208
- * if (rtc.open(ISL1208::OSCILLATOR_CRYSTAL)) {
+ * if (rtc.open()) {
* printf("Device detected!\n");
*
+ * //Configure the oscillator for a 32.768kHz crystal
+ * rtc.oscillatorMode(ISL1208::OSCILLATOR_CRYSTAL);
+ *
* //Check if we need to reset the time
* if (rtc.powerFailed()) {
* //The time has been lost due to a power complete power failure
@@ -138,14 +141,13 @@
*/
ISL1208(PinName sda, PinName scl);
- /** Probe for the ISL1208 and configures the oscillator mode if present
+ /** Probe for the ISL1208 and configure auto reset if present
*
- * @param mode The oscillator mode.
* @returns
* 'true' if the device exists on the bus,
* 'false' if the device doesn't exist on the bus.
*/
- bool open(OscillatorMode mode);
+ bool open();
/** Get the current time from the ISL1208
*
@@ -185,6 +187,18 @@
*/
void clearAlarmFlag();
+ /** Get the current oscillator mode of the ISL1208
+ *
+ * @returns The current oscillator mode as a OscillatorMode enum.
+ */
+ ISL1208::OscillatorMode oscillatorMode();
+
+ /** Set the oscillator mode of the ISL1208
+ *
+ * @param mode The new oscillator mode as a OscillatorMode enum.
+ */
+ void oscillatorMode(OscillatorMode mode);
+
/** Get the current output frequency on the IRQ/fOUT pin
*
* @returns The current output frequency.
ISL1208 Real Time Clock