Loading Session3-LF/Task1_LF/Task1_LF/Task1_LF.componentinfo.xml +15 −15 Original line number Diff line number Diff line Loading @@ -9,13 +9,13 @@ <CSub></CSub> <CVariant></CVariant> <CVendor>Atmel</CVendor> <CVersion>1.1.0</CVersion> <DefaultRepoPath>D:/Atmel\7.0\Packs</DefaultRepoPath> <CVersion>1.2.0</CVersion> <DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath> <DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" /> <Description></Description> <Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <d4p1:anyType i:type="FileInfo"> <AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\include</AbsolutePath> <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include</AbsolutePath> <Attribute></Attribute> <Category>include</Category> <Condition>C</Condition> Loading @@ -26,29 +26,29 @@ <SourcePath></SourcePath> </d4p1:anyType> <d4p1:anyType i:type="FileInfo"> <AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\include\avr\iotn817.h</AbsolutePath> <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom4809.h</AbsolutePath> <Attribute></Attribute> <Category>header</Category> <Condition>C</Condition> <FileContentHash>GzsE/dwQAz37AkZENa/sHg==</FileContentHash> <FileContentHash>mWiFIOAGwUPlW0rYsXcjkg==</FileContentHash> <FileVersion></FileVersion> <Name>include/avr/iotn817.h</Name> <Name>include/avr/iom4809.h</Name> <SelectString></SelectString> <SourcePath></SourcePath> </d4p1:anyType> <d4p1:anyType i:type="FileInfo"> <AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\templates\main.c</AbsolutePath> <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c</AbsolutePath> <Attribute>template</Attribute> <Category>source</Category> <Condition>C Exe</Condition> <FileContentHash>TQP/y9cNoVvAMzruFBs53A==</FileContentHash> <FileContentHash>GD1k8YYhulqRs6FD1B2Hog==</FileContentHash> <FileVersion></FileVersion> <Name>templates/main.c</Name> <SelectString>Main file (.c)</SelectString> <SourcePath></SourcePath> </d4p1:anyType> <d4p1:anyType i:type="FileInfo"> <AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\templates\main.cpp</AbsolutePath> <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp</AbsolutePath> <Attribute>template</Attribute> <Category>source</Category> <Condition>C Exe</Condition> Loading @@ -59,22 +59,22 @@ <SourcePath></SourcePath> </d4p1:anyType> <d4p1:anyType i:type="FileInfo"> <AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\gcc\dev\attiny817</AbsolutePath> <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809</AbsolutePath> <Attribute></Attribute> <Category>libraryPrefix</Category> <Condition>GCC</Condition> <FileContentHash i:nil="true" /> <FileVersion></FileVersion> <Name>gcc/dev/attiny817</Name> <Name>gcc/dev/atmega4809</Name> <SelectString></SelectString> <SourcePath></SourcePath> </d4p1:anyType> </Files> <PackName>ATtiny_DFP</PackName> <PackPath>D:/Atmel/7.0/Packs/atmel/ATtiny_DFP/1.1.102/Atmel.ATtiny_DFP.pdsc</PackPath> <PackVersion>1.1.102</PackVersion> <PackName>ATmega_DFP</PackName> <PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc</PackPath> <PackVersion>1.2.209</PackVersion> <PresentInProject>true</PresentInProject> <ReferenceConditionId>ATtiny817</ReferenceConditionId> <ReferenceConditionId>ATmega4809</ReferenceConditionId> <RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <d4p1:string></d4p1:string> </RteComponents> Loading Session3-LF/Task1_LF/Task1_LF/Task1_LF.cproj +83 −80 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ <ProjectVersion>7.0</ProjectVersion> <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName> <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid> <avrdevice>ATtiny817</avrdevice> <avrdevice>ATmega4809</avrdevice> <avrdeviceseries>none</avrdeviceseries> <OutputType>Executable</OutputType> <Language>C</Language> Loading @@ -27,18 +27,19 @@ <BootSegment>2</BootSegment> <eraseonlaunchrule>0</eraseonlaunchrule> <AsfFrameworkConfig> <framework-data xmlns=""> <framework-data> <options /> <configurations /> <files /> <documentation help="" /> <offline-documentation help="" /> <dependencies> <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.32.0" /> <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.34.1" /> </dependencies> </framework-data> </AsfFrameworkConfig> <avrtool>com.atmel.avrdbg.tool.edbg</avrtool> <avrtool> </avrtool> <avrtoolserialnumber>ATML2654041800000542</avrtoolserialnumber> <avrdeviceexpectedsignature>0x1E9320</avrdeviceexpectedsignature> <avrtoolinterface>UPDI</avrtoolinterface> Loading @@ -54,11 +55,13 @@ <ToolName>EDBG</ToolName> </com_atmel_avrdbg_tool_edbg> <avrtoolinterfaceclock>100000</avrtoolinterfaceclock> <ResetRule>0</ResetRule> <EraseKey /> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <ToolchainSettings> <AvrGcc> <avrgcc.common.Device>-mmcu=attiny817 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\gcc\dev\attiny817"</avrgcc.common.Device> <avrgcc.common.Device>-mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809"</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> Loading @@ -73,7 +76,7 @@ </avrgcc.compiler.symbols.DefSymbols> <avrgcc.compiler.directories.IncludePaths> <ListValues> <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value> </ListValues> </avrgcc.compiler.directories.IncludePaths> <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level> Loading @@ -87,7 +90,7 @@ </avrgcc.linker.libraries.Libraries> <avrgcc.assembler.general.IncludePaths> <ListValues> <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value> </ListValues> </avrgcc.assembler.general.IncludePaths> </AvrGcc> Loading @@ -96,7 +99,7 @@ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <ToolchainSettings> <AvrGcc> <avrgcc.common.Device>-mmcu=attiny817 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\gcc\dev\attiny817"</avrgcc.common.Device> <avrgcc.common.Device>-mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809"</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> Loading @@ -111,7 +114,7 @@ </avrgcc.compiler.symbols.DefSymbols> <avrgcc.compiler.directories.IncludePaths> <ListValues> <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value> </ListValues> </avrgcc.compiler.directories.IncludePaths> <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level> Loading @@ -126,7 +129,7 @@ </avrgcc.linker.libraries.Libraries> <avrgcc.assembler.general.IncludePaths> <ListValues> <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value> </ListValues> </avrgcc.assembler.general.IncludePaths> <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel> Loading Session3-LF/Task1_LF/Task1_LF/adc.c +2 −3 Original line number Diff line number Diff line Loading @@ -10,12 +10,11 @@ void adc_init(){ ADC0.CTRLA |= (ADC_RESSEL_8BIT_gc); //Set resolution, we choose 8 bits ADC0.CTRLB |= (ADC_SAMPLNUM_ACC4_gc); //OPTIONAL: We can use multiple samples if we like, example here with 4 ADC0.CTRLB |= (ADC_SAMPNUM_ACC4_gc); //OPTIONAL: We can use multiple samples if we like, example here with 4 //More samples gives a better result but takes longer ADC0.CTRLC |= (ADC_REFSEL_VDDREF_gc); //We select to use the supply voltage (VDD) as voltage reference ADC0.CTRLC |= (ADC_PRESC_DIV2_gc); //ADC clock prescaler, best accuracy when run below 2MHz. (Here div2 ~1.46 MHz) ADC0.CTRLA |= (ADC_ENABLE_bm); //Enable the ADC } Loading Session3-LF/Task1_LF/Task1_LF/main.c +2 −2 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ #include "uart.h" #define LIGHT 6 // Light sensor is connected to ADC channel 6 (which is on port A pin 6) #define LIGHT 0x01 // Light sensor is connected to ADC channel 1 (which is on port D pin 1) uint8_t data = 0; Loading Session3-LF/Task1_LF/Task1_LF/uart.c +28 −11 Original line number Diff line number Diff line Loading @@ -14,15 +14,25 @@ void uart_init(unsigned long baud){ //From chapter 24.3 in datasheet PORTB.OUTSET |= (1 << PIN2_bp); PORTB.DIRSET |= (1 << PIN2_bp); //Setting up TX pin as high output USART0.BAUD = baud; //Set baudrate //USART.CTRLC CMODE bits default to: async, 1 stop bit, 8 bit character size USART0.CTRLB |= (1 << USART_RXEN_bp) | (1 << USART_TXEN_bp); //Enable RX and TX //From chapter 22.3.1 in datasheet TX_PORT.OUTSET = (1 << TX_PIN); //Setting up TX pin as output TX_PORT.DIRSET = (1 << TX_PIN); //Setting up TX pin as output USART0.CTRLA |= (1 << USART_RXCIE_bp); //Enable interupts on RX //Set baud rate register USART3.BAUDL = (uint8_t) baud; //Set baud rate without shifting to get the 8 low bits USART3.BAUDH = (uint8_t)(baud >> 8); //Shift register right by 8 bits to get the 8 high bits //USART.CTRLC CMODE bits default to async, 1 stop bit, 8 bit character size //Since all bits are default 0 we only need to change the character size part USART3.CTRLC = (0x3 << USART_CHSIZE0_bp); //Enable RX and TX USART3.CTRLB = (1 << USART_RXEN_bp) | (1 << USART_TXEN_bp); //Enable interrupts on incoming data USART3.CTRLA |= (1 << USART_RXCIE_bp); fdevopen(uart_transmit, NULL); //This allows us to use printf instead of writing a single character at a time //It also allows for easily printing variable values: printf("X is currently: %d \n", x_var); Loading @@ -32,10 +42,17 @@ void uart_init(unsigned long baud){ // function to transmit data int uart_transmit(char data, FILE* stream){ while (!(USART0.STATUS & (1 << USART_DREIF_bp))){ //Wait for ongoing transmission to finish (if there is one) } USART0.TXDATAL = data; //Put new data in register //In this function we will be send data. //First we should check that there isn't already data being sent // if there is, we should probably wait for it to finish first while (!(USART3.STATUS & (1 << USART_DREIF_bp))){ //wait for previous transmit to finish }; //Put our new data into tx data register USART3.TXDATAL = data; return 0; } Loading Loading
Session3-LF/Task1_LF/Task1_LF/Task1_LF.componentinfo.xml +15 −15 Original line number Diff line number Diff line Loading @@ -9,13 +9,13 @@ <CSub></CSub> <CVariant></CVariant> <CVendor>Atmel</CVendor> <CVersion>1.1.0</CVersion> <DefaultRepoPath>D:/Atmel\7.0\Packs</DefaultRepoPath> <CVersion>1.2.0</CVersion> <DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath> <DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" /> <Description></Description> <Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <d4p1:anyType i:type="FileInfo"> <AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\include</AbsolutePath> <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include</AbsolutePath> <Attribute></Attribute> <Category>include</Category> <Condition>C</Condition> Loading @@ -26,29 +26,29 @@ <SourcePath></SourcePath> </d4p1:anyType> <d4p1:anyType i:type="FileInfo"> <AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\include\avr\iotn817.h</AbsolutePath> <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom4809.h</AbsolutePath> <Attribute></Attribute> <Category>header</Category> <Condition>C</Condition> <FileContentHash>GzsE/dwQAz37AkZENa/sHg==</FileContentHash> <FileContentHash>mWiFIOAGwUPlW0rYsXcjkg==</FileContentHash> <FileVersion></FileVersion> <Name>include/avr/iotn817.h</Name> <Name>include/avr/iom4809.h</Name> <SelectString></SelectString> <SourcePath></SourcePath> </d4p1:anyType> <d4p1:anyType i:type="FileInfo"> <AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\templates\main.c</AbsolutePath> <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c</AbsolutePath> <Attribute>template</Attribute> <Category>source</Category> <Condition>C Exe</Condition> <FileContentHash>TQP/y9cNoVvAMzruFBs53A==</FileContentHash> <FileContentHash>GD1k8YYhulqRs6FD1B2Hog==</FileContentHash> <FileVersion></FileVersion> <Name>templates/main.c</Name> <SelectString>Main file (.c)</SelectString> <SourcePath></SourcePath> </d4p1:anyType> <d4p1:anyType i:type="FileInfo"> <AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\templates\main.cpp</AbsolutePath> <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp</AbsolutePath> <Attribute>template</Attribute> <Category>source</Category> <Condition>C Exe</Condition> Loading @@ -59,22 +59,22 @@ <SourcePath></SourcePath> </d4p1:anyType> <d4p1:anyType i:type="FileInfo"> <AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\gcc\dev\attiny817</AbsolutePath> <AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809</AbsolutePath> <Attribute></Attribute> <Category>libraryPrefix</Category> <Condition>GCC</Condition> <FileContentHash i:nil="true" /> <FileVersion></FileVersion> <Name>gcc/dev/attiny817</Name> <Name>gcc/dev/atmega4809</Name> <SelectString></SelectString> <SourcePath></SourcePath> </d4p1:anyType> </Files> <PackName>ATtiny_DFP</PackName> <PackPath>D:/Atmel/7.0/Packs/atmel/ATtiny_DFP/1.1.102/Atmel.ATtiny_DFP.pdsc</PackPath> <PackVersion>1.1.102</PackVersion> <PackName>ATmega_DFP</PackName> <PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc</PackPath> <PackVersion>1.2.209</PackVersion> <PresentInProject>true</PresentInProject> <ReferenceConditionId>ATtiny817</ReferenceConditionId> <ReferenceConditionId>ATmega4809</ReferenceConditionId> <RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <d4p1:string></d4p1:string> </RteComponents> Loading
Session3-LF/Task1_LF/Task1_LF/Task1_LF.cproj +83 −80 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ <ProjectVersion>7.0</ProjectVersion> <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName> <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid> <avrdevice>ATtiny817</avrdevice> <avrdevice>ATmega4809</avrdevice> <avrdeviceseries>none</avrdeviceseries> <OutputType>Executable</OutputType> <Language>C</Language> Loading @@ -27,18 +27,19 @@ <BootSegment>2</BootSegment> <eraseonlaunchrule>0</eraseonlaunchrule> <AsfFrameworkConfig> <framework-data xmlns=""> <framework-data> <options /> <configurations /> <files /> <documentation help="" /> <offline-documentation help="" /> <dependencies> <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.32.0" /> <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.34.1" /> </dependencies> </framework-data> </AsfFrameworkConfig> <avrtool>com.atmel.avrdbg.tool.edbg</avrtool> <avrtool> </avrtool> <avrtoolserialnumber>ATML2654041800000542</avrtoolserialnumber> <avrdeviceexpectedsignature>0x1E9320</avrdeviceexpectedsignature> <avrtoolinterface>UPDI</avrtoolinterface> Loading @@ -54,11 +55,13 @@ <ToolName>EDBG</ToolName> </com_atmel_avrdbg_tool_edbg> <avrtoolinterfaceclock>100000</avrtoolinterfaceclock> <ResetRule>0</ResetRule> <EraseKey /> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <ToolchainSettings> <AvrGcc> <avrgcc.common.Device>-mmcu=attiny817 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\gcc\dev\attiny817"</avrgcc.common.Device> <avrgcc.common.Device>-mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809"</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> Loading @@ -73,7 +76,7 @@ </avrgcc.compiler.symbols.DefSymbols> <avrgcc.compiler.directories.IncludePaths> <ListValues> <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value> </ListValues> </avrgcc.compiler.directories.IncludePaths> <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level> Loading @@ -87,7 +90,7 @@ </avrgcc.linker.libraries.Libraries> <avrgcc.assembler.general.IncludePaths> <ListValues> <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value> </ListValues> </avrgcc.assembler.general.IncludePaths> </AvrGcc> Loading @@ -96,7 +99,7 @@ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <ToolchainSettings> <AvrGcc> <avrgcc.common.Device>-mmcu=attiny817 -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\gcc\dev\attiny817"</avrgcc.common.Device> <avrgcc.common.Device>-mmcu=atmega4809 -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega4809"</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> Loading @@ -111,7 +114,7 @@ </avrgcc.compiler.symbols.DefSymbols> <avrgcc.compiler.directories.IncludePaths> <ListValues> <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value> </ListValues> </avrgcc.compiler.directories.IncludePaths> <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level> Loading @@ -126,7 +129,7 @@ </avrgcc.linker.libraries.Libraries> <avrgcc.assembler.general.IncludePaths> <ListValues> <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value> </ListValues> </avrgcc.assembler.general.IncludePaths> <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel> Loading
Session3-LF/Task1_LF/Task1_LF/adc.c +2 −3 Original line number Diff line number Diff line Loading @@ -10,12 +10,11 @@ void adc_init(){ ADC0.CTRLA |= (ADC_RESSEL_8BIT_gc); //Set resolution, we choose 8 bits ADC0.CTRLB |= (ADC_SAMPLNUM_ACC4_gc); //OPTIONAL: We can use multiple samples if we like, example here with 4 ADC0.CTRLB |= (ADC_SAMPNUM_ACC4_gc); //OPTIONAL: We can use multiple samples if we like, example here with 4 //More samples gives a better result but takes longer ADC0.CTRLC |= (ADC_REFSEL_VDDREF_gc); //We select to use the supply voltage (VDD) as voltage reference ADC0.CTRLC |= (ADC_PRESC_DIV2_gc); //ADC clock prescaler, best accuracy when run below 2MHz. (Here div2 ~1.46 MHz) ADC0.CTRLA |= (ADC_ENABLE_bm); //Enable the ADC } Loading
Session3-LF/Task1_LF/Task1_LF/main.c +2 −2 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ #include "uart.h" #define LIGHT 6 // Light sensor is connected to ADC channel 6 (which is on port A pin 6) #define LIGHT 0x01 // Light sensor is connected to ADC channel 1 (which is on port D pin 1) uint8_t data = 0; Loading
Session3-LF/Task1_LF/Task1_LF/uart.c +28 −11 Original line number Diff line number Diff line Loading @@ -14,15 +14,25 @@ void uart_init(unsigned long baud){ //From chapter 24.3 in datasheet PORTB.OUTSET |= (1 << PIN2_bp); PORTB.DIRSET |= (1 << PIN2_bp); //Setting up TX pin as high output USART0.BAUD = baud; //Set baudrate //USART.CTRLC CMODE bits default to: async, 1 stop bit, 8 bit character size USART0.CTRLB |= (1 << USART_RXEN_bp) | (1 << USART_TXEN_bp); //Enable RX and TX //From chapter 22.3.1 in datasheet TX_PORT.OUTSET = (1 << TX_PIN); //Setting up TX pin as output TX_PORT.DIRSET = (1 << TX_PIN); //Setting up TX pin as output USART0.CTRLA |= (1 << USART_RXCIE_bp); //Enable interupts on RX //Set baud rate register USART3.BAUDL = (uint8_t) baud; //Set baud rate without shifting to get the 8 low bits USART3.BAUDH = (uint8_t)(baud >> 8); //Shift register right by 8 bits to get the 8 high bits //USART.CTRLC CMODE bits default to async, 1 stop bit, 8 bit character size //Since all bits are default 0 we only need to change the character size part USART3.CTRLC = (0x3 << USART_CHSIZE0_bp); //Enable RX and TX USART3.CTRLB = (1 << USART_RXEN_bp) | (1 << USART_TXEN_bp); //Enable interrupts on incoming data USART3.CTRLA |= (1 << USART_RXCIE_bp); fdevopen(uart_transmit, NULL); //This allows us to use printf instead of writing a single character at a time //It also allows for easily printing variable values: printf("X is currently: %d \n", x_var); Loading @@ -32,10 +42,17 @@ void uart_init(unsigned long baud){ // function to transmit data int uart_transmit(char data, FILE* stream){ while (!(USART0.STATUS & (1 << USART_DREIF_bp))){ //Wait for ongoing transmission to finish (if there is one) } USART0.TXDATAL = data; //Put new data in register //In this function we will be send data. //First we should check that there isn't already data being sent // if there is, we should probably wait for it to finish first while (!(USART3.STATUS & (1 << USART_DREIF_bp))){ //wait for previous transmit to finish }; //Put our new data into tx data register USART3.TXDATAL = data; return 0; } Loading