Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
avrkurs
avrkurs
Commits
11fb15c0
Commit
11fb15c0
authored
Feb 17, 2019
by
medlem
Browse files
Working USART and fixed comments and defines and tx string
parent
10bf504f
Pipeline
#242
failed with stages
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Session2-LF/UART/Debug/UART-LF.o
View file @
11fb15c0
No preview for this file type
Session2-LF/UART/Debug/UART.elf
View file @
11fb15c0
No preview for this file type
Session2-LF/UART/Debug/UART.hex
View file @
11fb15c0
...
...
@@ -7,13 +7,20 @@
:100060000C945A000C945A000C945A000C945A00A8
:100070000C945A000C945A000C945A000C945A0098
:100080000C945A000C945A000C945A000C945A0088
:100090000C945A000C945A000C94
5A
000C945A007
8
:1000A00011241FBECFEFCDBFDFE3DEBF0E94
76007D
:1000B0000C94
88
000C940000E0E2F4E021E02583
39
:100090000C945A000C945A000C94
9B
000C945A00
3
7
:1000A00011241FBECFEFCDBFDFE3DEBF0E94
88006B
:1000B0000C94
B2
000C940000E0E2F4E021E02583
0F
:1000C0002183E0E6F8E06087BB27A92F982F872FD0
:1000D000818783E0878380EC86830895E0E6F8E0FB
:1000E000948195FFFDCF8093620808956CE675E0DA
:1000F00080E090E00E945C00789488E60E946E00A8
:1001000025ED88E092E0215080409040E1F7F5CF66
:04011000F894FFCF91
:1000D000818783E0878380EC868385818068858340
:1000E0000895E0E6F8E0948195FFFDCF80936208E3
:1000F0000895CF93DF93EC018881882331F0219616
:100100000E94710089918111FBCFDF91CF910895F9
:100110006CE675E080E090E00E945C00789488E6F0
:1001200091E40E94790025ED88E092E02150804022
:100130009040E1F7F4CF1F920F920FB60F92112467
:100140008F93EF93FF93E0E6F8E084818823ECF748
:1001500080916008FF91EF918F910F900FBE0F90EB
:080160001F901895F894FFCFE1
:10016800446574746520657220656E2074657374C7
:020178000A007B
:00000001FF
Session2-LF/UART/Debug/UART.lss
View file @
11fb15c0
...
...
@@ -3,27 +3,31 @@ UART.elf: file format elf32-avr
Sections:
Idx Name Size VMA LMA File off Algn
0 .data 00000000 00802800 00802800 000001
68
2**0
0 .data 00000000 00802800 00802800 000001
ee
2**0
CONTENTS, ALLOC, LOAD, DATA
1 .text 000001
14
00000000 00000000 000000
5
4 2**1
1 .text 000001
68
00000000 00000000 000000
7
4 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
2 .comment 00000030 00000000 00000000 00000168 2**0
2 .rodata 00000012 00004168 00000168 000001dc 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .comment 00000030 00000000 00000000 000001ee 2**0
CONTENTS, READONLY
3
.note.gnu.avr.deviceinfo 00000040 00000000 00000000 00000
198
2**2
4
.note.gnu.avr.deviceinfo 00000040 00000000 00000000 00000
220
2**2
CONTENTS, READONLY
4
.debug_aranges 000000
3
0 00000000 00000000 00000
1d8
2**0
5
.debug_aranges 000000
4
0 00000000 00000000 00000
260
2**0
CONTENTS, READONLY, DEBUGGING
5
.debug_info 00002
7ba
00000000 00000000 0000020
8
2**0
6
.debug_info 00002
823
00000000 00000000 000002
a
0 2**0
CONTENTS, READONLY, DEBUGGING
6
.debug_abbrev 000022
6c
00000000 00000000 00002
9c2
2**0
7
.debug_abbrev 000022
d2
00000000 00000000 00002
ac3
2**0
CONTENTS, READONLY, DEBUGGING
7
.debug_line 000003
6a
00000000 00000000 00004
c2e
2**0
8
.debug_line 000003
c8
00000000 00000000 00004
d95
2**0
CONTENTS, READONLY, DEBUGGING
8
.debug_frame 000000
44
00000000 00000000 0000
4f98
2**2
9
.debug_frame 000000
8c
00000000 00000000 0000
5160
2**2
CONTENTS, READONLY, DEBUGGING
9
.debug_str 00001
1f0
00000000 00000000 0000
4fd
c 2**0
10
.debug_str 00001
211
00000000 00000000 0000
51e
c 2**0
CONTENTS, READONLY, DEBUGGING
10 .debug_ranges 00000020 00000000 00000000 000061cc 2**0
11 .debug_loc 000000d7 00000000 00000000 000063fd 2**0
CONTENTS, READONLY, DEBUGGING
12 .debug_ranges 00000030 00000000 00000000 000064d4 2**0
CONTENTS, READONLY, DEBUGGING
Disassembly of section .text:
...
...
@@ -67,7 +71,7 @@ Disassembly of section .text:
8c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
90: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
94: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
98: 0c 94
5a
00 jmp 0x
b4
; 0x
b4
<__
bad_interrupt
>
98: 0c 94
9b
00 jmp 0x
136
; 0x
136
<__
vector_38
>
9c: 0c 94 5a 00 jmp 0xb4 ; 0xb4 <__bad_interrupt>
000000a0 <__ctors_end>:
...
...
@@ -77,8 +81,8 @@ Disassembly of section .text:
a6: cd bf out 0x3d, r28 ; 61
a8: df e3 ldi r29, 0x3F ; 63
aa: de bf out 0x3e, r29 ; 62
ac: 0e 94
76
00 call 0x
ec
; 0x
ec
<main>
b0: 0c 94
88
00 jmp 0x1
10
; 0x1
10
<_exit>
ac: 0e 94
88
00 call 0x
110
; 0x
110
<main>
b0: 0c 94
b2
00 jmp 0x1
64
; 0x1
64
<_exit>
000000b4 <__bad_interrupt>:
b4: 0c 94 00 00 jmp 0 ; 0x0 <__vectors>
...
...
@@ -87,25 +91,22 @@ Disassembly of section .text:
void uart_init(unsigned long baud){
//From chapter 2
4
.3 in datasheet
//From chapter 2
2
.3
.1
in datasheet
PORT
B
.OUTSET = (1 <<
0
); //Setting up TX pin as output
TX_
PORT.OUTSET = (1 <<
TX_PIN
); //Setting up TX pin as output
b8: e0 e2 ldi r30, 0x20 ; 32
ba: f4 e0 ldi r31, 0x04 ; 4
bc: 21 e0 ldi r18, 0x01 ; 1
be: 25 83 std Z+5, r18 ; 0x05
PORT
B
.DIRSET = (1 <<
0
); //Setting up TX pin as output
TX_
PORT.DIRSET = (1 <<
TX_PIN
); //Setting up TX pin as output
c0: 21 83 std Z+1, r18 ; 0x01
//USART3.BAUDH = (baud >> 8); //Shift register right by 8 bits to get the 8 high bits
//USART3.BAUDL = baud; //Set baud rate without shifting to get the 8 low bits
//It turns out the compiler can handle this automatically, meaning this works just as well:
USART3.BAUDL = (uint8_t)baud;
//Set baud rate register
USART3.BAUDL = (uint8_t) baud; //Set baud rate without shifting to get the 8 low bits
c2: e0 e6 ldi r30, 0x60 ; 96
c4: f8 e0 ldi r31, 0x08 ; 8
c6: 60 87 std Z+8, r22 ; 0x08
USART3.BAUDH = (uint8_t)(baud >> 8);
USART3.BAUDH = (uint8_t)(baud >> 8);
//Shift register right by 8 bits to get the 8 high bits
c8: bb 27 eor r27, r27
ca: a9 2f mov r26, r25
cc: 98 2f mov r25, r24
...
...
@@ -114,75 +115,156 @@ void uart_init(unsigned long baud){
//USART.CTRLC CMODE bits default to async, 1 stop bit, 8 bit character size
USART3.CTRLC = (0x3 << 0);
//Since all bits are default 0 we only need to change the character size part
USART3.CTRLC = (0x3 << USART_CHSIZE0_bp);
d2: 83 e0 ldi r24, 0x03 ; 3
d4: 87 83 std Z+7, r24 ; 0x07
USART3.CTRLB = (1 << USART_RXEN_bp) | (1 << USART_TXEN_bp); //Enable RX and TX
//Enable RX and TX
USART3.CTRLB = (1 << USART_RXEN_bp) | (1 << USART_TXEN_bp);
d6: 80 ec ldi r24, 0xC0 ; 192
d8: 86 83 std Z+6, r24 ; 0x06
da: 08 95 ret
000000dc <uart_transmit>:
//Enable interrupts on incoming data
USART3.CTRLA |= (1 << USART_RXCIE_bp);
da: 85 81 ldd r24, Z+5 ; 0x05
dc: 80 68 ori r24, 0x80 ; 128
de: 85 83 std Z+5, r24 ; 0x05
e0: 08 95 ret
000000e2 <uart_transmit>:
//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))){
dc
: e0 e6 ldi r30, 0x60 ; 96
d
e: f8 e0 ldi r31, 0x08 ; 8
e
0
: 94 81 ldd r25, Z+4 ; 0x04
e
2
: 95 ff sbrs r25, 5
e
4
: fd cf rjmp .-6 ; 0xe
0
<uart_transmit+0x4>
e2
: e0 e6 ldi r30, 0x60 ; 96
e
4
: f8 e0 ldi r31, 0x08 ; 8
e
6
: 94 81 ldd r25, Z+4 ; 0x04
e
8
: 95 ff sbrs r25, 5
e
a
: fd cf rjmp .-6 ; 0xe
6
<uart_transmit+0x4>
//wait for previous transmit to finish
};
//Put our new data into
se sending
register
//Put our new data into
tx data
register
USART3.TXDATAL = data;
e6: 80 93 62 08 sts 0x0862, r24 ; 0x800862 <__TEXT_REGION_LENGTH__+0x700862>
ea: 08 95 ret
ec: 80 93 62 08 sts 0x0862, r24 ; 0x800862 <__TEXT_REGION_LENGTH__+0x700862>
f0: 08 95 ret
000000f2 <uart_transmit_string>:
}
000000ec <main>:
//To send a string we can do this
void uart_transmit_string(char* data) {
f2: cf 93 push r28
f4: df 93 push r29
f6: ec 01 movw r28, r24
while (*data != '\0') {
f8: 88 81 ld r24, Y
fa: 88 23 and r24, r24
fc: 31 f0 breq .+12 ; 0x10a <uart_transmit_string+0x18>
fe: 21 96 adiw r28, 0x01 ; 1
uart_transmit(*data);
100: 0e 94 71 00 call 0xe2 ; 0xe2 <uart_transmit>
}
//To send a string we can do this
void uart_transmit_string(char* data) {
while (*data != '\0') {
104: 89 91 ld r24, Y+
106: 81 11 cpse r24, r1
108: fb cf rjmp .-10 ; 0x100 <uart_transmit_string+0xe>
uart_transmit(*data);
data++;
}
}
10a: df 91 pop r29
10c: cf 91 pop r28
10e: 08 95 ret
00000110 <main>:
int main(void)
{
//Initialize the UART with our function.
//We will be using a baudrate of 9600 (defined as BAUD_9600 at the top of the file)
uart_init(BAUD_9600);
ec
: 6c e6 ldi r22, 0x6C ; 108
ee
: 75 e0 ldi r23, 0x05 ; 5
f0
: 80 e0 ldi r24, 0x00 ; 0
f2
: 90 e0 ldi r25, 0x00 ; 0
f4
: 0e 94 5c 00 call 0xb8 ; 0xb8 <uart_init>
110
: 6c e6 ldi r22, 0x6C ; 108
112
: 75 e0 ldi r23, 0x05 ; 5
114
: 80 e0 ldi r24, 0x00 ; 0
116
: 90 e0 ldi r25, 0x00 ; 0
118
: 0e 94 5c 00 call 0xb8 ; 0xb8 <uart_init>
sei(); //Enable inerrupt, important for anything here to work
f8
: 78 94 sei
11c
: 78 94 sei
while (1)
{
//We don't really need to do anything here.
//the ISR will handle receiving.
uart_transmit('h');
fa: 88 e6 ldi r24, 0x68 ; 104
fc: 0e 94 6e 00 call 0xdc ; 0xdc <uart_transmit>
uart_transmit_string("Dette er en test\n");
11e: 88 e6 ldi r24, 0x68 ; 104
120: 91 e4 ldi r25, 0x41 ; 65
122: 0e 94 79 00 call 0xf2 ; 0xf2 <uart_transmit_string>
#else
//round up by default
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
#endif
__builtin_avr_delay_cycles(__ticks_dc);
100: 25 ed ldi r18, 0xD5 ; 213
102: 88 e0 ldi r24, 0x08 ; 8
104: 92 e0 ldi r25, 0x02 ; 2
106: 21 50 subi r18, 0x01 ; 1
108: 80 40 sbci r24, 0x00 ; 0
10a: 90 40 sbci r25, 0x00 ; 0
10c: e1 f7 brne .-8 ; 0x106 <main+0x1a>
10e: f5 cf rjmp .-22 ; 0xfa <main+0xe>
00000110 <_exit>:
110: f8 94 cli
00000112 <__stop_program>:
112: ff cf rjmp .-2 ; 0x112 <__stop_program>
126: 25 ed ldi r18, 0xD5 ; 213
128: 88 e0 ldi r24, 0x08 ; 8
12a: 92 e0 ldi r25, 0x02 ; 2
12c: 21 50 subi r18, 0x01 ; 1
12e: 80 40 sbci r24, 0x00 ; 0
130: 90 40 sbci r25, 0x00 ; 0
132: e1 f7 brne .-8 ; 0x12c <main+0x1c>
134: f4 cf rjmp .-24 ; 0x11e <main+0xe>
00000136 <__vector_38>:
}
}
//Interrupt service routine for the receiver.
ISR (USART3_RXC_vect) {
136: 1f 92 push r1
138: 0f 92 push r0
13a: 0f b6 in r0, 0x3f ; 63
13c: 0f 92 push r0
13e: 11 24 eor r1, r1
140: 8f 93 push r24
142: ef 93 push r30
144: ff 93 push r31
//In the interrupt we will read the data in the receive buffer
//First we should check that new data has arrived the receive buffer
while (!(USART3.STATUS & (1 << USART_RXCIF_bp))){
146: e0 e6 ldi r30, 0x60 ; 96
148: f8 e0 ldi r31, 0x08 ; 8
14a: 84 81 ldd r24, Z+4 ; 0x04
14c: 88 23 and r24, r24
14e: ec f7 brge .-6 ; 0x14a <__vector_38+0x14>
//wait for previous transmit to finish
};
//Store the data in a temporarily variable
uint8_t tmp = USART3.RXDATAL;
150: 80 91 60 08 lds r24, 0x0860 ; 0x800860 <__TEXT_REGION_LENGTH__+0x700860>
154: ff 91 pop r31
156: ef 91 pop r30
158: 8f 91 pop r24
15a: 0f 90 pop r0
15c: 0f be out 0x3f, r0 ; 63
15e: 0f 90 pop r0
160: 1f 90 pop r1
162: 18 95 reti
00000164 <_exit>:
164: f8 94 cli
00000166 <__stop_program>:
166: ff cf rjmp .-2 ; 0x166 <__stop_program>
Session2-LF/UART/Debug/UART.map
View file @
11fb15c0
...
...
@@ -153,7 +153,7 @@ END GROUP
.rela.plt
*(.rela.plt)
.text 0x00000000 0x1
14
.text 0x00000000 0x1
68
*(.vectors)
.vectors 0x00000000 0xa0 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/gcc/dev/atmega4809/avrxmega3/crtatmega4809.o
0x00000000 __vector_default
...
...
@@ -208,7 +208,6 @@ END GROUP
*(.init9)
*(.text)
.text 0x000000b4 0x4 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/gcc/dev/atmega4809/avrxmega3/crtatmega4809.o
0x000000b4 __vector_38
0x000000b4 __vector_22
0x000000b4 __vector_28
0x000000b4 __vector_1
...
...
@@ -251,18 +250,24 @@ END GROUP
0x000000b8 . = ALIGN (0x2)
*(.text.*)
.text.uart_init
0x000000b8 0x2
4
UART-LF.o
0x000000b8 0x2
a
UART-LF.o
0x000000b8 uart_init
.text.uart_transmit
0x000000dc 0x10 UART-LF.o
0x000000dc uart_transmit
.text.main 0x000000ec 0x24 UART-LF.o
0x000000ec main
0x00000110 . = ALIGN (0x2)
0x000000e2 0x10 UART-LF.o
0x000000e2 uart_transmit
.text.uart_transmit_string
0x000000f2 0x1e UART-LF.o
0x000000f2 uart_transmit_string
.text.main 0x00000110 0x26 UART-LF.o
0x00000110 main
.text.__vector_38
0x00000136 0x2e UART-LF.o
0x00000136 __vector_38
0x00000164 . = ALIGN (0x2)
*(.fini9)
.fini9 0x000001
10
0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avrxmega3\libgcc.a(_exit.o)
0x000001
10
_exit
0x000001
10
exit
.fini9 0x000001
64
0x0 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avrxmega3\libgcc.a(_exit.o)
0x000001
64
_exit
0x000001
64
exit
*(.fini9)
*(.fini8)
*(.fini8)
...
...
@@ -281,16 +286,18 @@ END GROUP
*(.fini1)
*(.fini1)
*(.fini0)
.fini0 0x000001
10
0x4 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avrxmega3\libgcc.a(_exit.o)
.fini0 0x000001
64
0x4 c:/program files (x86)/atmel/studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avrxmega3\libgcc.a(_exit.o)
*(.fini0)
0x000001
14
_etext = .
0x000001
68
_etext = .
.rodata
.rodata
0x00004168 0x12 load address 0x00000168
*(.rodata)
*(.rodata*)
.rodata.str1.1
0x00004168 0x12 UART-LF.o
*(.gnu.linkonce.r*)
.data 0x00802800 0x0 load address 0x000001
14
.data 0x00802800 0x0 load address 0x000001
7a
[!provide] PROVIDE (__data_start, .)
*(.data)
*(.data*)
...
...
@@ -305,8 +312,8 @@ END GROUP
*(.bss*)
*(COMMON)
[!provide] PROVIDE (__bss_end, .)
0x000001
14
__data_load_start = LOADADDR (.data)
0x000001
14
__data_load_end = (__data_load_start + SIZEOF (.data))
0x000001
7a
__data_load_start = LOADADDR (.data)
0x000001
7a
__data_load_end = (__data_load_start + SIZEOF (.data))
.noinit 0x00802800 0x0
[!provide] PROVIDE (__noinit_start, .)
...
...
@@ -377,41 +384,42 @@ END GROUP
.debug_sfnames
*(.debug_sfnames)
.debug_aranges 0x00000000 0x
3
0
.debug_aranges 0x00000000 0x
4
0
*(.debug_aranges)
.debug_aranges
0x00000000 0x
3
0 UART-LF.o
0x00000000 0x
4
0 UART-LF.o
.debug_pubnames
*(.debug_pubnames)
.debug_info 0x00000000 0x2
7ba
.debug_info 0x00000000 0x2
823
*(.debug_info .gnu.linkonce.wi.*)
.debug_info 0x00000000 0x22b7 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/gcc/dev/atmega4809/avrxmega3/crtatmega4809.o
.debug_info 0x000022b7 0x5
03
UART-LF.o
.debug_info 0x000022b7 0x5
6c
UART-LF.o
.debug_abbrev 0x00000000 0x22
6c
.debug_abbrev 0x00000000 0x22
d2
*(.debug_abbrev)
.debug_abbrev 0x00000000 0x20e0 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/gcc/dev/atmega4809/avrxmega3/crtatmega4809.o
.debug_abbrev 0x000020e0 0x1
8c
UART-LF.o
.debug_abbrev 0x000020e0 0x1
f2
UART-LF.o
.debug_line 0x00000000 0x3
6a
.debug_line 0x00000000 0x3
c8
*(.debug_line .debug_line.* .debug_line_end)
.debug_line 0x00000000 0x187 C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/gcc/dev/atmega4809/avrxmega3/crtatmega4809.o
.debug_line 0x00000187 0x
1e3
UART-LF.o
.debug_line 0x00000187 0x
241
UART-LF.o
.debug_frame 0x00000000 0x
44
.debug_frame 0x00000000 0x
8c
*(.debug_frame)
.debug_frame 0x00000000 0x
44
UART-LF.o
.debug_frame 0x00000000 0x
8c
UART-LF.o
.debug_str 0x00000000 0x1
1f0
.debug_str 0x00000000 0x1
211
*(.debug_str)
.debug_str 0x00000000 0xe5d C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/gcc/dev/atmega4809/avrxmega3/crtatmega4809.o
.debug_str 0x00000e5d 0x3
93
UART-LF.o
0x3
cc
(size before relaxing)
.debug_str 0x00000e5d 0x3
b4
UART-LF.o
0x3
ed
(size before relaxing)
.debug_loc
.debug_loc
0x00000000 0xd7
*(.debug_loc)
.debug_loc 0x00000000 0xd7 UART-LF.o
.debug_macinfo
*(.debug_macinfo)
...
...
@@ -431,9 +439,9 @@ END GROUP
.debug_pubtypes
*(.debug_pubtypes)
.debug_ranges 0x00000000 0x
2
0
.debug_ranges 0x00000000 0x
3
0
*(.debug_ranges)
.debug_ranges 0x00000000 0x
2
0 UART-LF.o
.debug_ranges 0x00000000 0x
3
0 UART-LF.o
.debug_macro
*(.debug_macro)
...
...
Session2-LF/UART/Debug/UART.srec
View file @
11fb15c0
...
...
@@ -8,13 +8,20 @@ S11300500C945A000C945A000C945A000C945A00B4
S11300600C945A000C945A000C945A000C945A00A4
S11300700C945A000C945A000C945A000C945A0094
S11300800C945A000C945A000C945A000C945A0084
S11300900C945A000C945A000C94
5A
000C945A00
74
S11300A011241FBECFEFCDBFDFE3DEBF0E94
760079
S11300B00C94
88
000C940000E0E2F4E021E02583
35
S11300900C945A000C945A000C94
9B
000C945A00
33
S11300A011241FBECFEFCDBFDFE3DEBF0E94
880067
S11300B00C94
B2
000C940000E0E2F4E021E02583
0B
S11300C02183E0E6F8E06087BB27A92F982F872FCC
S11300D0818783E0878380EC86830895E0E6F8E0F7
S11300E0948195FFFDCF8093620808956CE675E0D6
S11300F080E090E00E945C00789488E60E946E00A4
S113010025ED88E092E0215080409040E1F7F5CF62
S1070110F894FFCF8D
S11300D0818783E0878380EC86838581806885833C
S11300E00895E0E6F8E0948195FFFDCF80936208DF
S11300F00895CF93DF93EC018881882331F0219612
S11301000E94710089918111FBCFDF91CF910895F5
S11301106CE675E080E090E00E945C00789488E6EC
S113012091E40E94790025ED88E092E0215080401E
S11301309040E1F7F4CF1F920F920FB60F92112463
S11301408F93EF93FF93E0E6F8E084818823ECF744
S113015080916008FF91EF918F910F900FBE0F90E7
S10B01601F901895F894FFCFDD
S1130168446574746520657220656E2074657374C3
S10501780A0077
S9030000FC
Session2-LF/UART/UART-LF.c
View file @
11fb15c0
...
...
@@ -15,33 +15,33 @@
/*
In this exercise we will set up and use UART communication.
The embedded debugger has a virtual com port that we will use to communicate with the computer.
*/
*/
#define TX_PORT PORTB
#define TX_PIN 0
void
uart_init
(
unsigned
long
baud
){
//From chapter 2
4
.3 in datasheet
//From chapter 2
2
.3
.1
in datasheet
PORT
B
.
OUTSET
=
(
1
<<
0
);
//Setting up TX pin as output
PORT
B
.
DIRSET
=
(
1
<<
0
);
//Setting up TX pin as output
TX_
PORT
.
OUTSET
=
(
1
<<
TX_PIN
);
//Setting up TX pin as output
TX_
PORT
.
DIRSET
=
(
1
<<
TX_PIN
);
//Setting up TX pin as output
//USART3.BAUDH = (baud >> 8); //Shift register right by 8 bits to get the 8 high bits
//USART3.BAUDL = baud; //Set baud rate without shifting to get the 8 low bits
//It turns out the compiler can handle this automatically, meaning this works just as well:
USART3
.
BAUDL
=
(
uint8_t
)
baud
;
USART3
.
BAUDH
=
(
uint8_t
)(
baud
>>
8
);
//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
USART3
.
CTRLC
=
(
0x3
<<
0
);
//Since all bits are default 0 we only need to change the character size part
USART3
.
CTRLC
=
(
0x3
<<
USART_CHSIZE0_bp
);
USART3
.
CTRLB
=
(
1
<<
USART_RXEN_bp
)
|
(
1
<<
USART_TXEN_bp
);
//Enable RX and TX
//Enable RX and TX
USART3
.
CTRLB
=
(
1
<<
USART_RXEN_bp
)
|
(
1
<<
USART_TXEN_bp
);
//USART3.CTRLA |= (1 << USART_RXCIE_bp); //Enable interrupts on incoming data
//Enable interrupts on incoming data
USART3
.
CTRLA
|=
(
1
<<
USART_RXCIE_bp
);
}
// function to transmit data
...
...
@@ -55,11 +55,20 @@ void uart_transmit(char data){
//wait for previous transmit to finish
};
//Put our new data into
se sending
register
//Put our new data into
tx data
register
USART3
.
TXDATAL
=
data
;
}
//To send a string we can do this
void
uart_transmit_string
(
char
*
data
)
{
while
(
*
data
!=
'\0'
)
{
uart_transmit
(
*
data
);
data
++
;
}
}
int
main
(
void
)
{
//Initialize the UART with our function.
...
...
@@ -72,10 +81,21 @@ int main(void)
{
//We don't really need to do anything here.
//the ISR will handle receiving.
uart_transmit
(
'h'
);
uart_transmit
_string
(
"Dette er en test
\n
"
);
_delay_ms
(
200
);
}
}
//Interrupt service routine for the receiver.
ISR
(
USART3_RXC_vect
)
{
//In the interrupt we will read the data in the receive buffer
//First we should check that new data has arrived the receive buffer
while
(
!
(
USART3
.
STATUS
&
(
1
<<
USART_RXCIF_bp
))){
//wait for previous transmit to finish
};
//Store the data in a temporarily variable
uint8_t
tmp
=
USART3
.
RXDATAL
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment