Commit 9e6ec5ba authored by Daniel Kampert's avatar Daniel Kampert 👷

Fix bug with wrong clock calculation in Tiny0 clock driver, update DS18B20 library example

parent 33d2906a
......@@ -15,27 +15,30 @@ double Temperature;
uint8_t AlarmDevices;
OneWire_ROM_t DS18B20_AlarmROM[DS18B20_BUS_DEVICES];
volatile uint8_t A;
int main(void)
{
if(DS18B20_Init() == ONEWIRE_NO_ERROR)
{
if(DS18B20_GetDevices(&Devices, DS18B20_BUS_DEVICES, DS18B20_ROM) == ONEWIRE_NO_ERROR)
{
// Loop through each sensor
for(uint8_t i = 0x00; i < Devices; i++)
{
// Set the alarm limit and start a new measurement
if((DS18B20_SetAlarm(&DS18B20_ROM[i], DS18B20_ALARM_UPPER_LIMIT, DS18B20_ALARM_LOWER_LIMIT) | DS18B20_Measure(&DS18B20_ROM[i], DS18B20_RESOLUTION_11, &Temperature)) == ONEWIRE_NO_ERROR)
{
}
}
}
else
{
A++;
}
}
else
{
A++;
}
while(1)
{
A++;
}
}
\ No newline at end of file
......@@ -39,8 +39,8 @@ uint32_t SysClock_GetClockPer(void)
if(CLKCTRL.MCLKCTRLB & CLKCTRL_PEN_bm)
{
uint8_t Prescaler = ((CLKCTRL.MCLKCTRLB >> 0x01) & 0x0F) + 0x01;
if(Prescaler > 0x06)
uint8_t Prescaler = CLKCTRL.MCLKCTRLB & 0x1E;
if(Prescaler > (0x06 << 0x01))
{
switch(Prescaler)
{
......@@ -73,7 +73,7 @@ uint32_t SysClock_GetClockPer(void)
}
else
{
return SysClock >> Prescaler;
return SysClock >> ((Prescaler >> 0x01) + 0x01);
}
}
......
......@@ -50,11 +50,11 @@
/** @brief Baudrate value for 115200 baud.
*/
static uint32_t _Baud115200 = 93;
static uint32_t _Baud115200 = 0x00;
/** @brief Baudrate value for 9600 baud.
*/
static uint16_t _Baud9600 = 1111;
static uint16_t _Baud9600 = 0x00;
/** @brief Transmit a data package over the USART 1-Wire interface and receive the answer.
* @param Data Data byte
......
......@@ -47,39 +47,39 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings>
<AvrGcc>
<avrgcc.common.Device>-mmcu=attiny406 -B "%24(PackRepoDir)\Atmel\ATtiny_DFP\1.3.229\gcc\dev\attiny406"</avrgcc.common.Device>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>NDEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\Atmel\ATtiny_DFP\1.3.229\include</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\Atmel\ATtiny_DFP\1.3.229\include</Value>
</ListValues>
</avrgcc.assembler.general.IncludePaths>
</AvrGcc>
<avrgcc.common.Device>-mmcu=attiny406 -B "%24(PackRepoDir)\Atmel\ATtiny_DFP\1.3.229\gcc\dev\attiny406"</avrgcc.common.Device>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>NDEBUG</Value>
</ListValues>
</avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\Atmel\ATtiny_DFP\1.3.229\include</Value>
</ListValues>
</avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\Atmel\ATtiny_DFP\1.3.229\include</Value>
</ListValues>
</avrgcc.assembler.general.IncludePaths>
</AvrGcc>
</ToolchainSettings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
......
......@@ -52,7 +52,7 @@ uint8_t AlarmDevices;
OneWire_ROM_t DS18B20_AlarmROM[DS18B20_BUS_DEVICES];
int main(void)
{
{
/*
Initialize the console service.
*/
......@@ -71,16 +71,16 @@ int main(void)
// Loop through each sensor
for(uint8_t i = 0x00; i < Devices; i++)
{
// Print the serial number
printf("[INFO] Sensor: %d\n\r", i + 1);
printf(" Serial: 0x");
for(uint8_t j = 0x00; j < 0x06; j++)
{
printf("%x", DS18B20_ROM[i].SerialNumber[j]);
}
printf("\n\r");
// Set the alarm limit and start a new measurement
if((DS18B20_SetAlarm(&DS18B20_ROM[i], DS18B20_ALARM_UPPER_LIMIT, DS18B20_ALARM_LOWER_LIMIT) | DS18B20_Measure(&DS18B20_ROM[i], DS18B20_RESOLUTION_11, &Temperature)) == ONEWIRE_NO_ERROR)
{
......@@ -95,21 +95,21 @@ int main(void)
if(DS18B20_GetAlarmDevices(&AlarmDevices, DS18B20_BUS_DEVICES, DS18B20_AlarmROM) == ONEWIRE_NO_ERROR)
{
printf(" %d alarm devices found!\n\r", AlarmDevices);
for(uint8_t i = 0x00; i < Devices; i++)
{
// Print the serial number
printf("[INFO] Sensor: %d\n\r", i + 1);
printf(" Serial: 0x");
for(uint8_t j = 0x00; j < 0x06; j++)
{
printf("%x", DS18B20_ROM[i].SerialNumber[j]);
}
printf("\n\r");
}
}
if(AlarmDevices == 0x00)
{
printf(" no alarm devices found!\n\r");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment