// Initialize the DS1307 uint32_t DS1307_Init(void) { uint32_t Error; I2C0_Init(); I2C0_Start(DS1307_ADDRESS, MASTER_TX); return Error; }
// read time from RTC uint32_t DS1307_ReadTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds) { uint32_t Error; I2C0_Start(DS1307_ADDRESS, MASTER_TX); Error= I2C0_TxByte(SECONDS_REG, (I2C_MCS_START | I2C_MCS_RUN | I2C_MCS_STOP)); I2C0_Start(DS1307_ADDRESS, MASTER_RX); Error|= I2C0_RxByte(seconds, (I2C_MCS_START | I2C_MCS_RUN | I2C_MCS_ACK)); Error|= I2C0_RxByte(minutes, (I2C_MCS_RUN | I2C_MCS_ACK)); Error|= I2C0_RxByte(hours, (I2C_MCS_RUN | I2C_MCS_STOP)); // convert all BCDs to Decimal BCD_To_DEC(seconds); BCD_To_DEC(minutes); BCD_To_DEC(hours); return Error; }
// read calender from RTC uint32_t DS1307_ReadCalender(uint8_t *year, uint8_t *month, uint8_t *dayOfMonth, uint8_t *dayOfWeek) { uint32_t Error; I2C0_Start(DS1307_ADDRESS, MASTER_TX); Error= I2C0_TxByte(DAY_OF_WEEK_REG, (I2C_MCS_START | I2C_MCS_RUN | I2C_MCS_STOP)); I2C0_Start(DS1307_ADDRESS, MASTER_RX); Error|= I2C0_RxByte(dayOfWeek, (I2C_MCS_START | I2C_MCS_RUN | I2C_MCS_ACK)); Error|= I2C0_RxByte(dayOfMonth, (I2C_MCS_RUN | I2C_MCS_ACK)); Error|= I2C0_RxByte(month, (I2C_MCS_RUN | I2C_MCS_ACK)); Error|= I2C0_RxByte(year, (I2C_MCS_RUN | I2C_MCS_STOP)); // convert all BCDs to Decimal BCD_To_DEC(dayOfWeek); BCD_To_DEC(dayOfMonth); BCD_To_DEC(month); BCD_To_DEC(year); return Error; }
void serialUI(void) { if (commandRetrived == 1) { if (commandType == 0) { checkCmd(); commandRetrived = 0; } if (commandType == 1) { if (setCmd == 0) { //this is to send in data. the data is not yet flashed led_switch(2); //data can be send in at any time also at flight time //it will be used with the next cycle print_uart0("FCm0;storing setting %d;00#",setupCache.settingNum); setToInSettings(); //fill the runtime struct with the settings setTempToInSetting(setupCache.settingNum); //save settings to ram cache commandRetrived = 0; } if (setCmd == 1) { print_uart0("FCm0;flashing settings;00#"); //here we write all the settings from ram to flash engines_Off(); //this is to save some of the flashing cycles. led_switch(3); //we could flash with any retrieved setting but that engineStatus = 0; //just helps abusing the flash cycles so its a manual //step to really save to flash writeSetup(); ADCStandstillValues(); //also we reset the ADCOffset commandRetrived = 0; initFCRuntime(); ledTest(); } } if (commandType == 2) { updateAcdRate(); commandRetrived = 0; } if (commandType == 3) { retriveSetting(); printSettings(); commandRetrived = 0; } if (commandType == 4) { if (I2CcmdType == I2CMODE_WRITEADDRESS){ if (updateYGE == 0) { I2C0Mode = I2CMODE_WRITEADDRESS; I2C0State = 0; updateYGE = 1; I2C0_Start(); } } if (I2CcmdType == I2CMODE_STARTUP_TARGET){ if (updateYGE == 0) { I2C0_Stop(); I2C0Mode = I2CMODE_WRITEADDRESS; I2C0State = 0; updateYGE = 1; I2C0_Start(); } } commandRetrived = 0; } } }