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
54e2f77a
Commit
54e2f77a
authored
Mar 15, 2017
by
Petter Breedveld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update to spi
parent
db5590dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
11 deletions
+51
-11
Debugger_Demo/Debugger_Demo/main.c
Debugger_Demo/Debugger_Demo/main.c
+43
-1
Session3-LF/Task1_LF/Task1_LF/uart.c
Session3-LF/Task1_LF/Task1_LF/uart.c
+0
-1
Session3-LF/Task2_LF/Task2_LF/spi.c
Session3-LF/Task2_LF/Task2_LF/spi.c
+8
-9
No files found.
Debugger_Demo/Debugger_Demo/main.c
View file @
54e2f77a
...
...
@@ -3,12 +3,54 @@
*
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
#define F_CPU 3333333UL
#define BAUD_9600 ((4UL*F_CPU)/9600)
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
return
0
;
}
void
uart_init
(
unsigned
long
baud
){
PORTB
.
OUTSET
|=
(
1
<<
PIN2_bp
);
PORTB
.
DIRSET
|=
(
1
<<
PIN2_bp
);
USART0
.
BAUD
=
baud
;
//Set baudrate
USART0
.
CTRLB
|=
(
1
<<
USART_RXEN_bp
)
|
(
1
<<
USART_TXEN_bp
);
//Enable RX and TX
USART0
.
CTRLA
|=
(
1
<<
USART_RXCIE_bp
);
//Enable interupts on RX
fdevopen
(
uart_transmit
,
NULL
);
//Allows the use of printf()
}
ISR
(
USART0_RXC_vect
){
uint8_t
data
=
USART0
.
RXDATAL
;
//We must read the data to clear the interrupt flag
}
int
main
(
void
)
{
/* Replace with your application code */
uart_init
(
BAUD_9600
);
while
(
1
)
{
...
...
Session3-LF/Task1_LF/Task1_LF/uart.c
View file @
54e2f77a
...
...
@@ -5,7 +5,6 @@
* Author: Petter
*/
#define F_CPU 3333333UL
#include <avr/io.h>
#include <avr/interrupt.h>
...
...
Session3-LF/Task2_LF/Task2_LF/spi.c
View file @
54e2f77a
...
...
@@ -17,13 +17,12 @@
// RTFD
//Oled is connected to alternate SPI pins
#define MOSI_
BIT
2 //on port C
#define SCK_
BIT
0 //on port C
#define SS_
BIT
3 //on port C
#define MOSI_
bm 1<<
2 //on port C
#define SCK_
bm 1<<
0 //on port C
#define SS_
bm 1<<
3 //on port C
#define SPI_PORT PORTC //We can now use SPI_PORT.DIR, .OUT etc.
//We could also have defined bit masks for MOSI, SCL and SS.
//Then we wouldn't have to shift them all the time
//We could also have defined bit positions for MOSI, SCL and SS.
...
...
@@ -34,9 +33,9 @@ void SPI_MasterInit()
PORTMUX
.
CTRLB
|=
PORTMUX_SPI0_bm
;
//To use alternative SPI pins
SPI_PORT
.
DIR
|=
(
1
<<
MOSI_BIT
)
|
(
1
<<
SCK_BIT
)
|
(
1
<<
SS_BIT
)
;
//Set pins as output
SPI_PORT
.
DIR
|=
MOSI_bm
|
SCK_bm
|
SS_bm
;
//Set pins as output
SPI_PORT
.
OUTSET
=
(
1
<<
SS_BIT
)
;
//Set SS high -> OLED inactive
SPI_PORT
.
OUTSET
=
SS_bm
;
//Set SS high -> OLED inactive
// Now enable SPI, Master and set clock rate
...
...
@@ -53,7 +52,7 @@ void SPI_MasterInit()
void
SPI_MasterTransmit
(
char
cData
)
{
// First select the correct slave by setting its slave select (SS) LOW
PORTC
.
OUTCLR
=
(
1
<<
SS_BIT
)
;
SPI_PORT
.
OUTCLR
=
SS_bm
;
// Then start the transmission by assigning the data to the SPI data register
SPI0
.
DATA
=
cData
;
...
...
@@ -66,5 +65,5 @@ void SPI_MasterTransmit(char cData)
SPI0
.
DATA
;
//Dummy read to clear flag
// Finally set the slave select bit HIGH before leaving the function
PORTC
.
OUTSET
=
(
1
<<
SS_BIT
)
;
SPI_PORT
.
OUTSET
=
SS_bm
;
}
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