aboutsummaryrefslogtreecommitdiffstats
path: root/Projects
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2011-01-13 22:56:49 +0000
committerDean Camera <dean@fourwalledcubicle.com>2011-01-13 22:56:49 +0000
commit70d55f6e0ca1f262bd8811ad8d4149e33125819a (patch)
tree5e618c7cc5bfc8ee4f410c44578d8704bfe72b0a /Projects
parent9c7594e7db5b06b2703a9975f2b250056ee0c212 (diff)
downloadlufa-70d55f6e0ca1f262bd8811ad8d4149e33125819a.tar.gz
lufa-70d55f6e0ca1f262bd8811ad8d4149e33125819a.tar.bz2
lufa-70d55f6e0ca1f262bd8811ad8d4149e33125819a.zip
Added new high level TWI packet read/write commands, altered behaviour of the TWI_StartTransmission() function.
Spell check source code files.
Diffstat (limited to 'Projects')
-rw-r--r--Projects/TempDataLogger/Lib/DS1307.c60
-rw-r--r--Projects/TempDataLogger/Lib/DS1307.h7
2 files changed, 22 insertions, 45 deletions
diff --git a/Projects/TempDataLogger/Lib/DS1307.c b/Projects/TempDataLogger/Lib/DS1307.c
index 40aba3204..2f84a18cf 100644
--- a/Projects/TempDataLogger/Lib/DS1307.c
+++ b/Projects/TempDataLogger/Lib/DS1307.c
@@ -7,13 +7,14 @@
#include "DS1307.h"
-void DS1307_SetTimeDate(const TimeDate_t* NewTimeDate)
+bool DS1307_SetTimeDate(const TimeDate_t* NewTimeDate)
{
#if defined(DUMMY_RTC)
- return;
+ return true;
#endif
DS1307_DateTimeRegs_t NewRegValues;
+ const uint8_t WriteAddress = 0;
// Convert new time data to the DS1307's time register layout
NewRegValues.Byte1.Fields.TenSec = (NewTimeDate->Second / 10);
@@ -34,27 +35,17 @@ void DS1307_SetTimeDate(const TimeDate_t* NewTimeDate)
NewRegValues.Byte7.Fields.TenYear = (NewTimeDate->Year / 10);
NewRegValues.Byte7.Fields.Year = (NewTimeDate->Year % 10);
- if (TWI_StartTransmission(DS1307_ADDRESS_WRITE, 10))
+ // Write the new Time and Date into the DS1307
+ if (TWI_WritePacket(DS1307_ADDRESS, 10, &WriteAddress, sizeof(WriteAddress),
+ (uint8_t*)&NewRegValues, sizeof(DS1307_DateTimeRegs_t)) != TWI_ERROR_NoError)
{
- // Must start writing to the first address within the device
- TWI_SendByte(0);
-
- // Write time data to the first set of device registers
- TWI_SendByte(NewRegValues.Byte1.IntVal);
- TWI_SendByte(NewRegValues.Byte2.IntVal);
- TWI_SendByte(NewRegValues.Byte3.IntVal);
-
- // Write date data to the second set of device registers
- TWI_SendByte(NewRegValues.Byte4.IntVal);
- TWI_SendByte(NewRegValues.Byte5.IntVal);
- TWI_SendByte(NewRegValues.Byte6.IntVal);
- TWI_SendByte(NewRegValues.Byte7.IntVal);
-
- TWI_StopTransmission();
+ return false;
}
+
+ return true;
}
-void DS1307_GetTimeDate(TimeDate_t* const TimeDate)
+bool DS1307_GetTimeDate(TimeDate_t* const TimeDate)
{
#if defined(DUMMY_RTC)
TimeDate->Hour = 1;
@@ -65,34 +56,19 @@ void DS1307_GetTimeDate(TimeDate_t* const TimeDate)
TimeDate->Month = 1;
TimeDate->Year = 1;
- return;
+ return true;
#endif
- if (TWI_StartTransmission(DS1307_ADDRESS_WRITE, 10))
- {
- // Must start reading from the first address within the device
- TWI_SendByte(0);
- TWI_StopTransmission();
- }
-
DS1307_DateTimeRegs_t CurrentRegValues;
+ const uint8_t ReadAddress = 0;
- if (TWI_StartTransmission(DS1307_ADDRESS_READ, 10))
+ // Read in the stored Time and Date from the DS1307
+ if (TWI_ReadPacket(DS1307_ADDRESS, 10, &ReadAddress, sizeof(ReadAddress),
+ (uint8_t*)&CurrentRegValues, sizeof(DS1307_DateTimeRegs_t)) != TWI_ERROR_NoError)
{
- // First set of registers store the current time
- TWI_ReceiveByte(&CurrentRegValues.Byte1.IntVal, false);
- TWI_ReceiveByte(&CurrentRegValues.Byte2.IntVal, false);
- TWI_ReceiveByte(&CurrentRegValues.Byte3.IntVal, false);
-
- // Second set of registers store the current date
- TWI_ReceiveByte(&CurrentRegValues.Byte4.IntVal, false);
- TWI_ReceiveByte(&CurrentRegValues.Byte5.IntVal, false);
- TWI_ReceiveByte(&CurrentRegValues.Byte6.IntVal, false);
- TWI_ReceiveByte(&CurrentRegValues.Byte7.IntVal, true);
-
- TWI_StopTransmission();
+ return false;
}
-
+
// Convert stored time value into decimal
TimeDate->Second = (CurrentRegValues.Byte1.Fields.TenSec * 10) + CurrentRegValues.Byte1.Fields.Sec;
TimeDate->Minute = (CurrentRegValues.Byte2.Fields.TenMin * 10) + CurrentRegValues.Byte2.Fields.Min;
@@ -102,5 +78,7 @@ void DS1307_GetTimeDate(TimeDate_t* const TimeDate)
TimeDate->Day = (CurrentRegValues.Byte5.Fields.TenDay * 10) + CurrentRegValues.Byte5.Fields.Day;
TimeDate->Month = (CurrentRegValues.Byte6.Fields.TenMonth * 10) + CurrentRegValues.Byte6.Fields.Month;
TimeDate->Year = (CurrentRegValues.Byte7.Fields.TenYear * 10) + CurrentRegValues.Byte7.Fields.Year;
+
+ return true;
}
diff --git a/Projects/TempDataLogger/Lib/DS1307.h b/Projects/TempDataLogger/Lib/DS1307.h
index 6269bb235..5181c3e87 100644
--- a/Projects/TempDataLogger/Lib/DS1307.h
+++ b/Projects/TempDataLogger/Lib/DS1307.h
@@ -111,12 +111,11 @@
} DS1307_DateTimeRegs_t;
/* Macros: */
- #define DS1307_ADDRESS_READ (0xD0 | TWI_ADDRESS_READ)
- #define DS1307_ADDRESS_WRITE (0xD0 | TWI_ADDRESS_WRITE)
+ #define DS1307_ADDRESS 0xD0
/* Function Prototypes: */
- void DS1307_SetTimeDate(const TimeDate_t* NewTimeDate);
- void DS1307_GetTimeDate(TimeDate_t* const TimeDate);
+ bool DS1307_SetTimeDate(const TimeDate_t* NewTimeDate);
+ bool DS1307_GetTimeDate(TimeDate_t* const TimeDate);
#endif