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.
Revision 4:a5c06ac163f1, committed 2019-04-12
- Comitter:
- mcm
- Date:
- Fri Apr 12 14:08:54 2019 +0000
- Parent:
- 3:c3635fe3ca6f
- Commit message:
- The driver was completed and tested (using a NUCLEO-L152RE board), it works as expected.
Changed in this revision
PCF85063.cpp | Show annotated file Show diff for this revision Revisions of this file |
PCF85063.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/PCF85063.cpp Tue Feb 19 20:22:28 2019 +0000 +++ b/PCF85063.cpp Fri Apr 12 14:08:54 2019 +0000 @@ -58,7 +58,7 @@ /* Read the register */ cmd[0] = PCF85063_CONTROL_1; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); /* Mask it and update it with the new value */ cmd[1] = ( ( cmd[1] & ~CONTROL_1_EXT_TEST_MASK ) | myEXT_TEST ); @@ -105,7 +105,7 @@ /* Read the register */ cmd[0] = PCF85063_CONTROL_1; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); /* Mask it and update it with the new value */ cmd[1] = ( ( cmd[1] & ~CONTROL_1_STOP_MASK ) | mySTOP ); @@ -201,7 +201,7 @@ /* Read the register */ cmd[0] = PCF85063_CONTROL_1; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); /* Mask it and update it with the new value */ cmd[1] = ( ( cmd[1] & ~CONTROL_1_CIE_MASK ) | myCIE ); @@ -248,7 +248,7 @@ /* Read the register */ cmd[0] = PCF85063_CONTROL_1; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); /* Mask it and update it with the new value */ cmd[1] = ( ( cmd[1] & ~CONTROL_1_12_24_MASK ) | my12_24.Time12H_24HMode ); @@ -295,7 +295,7 @@ /* Read the register */ cmd[0] = PCF85063_CONTROL_1; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); /* Mask it and update it with the new value */ cmd[1] = ( ( cmd[1] & ~CONTROL_1_CAP_SEL_MASK ) | myCAP_SEL ); @@ -343,7 +343,7 @@ /* Read the register */ cmd[0] = PCF85063_CONTROL_2; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); /* Mask it and update it with the new value */ cmd[1] = ( ( cmd[1] & ~( CONTROL_2_MI_MASK | CONTROL_2_HMI_MASK ) ) | myMI | myHMI ); @@ -390,7 +390,7 @@ /* Read the register */ cmd = PCF85063_CONTROL_2; aux = _i2c.write ( _PCF85063_Addr, &cmd, 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); /* Parse the data */ *myTF = (PCF85063_control_2_tf_t)( cmd & CONTROL_2_TF_MASK ); @@ -437,7 +437,7 @@ /* Read the register */ cmd[0] = PCF85063_CONTROL_2; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); /* Mask it and update it with the new value */ cmd[1] = ( cmd[1] & ~CONTROL_2_TF_MASK ); @@ -485,7 +485,7 @@ /* Read the register */ cmd[0] = PCF85063_CONTROL_2; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); /* Mask it and update it with the new value */ cmd[1] = ( cmd[1] & ~CONTROL_2_COF_MASK ) | myCOF; @@ -541,7 +541,7 @@ /* Read the register */ cmd[0] = PCF85063_OFFSET; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); /* Mask it and update it with the new value */ cmd[1] = ( cmd[1] & ~( OFFSET_MODE_MASK | 0b01111111 ) ) | ( myMODE | myOFFSET ); @@ -633,7 +633,7 @@ /* Read the register */ cmd = PCF85063_RAM_BYTE; aux = _i2c.write ( _PCF85063_Addr, &cmd, 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); /* Parse the data */ myData->ramByte = cmd; @@ -680,7 +680,7 @@ /* Read the register */ cmd = PCF85063_SECONDS; aux = _i2c.write ( _PCF85063_Addr, &cmd, 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); /* Parse the data */ myOS->os = (PCF85063_seconds_os_t)cmd; @@ -727,7 +727,7 @@ /* Read the register */ cmd[0] = PCF85063_SECONDS; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); /* Mask it and update it with the new value */ cmd[1] = ( cmd[1] & ~SECONDS_OS_MASK ); @@ -783,7 +783,7 @@ /* Read the register */ cmd[0] = PCF85063_HOURS; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 1U ); /* Mask it and update it with the new value */ cmd[1] = ( cmd[1] & ~HOURS_AMPM_MASK ) | myAM_PM_Indicator.TimeAM_PM_Mode; @@ -839,7 +839,7 @@ /* Read the register */ cmd = PCF85063_HOURS; aux = _i2c.write ( _PCF85063_Addr, &cmd, 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); /* Parse the data */ myAM_PM_Indicator->TimeAM_PM_Mode = (PCF85063_hours_ampm_t)cmd; @@ -886,7 +886,7 @@ /* Read the register */ cmd = PCF85063_DAYS; aux = _i2c.write ( _PCF85063_Addr, &cmd, 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); /* Parse the data */ myActualDay->BCDday = ( cmd & ( DAYS_DAYS_TEN_PLACE_MASK | DAYS_DAYS_UNIT_PLACE_MASK ) ); @@ -977,7 +977,7 @@ /* Read the register */ cmd = PCF85063_WEEKDAYS; aux = _i2c.write ( _PCF85063_Addr, &cmd, 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); /* Parse the data */ myActualWeekday->weekday = (PCF85063_weekdays_weekdays_t)( cmd & WEEKDAYS_WEEKDAYS_MASK ); @@ -1068,7 +1068,7 @@ /* Read the register */ cmd = PCF85063_MONTHS; aux = _i2c.write ( _PCF85063_Addr, &cmd, 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); /* Parse the data */ myActualMonth->BCDmonth = (PCF85063_months_months_t)( cmd & MONTHS_MONTHS_MASK ); @@ -1159,7 +1159,7 @@ /* Read the register */ cmd = PCF85063_YEARS; aux = _i2c.write ( _PCF85063_Addr, &cmd, 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd, 1U ); /* Parse the data */ myActualYear->BCDyear = cmd; @@ -1250,7 +1250,7 @@ /* Read the register */ cmd[0] = PCF85063_SECONDS; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); /* Parse the data */ if ( myActualTime->Time12H_24HMode == CONTROL_1_12_24_24_HOUR_MODE ) @@ -1308,7 +1308,7 @@ /* Read the register */ cmd[0] = PCF85063_SECONDS; aux = _i2c.write ( _PCF85063_Addr, &cmd[0], 1U, true ); - aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 3U ); + aux = _i2c.read ( _PCF85063_Addr, &cmd[1], 3U ); /* Mask it and update the register */ cmd[1] &= ~( SECONDS_SECONDS_TEN_PLACE_MASK | SECONDS_SECONDS_UNIT_PLACE_MASK );
--- a/PCF85063.h Tue Feb 19 20:22:28 2019 +0000 +++ b/PCF85063.h Fri Apr 12 14:08:54 2019 +0000 @@ -22,7 +22,182 @@ /** Example: @code +#include "mbed.h" +#include "PCF85063.h" +PCF85063 myPCF85063 ( I2C_SDA, I2C_SCL, PCF85063::PCF85063_ADDRESS, 400000 ); // I2C_SDA | I2C_SCL +Serial pc ( USBTX, USBRX ); // tx, rx + +DigitalOut myled ( LED1 ); +Ticker newAction; + + +// @brief Constants. + + +// @brief Variables. +volatile uint32_t myState; // State that indicates when to perform an ADC sample + + +// @brief FUNCTION PROTOTYPES +void changeDATA ( void ); + + + +// @brief FUNCTION FOR APPLICATION MAIN ENTRY. +int main() +{ + static const char* MY_WEEK_DAY_STRING[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; + + PCF85063::PCF85063_status_t aux; + PCF85063::PCF85063_data_t myPCF85063_Data; + + pc.baud ( 115200 ); + + + myled = 1; + wait(3); + myled = 0; + + // Perform a software reset + aux = myPCF85063.PCF85063_SoftwareReset (); + + // Wait until the oscillator is stable + do { + // Clear Clock integrity flag. + aux = myPCF85063.PCF85063_ClearOscillatorClockIntegrityFlag (); + + // Check Clock integrity flag. + aux = myPCF85063.PCF85063_CheckOscillatorClockIntegrityFlag ( &myPCF85063_Data ); + } while( myPCF85063_Data.os == PCF85063::SECONDS_OS_CLOCK_INTEGRITY_NOT_GUARANTEED ); + + // External clock test mode: Normal mode ( no test at all ) + aux = myPCF85063.PCF85063_SetTestMode ( PCF85063::CONTROL_1_EXT_TEST_NORMAL_MODE ); + + // RTC clock is enabled + aux = myPCF85063.PCF85063_SetRTCMode ( PCF85063::CONTROL_1_STOP_RTC_CLOCK_RUNS ); + + // No correction interrupt generated + aux = myPCF85063.PCF85063_SetCorrectionInterruptMode ( PCF85063::CONTROL_1_CIE_NO_CORRECTION_INTERRUPT_GENERATED ); + + // 24 hour mode is selected + myPCF85063_Data.Time12H_24HMode = PCF85063::CONTROL_1_12_24_24_HOUR_MODE; + aux = myPCF85063.PCF85063_Set12_24_HourMode ( myPCF85063_Data ); + + // Internal oscillator capacitor selection: 7 pF + aux = myPCF85063.PCF85063_SetInternalOscillatorCapacitor ( PCF85063::CONTROL_1_CAP_SEL_7_PF ); + + // Minute interrupt and half minute interrupt are disabled + aux = myPCF85063.PCF85063_SetMinuteInterrupts ( PCF85063::CONTROL_2_MI_MINUTE_INTERRUPT_DISABLED, PCF85063::CONTROL_2_HMI_HALF_MINUTE_INTERRUPT_DISABLED ); + + // Clear timer flag + aux = myPCF85063.PCF85063_ClearTimerFlag (); + + // CLKOUT: 1Hz + aux = myPCF85063.PCF85063_SetClockOutputFrequency ( PCF85063::CONTROL_2_COF_CLKOUT_1_HZ ); + + // Normal mode offset at 0. + aux = myPCF85063.PCF85063_SetOffset ( PCF85063::OFFSET_MODE_NORMAL_MODE, 0 ); + + // Write data ( 0x23 ) into device's RAM + myPCF85063_Data.ramByte = 0x23; + aux = myPCF85063.PCF85063_WriteByteRAM ( myPCF85063_Data ); + + // Read data from device's RAM + myPCF85063_Data.ramByte = 0; // Reset the variable + aux = myPCF85063.PCF85063_ReadByteRAM ( &myPCF85063_Data ); + pc.printf ( "Data in RAM: %x (0x23)\r\n", myPCF85063_Data.ramByte ); + + // Get day. After reset, we expect to get 0x01 + aux = myPCF85063.PCF85063_GetDay ( &myPCF85063_Data ); + + // Set day: 23 + myPCF85063_Data.BCDday = 0x23; + aux = myPCF85063.PCF85063_SetDay ( myPCF85063_Data ); + + // Get month. After reset, we expect to get 0x01 ( January ) + aux = myPCF85063.PCF85063_GetMonth ( &myPCF85063_Data ); + + // Set month: September + myPCF85063_Data.BCDmonth = PCF85063::MONTHS_MONTHS_SEPTEMBER; + aux = myPCF85063.PCF85063_SetMonth ( myPCF85063_Data ); + + // Get weekday. After reset, we expect to get Saturday + aux = myPCF85063.PCF85063_GetWeekday ( &myPCF85063_Data ); + + // Set weekday: Friday + myPCF85063_Data.weekday = PCF85063::WEEKDAYS_WEEKDAYS_FRIDAY; + aux = myPCF85063.PCF85063_SetWeekday ( myPCF85063_Data ); + + // Get year. After reset, we expect to get 00 ( it corresponds to 2000 ) + aux = myPCF85063.PCF85063_GetYear ( &myPCF85063_Data ); + + // Set year: 19 ( 2019 ) + myPCF85063_Data.BCDyear = 0x19; + aux = myPCF85063.PCF85063_SetYear ( myPCF85063_Data ); + + // Set time: 235955 ( 23:59:55 ) + myPCF85063_Data.BCDtime = 0x235955; + aux = myPCF85063.PCF85063_SetTime ( myPCF85063_Data ); + + myState = 0UL; // Reset the variable + newAction.attach( &changeDATA, 1U ); // the address of the function to be attached ( changeDATA ) and the interval ( 1s ) + + // Let the callbacks take care of everything + while(1) { + sleep(); + + if ( myState == 1UL ) { + myled = 1U; + + // Get time + aux = myPCF85063.PCF85063_GetTime ( &myPCF85063_Data ); + + // Get day + aux = myPCF85063.PCF85063_GetDay ( &myPCF85063_Data ); + + // Get month + aux = myPCF85063.PCF85063_GetMonth ( &myPCF85063_Data ); + + // Get weekday + aux = myPCF85063.PCF85063_GetWeekday ( &myPCF85063_Data ); + + // Get year + aux = myPCF85063.PCF85063_GetYear ( &myPCF85063_Data ); + + // Final data + pc.printf ( "Time: %x:%x:%x, Month %x Day %x %s 20%x\r\n", ( ( myPCF85063_Data.BCDtime & 0xFF0000 ) >> 16U ), ( ( myPCF85063_Data.BCDtime & 0x00FF00 ) >> 8U ), + ( myPCF85063_Data.BCDtime & 0x0000FF ), myPCF85063_Data.BCDmonth, myPCF85063_Data.BCDday, MY_WEEK_DAY_STRING[myPCF85063_Data.weekday], myPCF85063_Data.BCDyear ); + + // Reset the variables + myState = 0UL; + myled = 0U; + } + } +} + + // @brief changeDATA ( void ) + // + // @details It changes myState variable + // + // @param[in] N/A + // + // @param[out] N/A. + // + // + // @return N/A. + // + // + // @author Manuel Caballero + // @date 19/February/2019 + // @version 19/February/2019 The ORIGIN + // @pre N/A + // @warning N/A. + // +void changeDATA ( void ) +{ + myState = 1UL; +} @endcode */