Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
attinykurs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
simenpf
attinykurs
Commits
89bc499e
Commit
89bc499e
authored
Mar 05, 2019
by
siguhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Meurd and Yoolando read trough session3 tasks and fixed some things
parent
1436e0a1
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
70 additions
and
35 deletions
+70
-35
Session3/Task1/adc.h
Session3/Task1/adc.h
+2
-2
Session3/Task1/main.c
Session3/Task1/main.c
+11
-9
Session3/Task1/uart.c
Session3/Task1/uart.c
+38
-15
Session3/Task1/uart.h
Session3/Task1/uart.h
+12
-3
Session3/Task2/display.h
Session3/Task2/display.h
+2
-2
Session3/Task2/main.c
Session3/Task2/main.c
+3
-3
Session3/Task2/spi.c
Session3/Task2/spi.c
+2
-1
No files found.
Session3/Task1/adc.h
View file @
89bc499e
...
...
@@ -5,6 +5,6 @@
void
adc_init
(
void
);
//This function initialezes the ADC module
uint8_t
adc_read
(
uint8_t
channel
);
//T
H
is function takes in a channel and returns the result of the ADC measurement of the channel
uint8_t
adc_read
(
uint8_t
channel
);
//T
h
is function takes in a channel and returns the result of the ADC measurement of the channel
#endif
/* ADC_H_ */
\ No newline at end of file
#endif
/* ADC_H_ */
Session3/Task1/main.c
View file @
89bc499e
...
...
@@ -8,14 +8,16 @@
#include <avr/interrupt.h>
#include "adc.h"
//#include "adc.c" if on linux
#include "uart.h"
//#include "uart.c" if on linux
/* In this exercice you will be writing an ADC driver.
You will use this to read the light sensor on the
OI1 Xplained
board.
Connect th
e board to the EXT1 Header of the ATmega4809
You will use this to read the light sensor on the
IO1 Xplained Pro
board.
Connect th
is board to the Xplained Pro Extension Header of the Curiosity Nano Adapter.
We send the result of the measurement to the computer using UART.
A complete and working UART driver has been provided with the exercise
We send the result of the measurement to the computer using U
S
ART.
A complete and working U
S
ART driver has been provided with the exercise
It has been setup so that you can use printf to print nicely formated text and variable values to the terminal
...
...
@@ -26,8 +28,8 @@ int main(void)
//Initialize everything we need here
sei
();
//If we want to receive via UART we need interrupts enabled.
//NOTE: UART isn't used to receive here and as such this isn't required.
sei
();
//If we want to receive via U
S
ART we need interrupts enabled.
//NOTE: U
S
ART isn't used to receive here and as such this isn't required.
while
(
1
)
{
...
...
@@ -37,9 +39,9 @@ int main(void)
/*
About printf: Handles formatting of your print to terminal. This includes special characters, values of variables and more.
It takes one string and any variables you want to print.
Some handy special characters: \n = newline (enter), \t = tab
%
marks a variable to be inserted in the string. %d = decimal, %x = hexadecimal, %f = floating point number (There are many more)
Variables to be inserted have to be provided
comma separated
after the string in order of appearance in string.
Some handy special characters: \n = newline (enter)
(some terminals need \r also)
, \t = tab
'%'
marks a variable to be inserted in the string. %d = decimal, %x = hexadecimal, %f = floating point number (There are many more)
Variables to be inserted have to be provided
separated by commas,
after the string in order of appearance in string.
*/
...
...
Session3/Task1/uart.c
View file @
89bc499e
/*
* uart.c
*
* Created: 13.02.2017 04:55:46
* Author: Petter
*/
#include <avr/io.h>
...
...
@@ -6,17 +12,27 @@
#include "uart.h"
void
uart_init
(
u
nsigned
long
baud
){
void
uart_init
(
u
int16_t
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);
...
...
@@ -25,19 +41,26 @@ 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
int
uart_transmit
(
uint8_t
data
,
FILE
*
stream
){
//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
;
}
//Interrupt service routine for receiving
ISR
(
USART
0
_RXC_vect
){
ISR
(
USART
3
_RXC_vect
){
uint8_t
data
=
USART0
.
RXDATAL
;
//We must read the data to clear the interrupt flag
//Here we can do something with data if we would want that
}
\ No newline at end of file
}
Session3/Task1/uart.h
View file @
89bc499e
/*
* uart.h
*
* Created: 27.02.2017 16:51:11
* Author: Petter
*/
#ifndef UART_H_
#define UART_H_
#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
);
//This function initializes the UART module
int
uart_transmit
(
char
data
,
FILE
*
stream
);
//You will be using fprint, which uses this function to send data to terminal
void
uart_init
(
uint16_t
baud
);
#endif
/* UART_H_ */
\ No newline at end of file
int
uart_transmit
(
uint8_t
data
,
FILE
*
stream
);
#endif
/* UART_H_ */
Session3/Task2/display.h
View file @
89bc499e
...
...
@@ -7,7 +7,7 @@
// Below are the public functions that you can use to play with the screen
// Call this method to initialize the screen. This must be done before using any other functions
// Call this method to initialize the screen. This must be done before using any other functions
related to the screen.
void
DISP_init
();
// Call this method to write a bitmap to the screen. The bitmap must be a 32x16(512) array of bytes
...
...
@@ -25,4 +25,4 @@ void DISP_putc(char c);
void
DISP_print
(
const
char
*
str
);
#endif
/* DISPLAY_H_ */
\ No newline at end of file
#endif
/* DISPLAY_H_ */
Session3/Task2/main.c
View file @
89bc499e
...
...
@@ -12,14 +12,14 @@
#include "display.h"
/*
In this exercise you will write a driver for the SPI module. You will connect the OLED
screen to the EXT header
In this exercise you will write a driver for the SPI module. You will connect the OLED
1 Xplained Pro screen to the Xplained Pro Extension header.
and use your SPI driver to write bitmaps and text to the screen.
A finished driver for the screen is provided (display.c), as as a font for it. These build uppon the SPI driver.
You can read display.h to see what functions you can use with the screen.
No help beyond the function headers is provided. To start, it's recommend you:
a) glance over the chapter on SPI in the ATmega4809 datasheet
b) find out what pins of the ATmega the screen is connected to
b) find out what pins of the ATmega
4809
the screen is connected to
*/
...
...
@@ -68,6 +68,6 @@ int main(void)
while
(
1
)
{
//Code also here?
}
}
Session3/Task2/spi.c
View file @
89bc499e
...
...
@@ -12,8 +12,8 @@
void
SPI_MasterInit
()
{
//You should probably write code here
}
...
...
@@ -22,6 +22,7 @@ void SPI_MasterInit()
void
SPI_MasterTransmit
(
char
cData
)
{
//You should probably write code here
}
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