David Giles
/
CM-MBED_RSEDP_Test_Suite_LPC1768_V3
This is a complete listing of the RS-EDP software for the mbed module to support the RS-EDP platform.
SourceFiles/RSEDP_COM_PCF8583_Real_Time_Clock.cpp@0:5b7639d1f2c4, 2010-11-19 (annotated)
- Committer:
- DavidGilesHitex
- Date:
- Fri Nov 19 09:49:16 2010 +0000
- Revision:
- 0:5b7639d1f2c4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DavidGilesHitex | 0:5b7639d1f2c4 | 1 | /* Driver For PCF8583T Real Time Clock IC */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 2 | /* ************************************** */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 3 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 4 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 5 | /* Version 1.00 */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 6 | /* Start Date: 23/6/2009 */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 7 | /* The RTC Clock IC is part of the communications module */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 8 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 9 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 10 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 11 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 12 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 13 | /* Include Files Here */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 14 | #include "mbed.h" /* mbed header file */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 15 | #include "misra_types.h" /* MISRA Types header file */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 16 | #include "defines.h" |
DavidGilesHitex | 0:5b7639d1f2c4 | 17 | #include "RSEDP_Slave_Address_Defines.h" /* Slave Address of CNTRL I2C devices */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 18 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 19 | #include "mbed_Port_Structure.h" /* Port structure for MBED Module */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 20 | #include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 21 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 22 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 23 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 24 | #define START_YEAR (uint16_t) 2009 /* Value used for real time clock */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 25 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 26 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 27 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 28 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 29 | /* Function Prototypes Here */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 30 | sint32_t RSEDP_COM_setup_PCF8583(uint8_t Slave_Address, uint8_t mode); /* Setup the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 31 | sint32_t RSEDP_COM_PCF8583_Read_Status_Register(uint8_t Slave_Address, uint8_t *status_register); /* Read the status register of the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 32 | sint32_t RSEDP_COM_PCF8583_Write_Status_Register(uint8_t Slave_Address, uint8_t payload); /* Status register write */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 33 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 34 | /* RTC Function */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 35 | sint32_t RSEDP_COM_PCF8583_Write_RTC(uint8_t Slave_Address, uint8_t *RTC_Array); /* Write raw data to the RTC device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 36 | sint32_t RSEDP_COM_PCF8583_Read_RTC(uint8_t Slave_Address, uint8_t *RTC_Array); /* Read raw data from the real time clock */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 37 | sint32_t RSEDP_COM_PCF8583_Set_Clock(uint8_t Slave_Address, uint8_t hours, uint8_t minutes, uint8_t seconds,uint8_t F24hour_flag, uint8_t AMPM_flag); /* Set the clock only */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 38 | sint32_t RSEDP_COM_PCF8583_Set_Date(uint8_t Slave_Address, uint8_t dow, uint8_t day,uint8_t month, uint16_t year); /* Set the date only */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 39 | sint32_t RSEDP_COM_PCF8583_Read_Clock(uint8_t Slave_Address, uint8_t *Time_Array); /* Read the time component only */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 40 | sint32_t RSEDP_COM_PCF8583_Read_Date(uint8_t Slave_Address, uint8_t *Date_Array); /* Read the date component only */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 41 | sint32_t RSEDP_COM_PCF8583_Read_Clock_And_Date(uint8_t Slave_Address, uint8_t *Time_Array,uint8_t *Date_Array); /* Read time and date */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 42 | sint32_t RSEDP_COM_PCF8583_Start_Clock(uint8_t Slave_Address); /* Start the clock counting */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 43 | sint32_t RSEDP_COM_PCF8583_Stop_Clock(uint8_t Slave_Address); /* Stop the clock */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 44 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 45 | /* Battery Maintained SRAM functions */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 46 | sint32_t RSEDP_COM_PCF8583_Read_SRAM(uint8_t Slave_Address, uint8_t *read_data,uint8_t address); /* Read data from the battery maintained SRAM */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 47 | sint32_t RSEDP_COM_PCF8583_Write_SRAM(uint8_t Slave_Address, uint8_t payload,uint8_t address); /* Write data to the battery maintained SRAM */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 48 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 49 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 50 | /* Print Functions */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 51 | void RSEDP_COM_Print_Time(uint8_t *Time_Array); |
DavidGilesHitex | 0:5b7639d1f2c4 | 52 | void RSEDP_COM_Print_Date(uint8_t *Date_Array); |
DavidGilesHitex | 0:5b7639d1f2c4 | 53 | void RSEDP_COM_Print_Time_Date_Year(uint8_t *RTC_Array); |
DavidGilesHitex | 0:5b7639d1f2c4 | 54 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 55 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 56 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 57 | /* Static local functions */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 58 | static void delay_small(void); |
DavidGilesHitex | 0:5b7639d1f2c4 | 59 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 60 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 61 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 62 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 63 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 64 | /* Setup the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 65 | sint32_t RSEDP_COM_setup_PCF8583(uint8_t Slave_Address, uint8_t mode) |
DavidGilesHitex | 0:5b7639d1f2c4 | 66 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 67 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 68 | /* Assume the I2C Peripheral is already configured */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 69 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 70 | if ((mode=='c') | (mode== 'C')) |
DavidGilesHitex | 0:5b7639d1f2c4 | 71 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 72 | /* Configure for Clock mode */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 73 | Ack_Status = RSEDP_COM_PCF8583_Write_Status_Register(Slave_Address, 0x00); |
DavidGilesHitex | 0:5b7639d1f2c4 | 74 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 75 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 76 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 77 | if ((mode=='e') | (mode== 'E')) |
DavidGilesHitex | 0:5b7639d1f2c4 | 78 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 79 | /* configure for Event Counter Mode */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 80 | Ack_Status = RSEDP_COM_PCF8583_Write_Status_Register(Slave_Address, 0x20); |
DavidGilesHitex | 0:5b7639d1f2c4 | 81 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 82 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 83 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 84 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 85 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 86 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 87 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 88 | /* Read the status register of the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 89 | sint32_t RSEDP_COM_PCF8583_Read_Status_Register(uint8_t Slave_Address, uint8_t *status_register) |
DavidGilesHitex | 0:5b7639d1f2c4 | 90 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 91 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 92 | sint8_t tx_array[2]; |
DavidGilesHitex | 0:5b7639d1f2c4 | 93 | sint8_t rx_array=0; /* Variable used to receive data from slave */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 94 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 95 | tx_array[0] = 0x00; /* Memory address 0x00 */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 96 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 97 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 1); /* Set the RTC address */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 98 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 99 | if (Ack_Status == ACK) |
DavidGilesHitex | 0:5b7639d1f2c4 | 100 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 101 | Ack_Status = CNTRL_I2C_Master_Mode_Receive(Slave_Address, &rx_array,1); /* Read single byte address */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 102 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 103 | *status_register = rx_array; /* Load value from RTC into receive pointer */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 104 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 105 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 106 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 107 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 108 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 109 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 110 | /* Status register write */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 111 | sint32_t RSEDP_COM_PCF8583_Write_Status_Register(uint8_t Slave_Address, uint8_t payload) |
DavidGilesHitex | 0:5b7639d1f2c4 | 112 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 113 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 114 | sint8_t tx_array[2]; /* Transmission array */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 115 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 116 | tx_array[0] = 0x00; /* Address 0x00 is where the control register is located */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 117 | tx_array[1] = payload; /* Data to be written */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 118 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 119 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array,2); /* Send the data */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 120 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 121 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 122 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 123 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 124 | /* Read the real time clock information */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 125 | sint32_t RSEDP_COM_PCF8583_Read_RTC(uint8_t Slave_Address, uint8_t *RTC_Array) |
DavidGilesHitex | 0:5b7639d1f2c4 | 126 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 127 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 128 | sint8_t tx_array[2]; |
DavidGilesHitex | 0:5b7639d1f2c4 | 129 | sint8_t local_array[8]; |
DavidGilesHitex | 0:5b7639d1f2c4 | 130 | uint8_t n = 0u; |
DavidGilesHitex | 0:5b7639d1f2c4 | 131 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 132 | tx_array[0] = 0x01; /* Memory address 0x01 */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 133 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 134 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 1); /* Set the RTC memory address */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 135 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 136 | if (Ack_Status == ACK) |
DavidGilesHitex | 0:5b7639d1f2c4 | 137 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 138 | Ack_Status = CNTRL_I2C_Master_Mode_Receive(Slave_Address, local_array,7); /* Read single byte address */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 139 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 140 | for (n = 0; n < 7; n++) |
DavidGilesHitex | 0:5b7639d1f2c4 | 141 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 142 | RTC_Array[n] = (uint8_t) (local_array[n]); |
DavidGilesHitex | 0:5b7639d1f2c4 | 143 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 144 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 145 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 146 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 147 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 148 | /* Write the real time clock information */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 149 | sint32_t RSEDP_COM_PCF8583_Write_RTC(uint8_t Slave_Address, uint8_t *RTC_Array) |
DavidGilesHitex | 0:5b7639d1f2c4 | 150 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 151 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 152 | sint8_t tx_array[8]; |
DavidGilesHitex | 0:5b7639d1f2c4 | 153 | uint8_t n = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 154 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 155 | tx_array[0] = 0x01; /* Memory address 0x01 */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 156 | for (n = 1; n < 8; n++) /* Copy data into array */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 157 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 158 | tx_array[n] = *RTC_Array; |
DavidGilesHitex | 0:5b7639d1f2c4 | 159 | RTC_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 160 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 161 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 162 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 8); /* Transmit the data */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 163 | delay_small(); /* RTC is busy writing */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 164 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 165 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 166 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 167 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 168 | /* Set the clock inside the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 169 | sint32_t RSEDP_COM_PCF8583_Set_Clock(uint8_t Slave_Address, uint8_t hours, uint8_t minutes, uint8_t seconds,uint8_t F24hour_flag, uint8_t AMPM_flag) |
DavidGilesHitex | 0:5b7639d1f2c4 | 170 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 171 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 172 | sint8_t RTC_Array[5] = {0,0,0,0,0}; |
DavidGilesHitex | 0:5b7639d1f2c4 | 173 | uint8_t high = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 174 | uint8_t low = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 175 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 176 | /* Hundreths */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 177 | RTC_Array[1] = 0x00; /* Hundreths of a second -set to zero */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 178 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 179 | /* Seconds */ /* Convert to BCD */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 180 | low = (seconds % 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 181 | high = (seconds / 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 182 | RTC_Array[2] = ((high << 4) + low); |
DavidGilesHitex | 0:5b7639d1f2c4 | 183 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 184 | /* Minutes */ /* Convert to BCD */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 185 | low = (minutes % 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 186 | high = (minutes / 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 187 | RTC_Array[3] = ((high << 4) + low); |
DavidGilesHitex | 0:5b7639d1f2c4 | 188 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 189 | /* Hours */ /* Convert to BCD and add in 24 hour and AM/PM flag */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 190 | low = (hours % 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 191 | high = (hours / 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 192 | RTC_Array[4] = ((high << 4) + low); |
DavidGilesHitex | 0:5b7639d1f2c4 | 193 | RTC_Array[4] = (RTC_Array[4] & 0x3f); |
DavidGilesHitex | 0:5b7639d1f2c4 | 194 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 195 | F24hour_flag = ((F24hour_flag & 0x01) << 7); |
DavidGilesHitex | 0:5b7639d1f2c4 | 196 | AMPM_flag = ((AMPM_flag & 0x01) << 6); |
DavidGilesHitex | 0:5b7639d1f2c4 | 197 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 198 | RTC_Array[4] += F24hour_flag + AMPM_flag; |
DavidGilesHitex | 0:5b7639d1f2c4 | 199 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 200 | RTC_Array[0] = 0x01; /* Target destination address of data */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 201 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 202 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, RTC_Array, 5); /* Transmit the data */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 203 | delay_small(); /* RTC is busy writing */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 204 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 205 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 206 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 207 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 208 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 209 | /* Write the time and date to the RTC clock */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 210 | sint32_t RSEDP_COM_PCF8583_Set_Date(uint8_t Slave_Address, uint8_t dow, uint8_t day,uint8_t month, uint16_t year) |
DavidGilesHitex | 0:5b7639d1f2c4 | 211 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 212 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 213 | sint8_t RTC_Array[5] = {0,0,0,0,0}; |
DavidGilesHitex | 0:5b7639d1f2c4 | 214 | uint8_t high = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 215 | uint8_t low = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 216 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 217 | /* day of month */ /* Convert to BCD */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 218 | if (day > 31) day = 31; |
DavidGilesHitex | 0:5b7639d1f2c4 | 219 | low = (day % 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 220 | high = (day / 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 221 | RTC_Array[1] = (((high << 4) + low) & 0x3f); |
DavidGilesHitex | 0:5b7639d1f2c4 | 222 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 223 | /* year */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 224 | year = ((year - 2008) & 0x03); |
DavidGilesHitex | 0:5b7639d1f2c4 | 225 | RTC_Array[1] += (year << 6); |
DavidGilesHitex | 0:5b7639d1f2c4 | 226 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 227 | /* Day of week */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 228 | if (dow > 6) dow = 6; |
DavidGilesHitex | 0:5b7639d1f2c4 | 229 | dow = (dow << 5); |
DavidGilesHitex | 0:5b7639d1f2c4 | 230 | RTC_Array[2] = dow; |
DavidGilesHitex | 0:5b7639d1f2c4 | 231 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 232 | /* months */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 233 | if (month > 12) month = 12; |
DavidGilesHitex | 0:5b7639d1f2c4 | 234 | low = (month % 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 235 | high = (month / 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 236 | RTC_Array[2] += (((high << 4) + low)); |
DavidGilesHitex | 0:5b7639d1f2c4 | 237 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 238 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 239 | RTC_Array[0] = 0x05; /* Target destination address of data */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 240 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 241 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, RTC_Array, 3); /* Transmit the data */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 242 | delay_small(); /* RTC is busy writing */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 243 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 244 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 245 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 246 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 247 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 248 | /* Start the clock counting */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 249 | sint32_t RSEDP_COM_PCF8583_Start_Clock(uint8_t Slave_Address) |
DavidGilesHitex | 0:5b7639d1f2c4 | 250 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 251 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 252 | uint8_t status_reg = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 253 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 254 | Ack_Status = RSEDP_COM_PCF8583_Read_Status_Register(Slave_Address, &status_reg); |
DavidGilesHitex | 0:5b7639d1f2c4 | 255 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 256 | status_reg = (status_reg & 0x7f); |
DavidGilesHitex | 0:5b7639d1f2c4 | 257 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 258 | if (Ack_Status ==ACK) |
DavidGilesHitex | 0:5b7639d1f2c4 | 259 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 260 | Ack_Status = RSEDP_COM_PCF8583_Write_Status_Register(Slave_Address, status_reg); |
DavidGilesHitex | 0:5b7639d1f2c4 | 261 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 262 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 263 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 264 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 265 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 266 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 267 | /* Stop the clock */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 268 | sint32_t RSEDP_COM_PCF8583_Stop_Clock(uint8_t Slave_Address) |
DavidGilesHitex | 0:5b7639d1f2c4 | 269 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 270 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 271 | uint8_t status_reg = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 272 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 273 | Ack_Status = RSEDP_COM_PCF8583_Read_Status_Register(Slave_Address, &status_reg); |
DavidGilesHitex | 0:5b7639d1f2c4 | 274 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 275 | status_reg = (status_reg | 0x80); |
DavidGilesHitex | 0:5b7639d1f2c4 | 276 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 277 | if (Ack_Status == ACK) |
DavidGilesHitex | 0:5b7639d1f2c4 | 278 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 279 | RSEDP_COM_PCF8583_Write_Status_Register(Slave_Address, status_reg); |
DavidGilesHitex | 0:5b7639d1f2c4 | 280 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 281 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 282 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 283 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 284 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 285 | /* Read the time component only */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 286 | sint32_t RSEDP_COM_PCF8583_Read_Clock(uint8_t Slave_Address, uint8_t *Time_Array) |
DavidGilesHitex | 0:5b7639d1f2c4 | 287 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 288 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 289 | uint8_t RTC_Array[6] = {0,0,0,0,0,0}; /* Hundreths, seconds, minutes,hours, year/date, weekday/month */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 290 | uint8_t temp8 = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 291 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 292 | Ack_Status = RSEDP_COM_PCF8583_Read_RTC(Slave_Address, RTC_Array); |
DavidGilesHitex | 0:5b7639d1f2c4 | 293 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 294 | /* hours */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 295 | temp8 = (((RTC_Array[3] & 0x30) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 296 | *Time_Array = ((RTC_Array[3] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 297 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 298 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 299 | /* Minutes */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 300 | temp8=(((RTC_Array[2] & 0xf0) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 301 | *Time_Array = ((RTC_Array[2] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 302 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 303 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 304 | /* Seconds */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 305 | temp8=(((RTC_Array[1] & 0xf0) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 306 | *Time_Array = ((RTC_Array[1] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 307 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 308 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 309 | /* Hundreths */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 310 | temp8=(((RTC_Array[0] & 0xf0) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 311 | *Time_Array = ((RTC_Array[0] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 312 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 313 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 314 | // 24 Hour Flag |
DavidGilesHitex | 0:5b7639d1f2c4 | 315 | *Time_Array = ((RTC_Array[3] & 0x80) >> 7); |
DavidGilesHitex | 0:5b7639d1f2c4 | 316 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 317 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 318 | // AMPM Flag |
DavidGilesHitex | 0:5b7639d1f2c4 | 319 | *Time_Array = (( RTC_Array[3] & 0x40) >> 6); |
DavidGilesHitex | 0:5b7639d1f2c4 | 320 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 321 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 322 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 323 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 324 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 325 | /* Read the date component only */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 326 | sint32_t RSEDP_COM_PCF8583_Read_Date(uint8_t Slave_Address, uint8_t *Date_Array) |
DavidGilesHitex | 0:5b7639d1f2c4 | 327 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 328 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 329 | uint8_t RTC_Array[6] = {0,0,0,0,0,0}; /* Hundreths, seconds, minutes,hours, year/date, weekday/month */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 330 | uint8_t temp8 = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 331 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 332 | Ack_Status = RSEDP_COM_PCF8583_Read_RTC(Slave_Address, RTC_Array); |
DavidGilesHitex | 0:5b7639d1f2c4 | 333 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 334 | /* Weekday */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 335 | *Date_Array = ((RTC_Array[5] & 0xe0) >> 5); |
DavidGilesHitex | 0:5b7639d1f2c4 | 336 | Date_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 337 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 338 | /* Date */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 339 | temp8=(((RTC_Array[4] & 0x30) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 340 | *Date_Array = ((RTC_Array[4] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 341 | Date_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 342 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 343 | /* Month */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 344 | temp8 = (((RTC_Array[5] & 0x10) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 345 | *Date_Array = ((RTC_Array[5] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 346 | Date_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 347 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 348 | /* Year */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 349 | *Date_Array = ((RTC_Array[4] & 0xc0) >> 6); |
DavidGilesHitex | 0:5b7639d1f2c4 | 350 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 351 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 352 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 353 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 354 | /* Read time and date */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 355 | sint32_t RSEDP_COM_PCF8583_Read_Clock_And_Date(uint8_t Slave_Address, uint8_t *Time_Array,uint8_t *Date_Array) |
DavidGilesHitex | 0:5b7639d1f2c4 | 356 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 357 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 358 | uint8_t RTC_Array[6] = {0,0,0,0,0,0}; /* Hundreths, seconds, minutes,hours, year/date, weekday/month */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 359 | uint8_t temp8 = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 360 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 361 | Ack_Status = RSEDP_COM_PCF8583_Read_RTC(Slave_Address, RTC_Array); |
DavidGilesHitex | 0:5b7639d1f2c4 | 362 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 363 | /* hours */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 364 | temp8 = (((RTC_Array[3] & 0x30) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 365 | *Time_Array = ((RTC_Array[3] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 366 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 367 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 368 | /* Minutes */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 369 | temp8 = (((RTC_Array[2] & 0xf0) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 370 | *Time_Array = ((RTC_Array[2] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 371 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 372 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 373 | /* Seconds */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 374 | temp8 = (((RTC_Array[1] & 0xf0) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 375 | *Time_Array = ((RTC_Array[1] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 376 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 377 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 378 | /* Hundreths */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 379 | temp8 = (((RTC_Array[0] & 0xf0) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 380 | *Time_Array = ((RTC_Array[0] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 381 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 382 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 383 | /* 24 Hour Flag */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 384 | *Time_Array = ((RTC_Array[3] & 0x80)>>7); |
DavidGilesHitex | 0:5b7639d1f2c4 | 385 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 386 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 387 | /* AMPM Flag */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 388 | *Time_Array = (( RTC_Array[3] & 0x40) >> 6); |
DavidGilesHitex | 0:5b7639d1f2c4 | 389 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 390 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 391 | /* Date */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 392 | /* Weekday */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 393 | *Date_Array = ((RTC_Array[5] & 0xe0) >> 5); |
DavidGilesHitex | 0:5b7639d1f2c4 | 394 | Date_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 395 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 396 | /* Date */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 397 | temp8 = (((RTC_Array[4] & 0x30) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 398 | *Date_Array = ((RTC_Array[4] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 399 | Date_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 400 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 401 | /* Month */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 402 | temp8 = (((RTC_Array[5] & 0x10) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 403 | *Date_Array = ((RTC_Array[5] & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 404 | Date_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 405 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 406 | /* Year */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 407 | *Date_Array = ((RTC_Array[4] & 0xc0) >> 6); |
DavidGilesHitex | 0:5b7639d1f2c4 | 408 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 409 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 410 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 411 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 412 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 413 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 414 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 415 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 416 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 417 | /* Battery Maintained SRAM functions */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 418 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 419 | /* Read data from the battery maintained SRAM */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 420 | sint32_t RSEDP_COM_PCF8583_Read_SRAM(uint8_t Slave_Address, uint8_t *read_data, uint8_t address) |
DavidGilesHitex | 0:5b7639d1f2c4 | 421 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 422 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 423 | sint8_t tx_array[2]; /* Transmission array of data */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 424 | sint8_t rx_array=0; /* Variable used to receive data from slave */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 425 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 426 | tx_array[0] = address; /* Memory address to read */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 427 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 428 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 1); /* Set the RTC address */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 429 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 430 | if (Ack_Status == ACK) |
DavidGilesHitex | 0:5b7639d1f2c4 | 431 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 432 | CNTRL_I2C_Master_Mode_Receive(Slave_Address, &rx_array,1); /* Read single byte address */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 433 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 434 | *read_data=rx_array; /* Load value from RTC into receive pointer */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 435 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 436 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 437 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 438 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 439 | /* Write data to the battery maintained SRAM */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 440 | sint32_t RSEDP_COM_PCF8583_Write_SRAM(uint8_t Slave_Address, uint8_t payload, uint8_t address) |
DavidGilesHitex | 0:5b7639d1f2c4 | 441 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 442 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 443 | sint8_t tx_array[2]; /* Transmission array */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 444 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 445 | tx_array[0] = address; /* Address */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 446 | tx_array[1] = payload; /* Data */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 447 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 448 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array,2); /* Send the data */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 449 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 450 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 451 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 452 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 453 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 454 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 455 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 456 | /* Print the time, date and year */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 457 | void RSEDP_COM_Print_Time_Date_Year(uint8_t *RTC_Array) |
DavidGilesHitex | 0:5b7639d1f2c4 | 458 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 459 | uint8_t hundreths = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 460 | uint8_t seconds = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 461 | uint8_t minutes = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 462 | uint8_t hours = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 463 | uint8_t date = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 464 | uint16_t year = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 465 | uint8_t weekday = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 466 | uint8_t month = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 467 | uint8_t temp8 = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 468 | uint8_t AMPM_flag = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 469 | uint8_t F24hour_flag=0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 470 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 471 | /* Hundreths */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 472 | temp8 = (((*RTC_Array & 0xf0) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 473 | hundreths = ((*RTC_Array & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 474 | RTC_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 475 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 476 | /* Seconds */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 477 | temp8 = (((*RTC_Array & 0xf0) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 478 | seconds = ((*RTC_Array & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 479 | RTC_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 480 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 481 | /* Minutes */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 482 | temp8 = (((*RTC_Array & 0xf0) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 483 | minutes = ((*RTC_Array & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 484 | RTC_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 485 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 486 | /* hours */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 487 | temp8 = (((*RTC_Array & 0x30) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 488 | hours = ((*RTC_Array & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 489 | F24hour_flag = ((*RTC_Array & 0x80) >> 7); |
DavidGilesHitex | 0:5b7639d1f2c4 | 490 | AMPM_flag = (( *RTC_Array & 0x40) >> 6); |
DavidGilesHitex | 0:5b7639d1f2c4 | 491 | RTC_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 492 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 493 | /* Date */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 494 | temp8 = (((*RTC_Array & 0x30) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 495 | date = ((*RTC_Array & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 496 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 497 | /* Year */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 498 | year = ((*RTC_Array & 0xc0) >> 6); |
DavidGilesHitex | 0:5b7639d1f2c4 | 499 | RTC_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 500 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 501 | /* Weekday */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 502 | weekday = ((*RTC_Array & 0xe0) >> 5); |
DavidGilesHitex | 0:5b7639d1f2c4 | 503 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 504 | /* Month */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 505 | temp8 = (((*RTC_Array & 0x10) >> 4) * 10); |
DavidGilesHitex | 0:5b7639d1f2c4 | 506 | month = ((*RTC_Array & 0x0f) + temp8); |
DavidGilesHitex | 0:5b7639d1f2c4 | 507 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 508 | pc.printf("%.2d:", hours); |
DavidGilesHitex | 0:5b7639d1f2c4 | 509 | pc.printf("%.2d ", minutes); |
DavidGilesHitex | 0:5b7639d1f2c4 | 510 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 511 | if (F24hour_flag==1) |
DavidGilesHitex | 0:5b7639d1f2c4 | 512 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 513 | if (AMPM_flag == 0) |
DavidGilesHitex | 0:5b7639d1f2c4 | 514 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 515 | pc.printf("AM "); |
DavidGilesHitex | 0:5b7639d1f2c4 | 516 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 517 | if (AMPM_flag == 1) |
DavidGilesHitex | 0:5b7639d1f2c4 | 518 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 519 | pc.printf("PM "); |
DavidGilesHitex | 0:5b7639d1f2c4 | 520 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 521 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 522 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 523 | pc.printf("%.2d.",seconds); |
DavidGilesHitex | 0:5b7639d1f2c4 | 524 | pc.printf("%.2d seconds ", hundreths); |
DavidGilesHitex | 0:5b7639d1f2c4 | 525 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 526 | if (weekday == 0) pc.printf("Monday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 527 | if (weekday == 1) pc.printf("Tuesday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 528 | if (weekday == 2) pc.printf("Wednesday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 529 | if (weekday == 3) pc.printf("Thursday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 530 | if (weekday == 4) pc.printf("Friday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 531 | if (weekday == 5) pc.printf("Saturday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 532 | if (weekday == 6) pc.printf("Sunday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 533 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 534 | pc.printf(" %.2d ",date); |
DavidGilesHitex | 0:5b7639d1f2c4 | 535 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 536 | if (month == 1) pc.printf("January"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 537 | if (month == 2) pc.printf("Febuary"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 538 | if (month == 3) pc.printf("March"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 539 | if (month == 4) pc.printf("April"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 540 | if (month == 5) pc.printf("May"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 541 | if (month == 6) pc.printf("June"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 542 | if (month == 7) pc.printf("July"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 543 | if (month == 8) pc.printf("August"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 544 | if (month == 9) pc.printf("September"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 545 | if (month == 10) pc.printf("October"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 546 | if (month == 11) pc.printf("November"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 547 | if (month == 12) pc.printf("December"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 548 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 549 | year = year + START_YEAR; |
DavidGilesHitex | 0:5b7639d1f2c4 | 550 | pc.printf(" %.4d ", year); |
DavidGilesHitex | 0:5b7639d1f2c4 | 551 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 552 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 553 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 554 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 555 | /* Print the Time */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 556 | void RSEDP_COM_Print_Time(uint8_t *Time_Array) |
DavidGilesHitex | 0:5b7639d1f2c4 | 557 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 558 | uint8_t hours = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 559 | uint8_t minutes = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 560 | uint8_t seconds = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 561 | uint8_t hundreths = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 562 | uint8_t F24hour_flag=0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 563 | uint8_t AMPM_flag = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 564 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 565 | hours = *Time_Array; |
DavidGilesHitex | 0:5b7639d1f2c4 | 566 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 567 | minutes = *Time_Array; |
DavidGilesHitex | 0:5b7639d1f2c4 | 568 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 569 | seconds = *Time_Array; |
DavidGilesHitex | 0:5b7639d1f2c4 | 570 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 571 | hundreths = *Time_Array; |
DavidGilesHitex | 0:5b7639d1f2c4 | 572 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 573 | F24hour_flag = *Time_Array; |
DavidGilesHitex | 0:5b7639d1f2c4 | 574 | Time_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 575 | AMPM_flag = *Time_Array; |
DavidGilesHitex | 0:5b7639d1f2c4 | 576 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 577 | pc.printf("%.2d:",hours); |
DavidGilesHitex | 0:5b7639d1f2c4 | 578 | pc.printf("%.2d ",minutes); |
DavidGilesHitex | 0:5b7639d1f2c4 | 579 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 580 | if (F24hour_flag == 1) |
DavidGilesHitex | 0:5b7639d1f2c4 | 581 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 582 | if (AMPM_flag == 0) |
DavidGilesHitex | 0:5b7639d1f2c4 | 583 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 584 | pc.printf("AM "); |
DavidGilesHitex | 0:5b7639d1f2c4 | 585 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 586 | if (AMPM_flag == 1) |
DavidGilesHitex | 0:5b7639d1f2c4 | 587 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 588 | pc.printf("PM "); |
DavidGilesHitex | 0:5b7639d1f2c4 | 589 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 590 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 591 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 592 | pc.printf("%.2d.",seconds); |
DavidGilesHitex | 0:5b7639d1f2c4 | 593 | pc.printf("%.2d seconds ",hundreths); |
DavidGilesHitex | 0:5b7639d1f2c4 | 594 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 595 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 596 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 597 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 598 | /* Print the date */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 599 | void RSEDP_COM_Print_Date(uint8_t *Date_Array) |
DavidGilesHitex | 0:5b7639d1f2c4 | 600 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 601 | uint8_t date = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 602 | uint16_t year = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 603 | uint8_t weekday = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 604 | uint8_t month = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 605 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 606 | weekday = *Date_Array; |
DavidGilesHitex | 0:5b7639d1f2c4 | 607 | Date_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 608 | date = *Date_Array; |
DavidGilesHitex | 0:5b7639d1f2c4 | 609 | Date_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 610 | month = *Date_Array; |
DavidGilesHitex | 0:5b7639d1f2c4 | 611 | Date_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 612 | year = *Date_Array; |
DavidGilesHitex | 0:5b7639d1f2c4 | 613 | Date_Array++; |
DavidGilesHitex | 0:5b7639d1f2c4 | 614 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 615 | if (weekday == 0) pc.printf("Monday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 616 | if (weekday == 1) pc.printf("Tuesday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 617 | if (weekday == 2) pc.printf("Wednesday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 618 | if (weekday == 3) pc.printf("Thursday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 619 | if (weekday == 4) pc.printf("Friday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 620 | if (weekday == 5) pc.printf("Saturday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 621 | if (weekday == 6) pc.printf("Sunday"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 622 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 623 | pc.printf(" %.2d ",date); |
DavidGilesHitex | 0:5b7639d1f2c4 | 624 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 625 | if (month == 1) pc.printf("January"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 626 | if (month == 2) pc.printf("Febuary"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 627 | if (month == 3) pc.printf("March"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 628 | if (month == 4) pc.printf("April"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 629 | if (month == 5) pc.printf("May"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 630 | if (month == 6) pc.printf("June"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 631 | if (month == 7) pc.printf("July"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 632 | if (month == 8) pc.printf("August"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 633 | if (month == 9) pc.printf("September"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 634 | if (month == 10) pc.printf("October"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 635 | if (month == 11) pc.printf("November"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 636 | if (month == 12) pc.printf("December"); |
DavidGilesHitex | 0:5b7639d1f2c4 | 637 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 638 | year = year + START_YEAR; |
DavidGilesHitex | 0:5b7639d1f2c4 | 639 | pc.printf(" %.4d ", year); |
DavidGilesHitex | 0:5b7639d1f2c4 | 640 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 641 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 642 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 643 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 644 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 645 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 646 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 647 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 648 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 649 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 650 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 651 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 652 | /* Small 5ms delay approx */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 653 | /* Note: Change this delay to suite the write time/busy period of the RTC */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 654 | static void delay_small(void) |
DavidGilesHitex | 0:5b7639d1f2c4 | 655 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 656 | uint32_t nnnn=0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 657 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 658 | for(nnnn = 0; nnnn < 0x12000; nnnn++) |
DavidGilesHitex | 0:5b7639d1f2c4 | 659 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 660 | ; |
DavidGilesHitex | 0:5b7639d1f2c4 | 661 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 662 | } |