Commit 3f2d896a authored by BuildTools's avatar BuildTools
Browse files

Session 3 ported. Oled reset tin is NC(I think), so OLED is acting strange, but working.

parent 8de5c12b
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
<CSub></CSub> <CSub></CSub>
<CVariant></CVariant> <CVariant></CVariant>
<CVendor>Atmel</CVendor> <CVendor>Atmel</CVendor>
<CVersion>1.1.0</CVersion> <CVersion>1.2.0</CVersion>
<DefaultRepoPath>D:/Atmel\7.0\Packs</DefaultRepoPath> <DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" /> <DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<Description></Description> <Description></Description>
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:anyType i:type="FileInfo"> <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> <Attribute></Attribute>
<Category>include</Category> <Category>include</Category>
<Condition>C</Condition> <Condition>C</Condition>
...@@ -26,29 +26,29 @@ ...@@ -26,29 +26,29 @@
<SourcePath></SourcePath> <SourcePath></SourcePath>
</d4p1:anyType> </d4p1:anyType>
<d4p1:anyType i:type="FileInfo"> <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> <Attribute></Attribute>
<Category>header</Category> <Category>header</Category>
<Condition>C</Condition> <Condition>C</Condition>
<FileContentHash>GzsE/dwQAz37AkZENa/sHg==</FileContentHash> <FileContentHash>mWiFIOAGwUPlW0rYsXcjkg==</FileContentHash>
<FileVersion></FileVersion> <FileVersion></FileVersion>
<Name>include/avr/iotn817.h</Name> <Name>include/avr/iom4809.h</Name>
<SelectString></SelectString> <SelectString></SelectString>
<SourcePath></SourcePath> <SourcePath></SourcePath>
</d4p1:anyType> </d4p1:anyType>
<d4p1:anyType i:type="FileInfo"> <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> <Attribute>template</Attribute>
<Category>source</Category> <Category>source</Category>
<Condition>C Exe</Condition> <Condition>C Exe</Condition>
<FileContentHash>TQP/y9cNoVvAMzruFBs53A==</FileContentHash> <FileContentHash>GD1k8YYhulqRs6FD1B2Hog==</FileContentHash>
<FileVersion></FileVersion> <FileVersion></FileVersion>
<Name>templates/main.c</Name> <Name>templates/main.c</Name>
<SelectString>Main file (.c)</SelectString> <SelectString>Main file (.c)</SelectString>
<SourcePath></SourcePath> <SourcePath></SourcePath>
</d4p1:anyType> </d4p1:anyType>
<d4p1:anyType i:type="FileInfo"> <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> <Attribute>template</Attribute>
<Category>source</Category> <Category>source</Category>
<Condition>C Exe</Condition> <Condition>C Exe</Condition>
...@@ -59,22 +59,22 @@ ...@@ -59,22 +59,22 @@
<SourcePath></SourcePath> <SourcePath></SourcePath>
</d4p1:anyType> </d4p1:anyType>
<d4p1:anyType i:type="FileInfo"> <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> <Attribute></Attribute>
<Category>libraryPrefix</Category> <Category>libraryPrefix</Category>
<Condition>GCC</Condition> <Condition>GCC</Condition>
<FileContentHash i:nil="true" /> <FileContentHash i:nil="true" />
<FileVersion></FileVersion> <FileVersion></FileVersion>
<Name>gcc/dev/attiny817</Name> <Name>gcc/dev/atmega4809</Name>
<SelectString></SelectString> <SelectString></SelectString>
<SourcePath></SourcePath> <SourcePath></SourcePath>
</d4p1:anyType> </d4p1:anyType>
</Files> </Files>
<PackName>ATtiny_DFP</PackName> <PackName>ATmega_DFP</PackName>
<PackPath>D:/Atmel/7.0/Packs/atmel/ATtiny_DFP/1.1.102/Atmel.ATtiny_DFP.pdsc</PackPath> <PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc</PackPath>
<PackVersion>1.1.102</PackVersion> <PackVersion>1.2.209</PackVersion>
<PresentInProject>true</PresentInProject> <PresentInProject>true</PresentInProject>
<ReferenceConditionId>ATtiny817</ReferenceConditionId> <ReferenceConditionId>ATmega4809</ReferenceConditionId>
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string></d4p1:string> <d4p1:string></d4p1:string>
</RteComponents> </RteComponents>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<ProjectVersion>7.0</ProjectVersion> <ProjectVersion>7.0</ProjectVersion>
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName> <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid> <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
<avrdevice>ATtiny817</avrdevice> <avrdevice>ATmega4809</avrdevice>
<avrdeviceseries>none</avrdeviceseries> <avrdeviceseries>none</avrdeviceseries>
<OutputType>Executable</OutputType> <OutputType>Executable</OutputType>
<Language>C</Language> <Language>C</Language>
...@@ -27,18 +27,19 @@ ...@@ -27,18 +27,19 @@
<BootSegment>2</BootSegment> <BootSegment>2</BootSegment>
<eraseonlaunchrule>0</eraseonlaunchrule> <eraseonlaunchrule>0</eraseonlaunchrule>
<AsfFrameworkConfig> <AsfFrameworkConfig>
<framework-data xmlns=""> <framework-data>
<options /> <options />
<configurations /> <configurations />
<files /> <files />
<documentation help="" /> <documentation help="" />
<offline-documentation help="" /> <offline-documentation help="" />
<dependencies> <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> </dependencies>
</framework-data> </framework-data>
</AsfFrameworkConfig> </AsfFrameworkConfig>
<avrtool>com.atmel.avrdbg.tool.edbg</avrtool> <avrtool>
</avrtool>
<avrtoolserialnumber>ATML2654041800000542</avrtoolserialnumber> <avrtoolserialnumber>ATML2654041800000542</avrtoolserialnumber>
<avrdeviceexpectedsignature>0x1E9320</avrdeviceexpectedsignature> <avrdeviceexpectedsignature>0x1E9320</avrdeviceexpectedsignature>
<avrtoolinterface>UPDI</avrtoolinterface> <avrtoolinterface>UPDI</avrtoolinterface>
...@@ -54,83 +55,85 @@ ...@@ -54,83 +55,85 @@
<ToolName>EDBG</ToolName> <ToolName>EDBG</ToolName>
</com_atmel_avrdbg_tool_edbg> </com_atmel_avrdbg_tool_edbg>
<avrtoolinterfaceclock>100000</avrtoolinterfaceclock> <avrtoolinterfaceclock>100000</avrtoolinterfaceclock>
<ResetRule>0</ResetRule>
<EraseKey />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings> <ToolchainSettings>
<AvrGcc> <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.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss> <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep> <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec> <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures> <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned> <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned> <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols> <avrgcc.compiler.symbols.DefSymbols>
<ListValues> <ListValues>
<Value>NDEBUG</Value> <Value>NDEBUG</Value>
</ListValues> </ListValues>
</avrgcc.compiler.symbols.DefSymbols> </avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths> <avrgcc.compiler.directories.IncludePaths>
<ListValues> <ListValues>
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
</ListValues> </ListValues>
</avrgcc.compiler.directories.IncludePaths> </avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level> <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers> <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum> <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings> <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.linker.libraries.Libraries> <avrgcc.linker.libraries.Libraries>
<ListValues> <ListValues>
<Value>libm</Value> <Value>libm</Value>
</ListValues> </ListValues>
</avrgcc.linker.libraries.Libraries> </avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths> <avrgcc.assembler.general.IncludePaths>
<ListValues> <ListValues>
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
</ListValues> </ListValues>
</avrgcc.assembler.general.IncludePaths> </avrgcc.assembler.general.IncludePaths>
</AvrGcc> </AvrGcc>
</ToolchainSettings> </ToolchainSettings>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ToolchainSettings> <ToolchainSettings>
<AvrGcc> <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.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss> <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep> <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec> <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures> <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned> <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned> <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
<avrgcc.compiler.symbols.DefSymbols> <avrgcc.compiler.symbols.DefSymbols>
<ListValues> <ListValues>
<Value>DEBUG</Value> <Value>DEBUG</Value>
</ListValues> </ListValues>
</avrgcc.compiler.symbols.DefSymbols> </avrgcc.compiler.symbols.DefSymbols>
<avrgcc.compiler.directories.IncludePaths> <avrgcc.compiler.directories.IncludePaths>
<ListValues> <ListValues>
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
</ListValues> </ListValues>
</avrgcc.compiler.directories.IncludePaths> </avrgcc.compiler.directories.IncludePaths>
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level> <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers> <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum> <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel> <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings> <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
<avrgcc.linker.libraries.Libraries> <avrgcc.linker.libraries.Libraries>
<ListValues> <ListValues>
<Value>libm</Value> <Value>libm</Value>
</ListValues> </ListValues>
</avrgcc.linker.libraries.Libraries> </avrgcc.linker.libraries.Libraries>
<avrgcc.assembler.general.IncludePaths> <avrgcc.assembler.general.IncludePaths>
<ListValues> <ListValues>
<Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.1.102\include</Value> <Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
</ListValues> </ListValues>
</avrgcc.assembler.general.IncludePaths> </avrgcc.assembler.general.IncludePaths>
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel> <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
</AvrGcc> </AvrGcc>
</ToolchainSettings> </ToolchainSettings>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
......
...@@ -10,12 +10,11 @@ ...@@ -10,12 +10,11 @@
void adc_init(){ void adc_init(){
ADC0.CTRLA |= (ADC_RESSEL_8BIT_gc); //Set resolution, we choose 8 bits 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 //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_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.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 ADC0.CTRLA |= (ADC_ENABLE_bm); //Enable the ADC
} }
...@@ -28,7 +27,7 @@ uint8_t adc_read(uint8_t channel){ ...@@ -28,7 +27,7 @@ uint8_t adc_read(uint8_t channel){
ADC0.COMMAND |= (ADC_STCONV_bm); //Start a conversion ADC0.COMMAND |= (ADC_STCONV_bm); //Start a conversion
while(!(ADC0.INTFLAGS & ADC_RESRDY_bm)){ while(!(ADC0.INTFLAGS & ADC_RESRDY_bm)){
//Wait for the results ready flag to be set //Wait for the results ready flag to be set
} }
return ADC0.RESL; //Return 8 bit result return ADC0.RESL; //Return 8 bit result
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "uart.h" #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; uint8_t data = 0;
...@@ -37,7 +37,7 @@ int main(void) ...@@ -37,7 +37,7 @@ int main(void)
data = adc_read(LIGHT); //Read the analog voltage on channel 6, connected to light sensor data = adc_read(LIGHT); //Read the analog voltage on channel 6, connected to light sensor
//The light sensor returns the ones complement (the opposite) of the brightness: //The light sensor returns the ones complement (the opposite) of the brightness:
data = 0xff - data; data = 0xff - data;
printf("Light intensity is currently %d brightness points!\r\n", data); //Print out the value neatly using printf printf("Light intensity is currently %d brightness points!\r\n", data); //Print out the value neatly using printf
/* /*
......
...@@ -14,15 +14,25 @@ ...@@ -14,15 +14,25 @@
void uart_init(unsigned long baud){ void uart_init(unsigned long baud){
//From chapter 24.3 in datasheet //From chapter 22.3.1 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
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 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); //It also allows for easily printing variable values: printf("X is currently: %d \n", x_var);
...@@ -32,10 +42,17 @@ void uart_init(unsigned long baud){ ...@@ -32,10 +42,17 @@ void uart_init(unsigned long baud){
// function to transmit data // function to transmit data
int uart_transmit(char data, FILE* stream){ int uart_transmit(char data, FILE* stream){
while (!(USART0.STATUS & (1 << USART_DREIF_bp))){
//Wait for ongoing transmission to finish (if there is one) //In this function we will be send data.
}
USART0.TXDATAL = data; //Put new data in register //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; return 0;
} }
......
...@@ -10,9 +10,12 @@ ...@@ -10,9 +10,12 @@
#define UART_H_ #define UART_H_
#include <stdio.h> //Required for the FILE* type to be recognzed in the uart_transmit prototype #include <stdio.h> //Required for the FILE* type to be recognzed in the uart_transmit prototype
#define TX_PORT PORTB
#define TX_PIN 0
void uart_init(unsigned long baud); void uart_init(unsigned long baud);
int uart_transmit(char data, FILE* stream); int uart_transmit(char data, FILE* stream);
#endif /* UART_H_ */ #endif /* UART_H_ */
\ No newline at end of file
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
<CSub></CSub> <CSub></CSub>
<CVariant></CVariant> <CVariant></CVariant>
<CVendor>Atmel</CVendor> <CVendor>Atmel</CVendor>
<CVersion>1.1.0</CVersion> <CVersion>1.2.0</CVersion>
<DefaultRepoPath>D:/Atmel\7.0\Packs</DefaultRepoPath> <DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" /> <DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<Description></Description> <Description></Description>
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:anyType i:type="FileInfo"> <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> <Attribute></Attribute>
<Category>include</Category> <Category>include</Category>
<Condition>C</Condition> <Condition>C</Condition>
...@@ -26,29 +26,29 @@ ...@@ -26,29 +26,29 @@
<SourcePath></SourcePath> <SourcePath></SourcePath>
</d4p1:anyType> </d4p1:anyType>
<d4p1:anyType i:type="FileInfo"> <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> <Attribute></Attribute>
<Category>header</Category> <Category>header</Category>
<Condition>C</Condition> <Condition>C</Condition>
<FileContentHash>GzsE/dwQAz37AkZENa/sHg==</FileContentHash> <FileContentHash>mWiFIOAGwUPlW0rYsXcjkg==</FileContentHash>
<FileVersion></FileVersion> <FileVersion></FileVersion>
<Name>include/avr/iotn817.h</Name> <Name>include/avr/iom4809.h</Name>
<SelectString></SelectString> <SelectString></SelectString>
<SourcePath></SourcePath> <SourcePath></SourcePath>
</d4p1:anyType> </d4p1:anyType>
<d4p1:anyType i:type="FileInfo"> <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> <Attribute>template</Attribute>
<Category>source</Category> <Category>source</Category>
<Condition>C Exe</Condition> <Condition>C Exe</Condition>
<FileContentHash>RtJJIrracgoBJUhAmsGN5g==</FileContentHash> <FileContentHash>GD1k8YYhulqRs6FD1B2Hog==</FileContentHash>
<FileVersion></FileVersion> <FileVersion></FileVersion>
<Name>templates/main.c</Name> <Name>templates/main.c</Name>
<SelectString>Main file (.c)</SelectString> <SelectString>Main file (.c)</SelectString>
<SourcePath></SourcePath> <SourcePath></SourcePath>
</d4p1:anyType> </d4p1:anyType>
<d4p1:anyType i:type="FileInfo"> <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> <Attribute>template</Attribute>
<Category>source</Category> <Category>source</Category>
<Condition>C Exe</Condition> <Condition>C Exe</Condition>
...@@ -59,22 +59,22 @@ ...@@ -59,22 +59,22 @@
<SourcePath></SourcePath> <SourcePath></SourcePath>
</d4p1:anyType> </d4p1:anyType>
<d4p1:anyType i:type="FileInfo"> <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> <Attribute></Attribute>
<Category>libraryPrefix</Category> <Category>libraryPrefix</Category>
<Condition>GCC</Condition> <Condition>GCC</Condition>
<FileContentHash i:nil="true" /> <FileContentHash i:nil="true" />
<FileVersion></FileVersion> <FileVersion></FileVersion>
<Name>gcc/dev/attiny817</Name> <Name>gcc/dev/atmega4809</Name>
<SelectString></SelectString> <SelectString></SelectString>
<SourcePath></SourcePath> <SourcePath></SourcePath>
</d4p1:anyType> </d4p1:anyType>
</Files> </Files>
<PackName>ATtiny_DFP</PackName> <PackName>ATmega_DFP</PackName>
<PackPath>D:/Atmel/7.0/Packs/atmel/ATtiny_DFP/1.1.102/Atmel.ATtiny_DFP.pdsc</PackPath> <PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc</PackPath>
<PackVersion>1.1.102</PackVersion> <PackVersion>1.2.209</PackVersion>
<PresentInProject>true</PresentInProject> <PresentInProject>true</PresentInProject>
<ReferenceConditionId>ATtiny817</ReferenceConditionId> <ReferenceConditionId>ATmega4809</ReferenceConditionId>
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string></d4p1:string> <d4p1:string></d4p1:string>
</RteComponents> </RteComponents>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<ProjectVersion>7.0</ProjectVersion> <ProjectVersion>7.0</ProjectVersion>
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName> <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid> <ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
<avrdevice>ATtiny817</avrdevice> <avrdevice>ATmega4809</avrdevice>
<avrdeviceseries>none</avrdeviceseries> <avrdeviceseries>none</avrdeviceseries>
<OutputType>Executable</OutputType> <OutputType>Executable</OutputType>
<Language>C</Language> <Language>C</Language>
...@@ -20,103 +20,119 @@ ...@@ -20,103 +20,119 @@