im trying to use my Micro OLED Sparkfun display (here is the datasheet enter link description here) but i have a problem about code. Maybe is the problem in code because im working first time with SPI in Atmel so if would be somebody so nice and check it out, give me some advices about i will be so thankful.
EDIT: Here is the changed code and picture of display wires
#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>
#define SCK DDB5
#define SDIN DDB3
#define D_C DDB0
#define CS DDB2
#define RST DDB1
void SPI_MasterInit(void)
{
/* Set MOSI and SCK output, all others input */
DDRB = (1<<SCK)|(1<<SDIN)|(1<<D_C)|(1<<CS)|(1<<RST);
/* Enable SPI, Master, set clock rate fck/16 */
PORTB |= (1<<CS);
PORTB |= (1<<D_C);
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0)|(0<<DORD);
}
void SPI_MasterTransmit_Command(int cCommand)
{
PORTB &= ~(1<<CS);
PORTB &= ~(1<<D_C);
_delay_ms(200);
/* Start transmission */
SPDR = cCommand;
/* set dc and cs low to send command */
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));
/* set dc cs high again */
PORTB |= (1<<CS);
PORTB |= (1<<D_C);
}
void Display_ON(void)
{
PORTB &= ~(1<<RST);
_delay_ms(50);
PORTB |= (1<<RST);
_delay_ms(50);
PORTB &= ~(1<<RST);
_delay_ms(50);
SPI_MasterTransmit_Command(0xAF);
_delay_ms(200);
}
int main(void)
{
SPI_MasterInit();
Display_ON();
SPI_MasterTransmit_Command(0xA5);
}