Commit 89bc499e authored by siguhe's avatar siguhe

Meurd and Yoolando read trough session3 tasks and fixed some things

parent 1436e0a1
......@@ -5,6 +5,6 @@
void adc_init(void); //This function initialezes the ADC module
uint8_t adc_read(uint8_t channel); //THis function takes in a channel and returns the result of the ADC measurement of the channel
uint8_t adc_read(uint8_t channel); //This 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_ */
......@@ -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 the board to the EXT1 Header of the ATmega4809
You will use this to read the light sensor on the IO1 Xplained Pro board.
Connect this 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 USART.
A complete and working USART 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 USART we need interrupts enabled.
//NOTE: USART 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.
*/
......
/*
* 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(unsigned long baud){
void uart_init(uint16_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(USART0_RXC_vect){
ISR(USART3_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
}
/*
* 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_ */
......@@ -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_ */
......@@ -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 OLED1 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 ATmega4809 the screen is connected to
*/
......@@ -68,6 +68,6 @@ int main(void)
while (1)
{
//Code also here?
}
}
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment