Commit 55bcbee3 authored by Petter Breedveld's avatar Petter Breedveld

OLED fix

OLD now working again. EXT header can be selected through a define in spi.h
parent f0484545
<?xml version="1.0" encoding="utf-8"?>
<Store xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="AtmelPackComponentManagement">
<ProjectComponents>
<ProjectComponent z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<CApiVersion></CApiVersion>
<CBundle></CBundle>
<CClass>Device</CClass>
<CGroup>Startup</CGroup>
<CSub></CSub>
<CVariant></CVariant>
<CVendor>Atmel</CVendor>
<CVersion>1.1.0</CVersion>
<DefaultRepoPath>D:/Atmel\7.0\Packs</DefaultRepoPath>
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<Description></Description>
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\include</AbsolutePath>
<Attribute></Attribute>
<Category>include</Category>
<Condition>C</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>include</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\include\avr\iotn817.h</AbsolutePath>
<Attribute></Attribute>
<Category>header</Category>
<Condition>C</Condition>
<FileContentHash>GzsE/dwQAz37AkZENa/sHg==</FileContentHash>
<FileVersion></FileVersion>
<Name>include/avr/iotn817.h</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\templates\main.c</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>RtJJIrracgoBJUhAmsGN5g==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.c</Name>
<SelectString>Main file (.c)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\templates\main.cpp</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>YXFphlh0CtZJU+ebktABgQ==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.cpp</Name>
<SelectString>Main file (.cpp)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\gcc\dev\attiny817</AbsolutePath>
<Attribute></Attribute>
<Category>libraryPrefix</Category>
<Condition>GCC</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>gcc/dev/attiny817</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
</Files>
<PackName>ATtiny_DFP</PackName>
<PackPath>D:/Atmel/7.0/Packs/atmel/ATtiny_DFP/1.1.102/Atmel.ATtiny_DFP.pdsc</PackPath>
<PackVersion>1.1.102</PackVersion>
<PresentInProject>true</PresentInProject>
<ReferenceConditionId>ATtiny817</ReferenceConditionId>
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string></d4p1:string>
</RteComponents>
<Status>Resolved</Status>
<VersionMode>Fixed</VersionMode>
<IsComponentInAtProject>true</IsComponentInAtProject>
</ProjectComponent>
</ProjectComponents>
<?xml version="1.0" encoding="utf-8"?>
<Store xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="AtmelPackComponentManagement">
<ProjectComponents>
<ProjectComponent z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<CApiVersion></CApiVersion>
<CBundle></CBundle>
<CClass>Device</CClass>
<CGroup>Startup</CGroup>
<CSub></CSub>
<CVariant></CVariant>
<CVendor>Atmel</CVendor>
<CVersion>1.1.0</CVersion>
<DefaultRepoPath>D:/Atmel\7.0\Packs</DefaultRepoPath>
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<Description></Description>
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\include</AbsolutePath>
<Attribute></Attribute>
<Category>include</Category>
<Condition>C</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>include</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\include\avr\iotn817.h</AbsolutePath>
<Attribute></Attribute>
<Category>header</Category>
<Condition>C</Condition>
<FileContentHash>GzsE/dwQAz37AkZENa/sHg==</FileContentHash>
<FileVersion></FileVersion>
<Name>include/avr/iotn817.h</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\templates\main.c</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>RtJJIrracgoBJUhAmsGN5g==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.c</Name>
<SelectString>Main file (.c)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\templates\main.cpp</AbsolutePath>
<Attribute>template</Attribute>
<Category>source</Category>
<Condition>C Exe</Condition>
<FileContentHash>YXFphlh0CtZJU+ebktABgQ==</FileContentHash>
<FileVersion></FileVersion>
<Name>templates/main.cpp</Name>
<SelectString>Main file (.cpp)</SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
<d4p1:anyType i:type="FileInfo">
<AbsolutePath>D:/Atmel\7.0\Packs\atmel\ATtiny_DFP\1.1.102\gcc\dev\attiny817</AbsolutePath>
<Attribute></Attribute>
<Category>libraryPrefix</Category>
<Condition>GCC</Condition>
<FileContentHash i:nil="true" />
<FileVersion></FileVersion>
<Name>gcc/dev/attiny817</Name>
<SelectString></SelectString>
<SourcePath></SourcePath>
</d4p1:anyType>
</Files>
<PackName>ATtiny_DFP</PackName>
<PackPath>D:/Atmel/7.0/Packs/atmel/ATtiny_DFP/1.1.102/Atmel.ATtiny_DFP.pdsc</PackPath>
<PackVersion>1.1.102</PackVersion>
<PresentInProject>true</PresentInProject>
<ReferenceConditionId>ATtiny817</ReferenceConditionId>
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string></d4p1:string>
</RteComponents>
<Status>Resolved</Status>
<VersionMode>Fixed</VersionMode>
<IsComponentInAtProject>true</IsComponentInAtProject>
</ProjectComponent>
</ProjectComponents>
</Store>
\ No newline at end of file
......@@ -4,14 +4,6 @@
#define F_CPU 3333333UL
#define DSP_MODE_bm 1<<5
#define DSP_MODE_PORT PORTC
#define DSP_RST_bm 1<<5
#define DSP_RST_PORT PORTB
// System headers
#include <avr/io.h>
#include <util/delay.h>
......@@ -23,6 +15,27 @@
#include "font8x8.h"
//From spi.h:
#ifndef EXT3 // for using EXT1 header:
#define DSP_MODE_bm (1 << 7)
#define DSP_MODE_PORT PORTB
#define DSP_RST_bm (1 << 4)
#define DSP_RST_PORT PORTA
#else //For using EXT3 header:
#define DSP_MODE_bm (1 << 5)
#define DSP_MODE_PORT PORTC
#define DSP_RST_bm (1 << 5)
#define DSP_RST_PORT PORTB
#endif /* EXT3 */
// This file contains a simple driver for the display so that one can print characters and strings.
// You shouldn't need to do anything in this file for things to work.
// Of course, you're welcome to check it out if you want to see how things work under the hood.
......
......@@ -11,20 +11,6 @@
#include "display.h"
/*
In this exercise you will write a driver for the SPI module. You will connect the OLED screen to the EXT3 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 ATtiny817 datasheet
b) find out what pins of the ATtiny the screen is connected to
*/
const uint8_t bitmap[512] PROGMEM =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
......@@ -64,14 +50,16 @@ const uint8_t bitmap[512] PROGMEM =
int main(void)
{
// The EXT header can be selected though a define in spi.h
DISP_init();
DISP_write_bitmap(bitmap); //Printing Bitmap
//DISP_print("Hello World!"); //Printing text
while (1)
{
}
}
......@@ -9,17 +9,30 @@
// Project headers
#include "spi.h"
// In this file, you will need to write the contents of the SPI communication routines.
// You need to setup SPI communication in SPI_MasterInit() and
// transmit data in SPI_MasterTransmit(...).
//
// HINT: Check out the defines in the file defines.h to see defines
// such as data direction registers and bit positions, and as always:
// RTFD
//Oled is connected to alternate SPI pins
#define MOSI_bm 1<<2 //on port C
#define SCK_bm 1<<0 //on port C
#define SS_bm 1<<3 //on port A
#define SPI_PORT PORTC //We can now use SPI_PORT.DIR, .OUT etc.
#define SS_PORT PORTA //SS is on a different port
#define MOSI_bm (1 << 2) //on port C
#define SCK_bm (1 << 0) //on port C
#define SPI_PORT PORTC //
//We could also have defined bit positions for MOSI, SCL and SS.
#ifndef EXT3 // for using EXT1 header:
#define SS_bm (1 << 3)
#define SS_PORT PORTC
#else // for using EXT3 header:
#define SS_bm (1 << 3)
#define SS_PORT PORTA
#endif /* EXT3 */
void SPI_MasterInit()
......@@ -27,42 +40,38 @@ void SPI_MasterInit()
// Initialize the SPI port as master
// You will need to set MOSI, SCK, SS (slave select) as outputs
//Connect OLED to EXT3
PORTMUX.CTRLB |= PORTMUX_SPI0_bm; //To use alternative SPI pins
PORTMUX.CTRLB |= (PORTMUX_SPI0_bm); //To use alternative SPI pins
SPI_PORT.DIR |= MOSI_bm | SCK_bm; //Set pins as output
SS_PORT.DIR |= SS_bm;
SPI_PORT.DIRSET = (MOSI_bm) | (SCK_bm); //Set pins as output
SS_PORT.DIRSET = (SS_bm);
SS_PORT.OUTSET = SS_bm; //Set SS high -> OLED inactive
SS_PORT.OUTSET = (SS_bm); //Set SS high -> OLED inactive
// Now enable SPI, Master and set clock rate
SPI0.CTRLA |= SPI_ENABLE_bm | SPI_MASTER_bm; //Default clock divisor of 4 is fine
SPI0.CTRLA |= (SPI_ENABLE_bm) | (SPI_MASTER_bm); //Default clock divisor of 4 is fine
//Make sure SS does not disable master mode (Possibly not required)
SPI0.CTRLB |= SPI_SSD_bm;
//Make sure SS does not disable master mode
SPI0.CTRLB |= (SPI_SSD_bm);
}
void SPI_MasterTransmit(char cData)
{
// First select the correct slave by setting its slave select (SS) LOW
SS_PORT.OUTCLR = SS_bm;
// First select the correct slave by setting the slave select (SS) bit LOW
SS_PORT.OUTCLR = (SS_bm);
// Then start the transmission by assigning the data to the SPI data register
SPI0.DATA = cData;
// Now wait for the data transmission to complete by periodically checking the SPI status register
//the SPI_IF and SPI_WRCOL is the only interrupt flag with a function in non-buffered mode.
while(!(SPI0.INTFLAGS & SPI_IF_bm)){
}
//the SPI_IF is the only interupt flag with a function in non-buffered mode.
while(!(SPI0.INTFLAGS & (SPI_IF_bm)));
SPI0.DATA; //Dummy read to clear flag
// Finally set the slave select bit HIGH before leaving the function
SS_PORT.OUTSET = SS_bm;
SS_PORT.OUTSET = (SS_bm);
}
......@@ -9,6 +9,11 @@
#ifndef SPI_H_
#define SPI_H_
/*SPI and OLED will use EXT1 default, uncomment to use EXT3:
This define is used by spi.c and display.c to select the correct pins */
#define EXT3
// Function for initializing SPI
void SPI_MasterInit(void);
......
......@@ -4,14 +4,6 @@
#define F_CPU 3333333UL
#define DSP_MODE_bm 1<<7
#define DSP_MODE_PORT PORTB
#define DSP_RST_bm 1<<4
#define DSP_RST_PORT PORTA
// System headers
#include <avr/io.h>
#include <util/delay.h>
......@@ -23,6 +15,27 @@
#include "font8x8.h"
//From spi.h:
#ifndef EXT3 // for using EXT1 header:
#define DSP_MODE_bm (1 << 7)
#define DSP_MODE_PORT PORTB
#define DSP_RST_bm (1 << 4)
#define DSP_RST_PORT PORTA
#else //For using EXT3 header:
#define DSP_MODE_bm (1 << 5)
#define DSP_MODE_PORT PORTC
#define DSP_RST_bm (1 << 5)
#define DSP_RST_PORT PORTB
#endif /* EXT3 */
// This file contains a simple driver for the display so that one can print characters and strings.
// You shouldn't need to do anything in this file for things to work.
// Of course, you're welcome to check it out if you want to see how things work under the hood.
......
......@@ -9,10 +9,15 @@
#ifndef SPI_H_
#define SPI_H_
/*SPI and OLED will use EXT1 default, uncomment to use EXT3:
This define is used by spi.c and display.c to select the correct pins */
#define EXT3
// Function for initializing SPI
void SPI_MasterInit(void);
// Function for transmitting one byte of SPI data
// Function for transmitting SPI data
void SPI_MasterTransmit(char cData);
......
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