Hi there, im trying to use my Micro OLED Sparkfun display (here is the datasheet https://cdn.sparkfun.com/assets/learn_tutorials/3/0/8/SSD1306.pdf) 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.
Code is here
#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>
void SPI_MasterInit(void)
{
/* Set MOSI and SCK output, all others input */
DDRB = (1<<DDB3)|(1<<DDB5)|(1<<DDB1)|(1<<DDB2)|(1<<DDB0);
PORTB |= (1<<PB2);
/* Enable SPI, Master, set clock rate fck/16 */
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
}
void SPI_MasterTransmit_Command(char cCommand)
{
/* Set to command mode pin number 9 */
PORTB &= ~(1<<PB1);
/* Start transmission */
SPDR = cCommand;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));
}
void SPI_MasterTransmit_Data(char cData)
{
/* Set to data mode pin number 9 */
PORTB |=(1<<PB1);
/* Start transmission */
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));
}
void Display_ON(void)
{
PORTB &= ~(1<<PB0);
_delay_us(10);
PORTB |= (1<<PB0);
_delay_us(10);
PORTB &= ~(1<<PB0);
_delay_us(10);
SPI_MasterTransmit_Command(0xAf);
_delay_ms(200);
}
int main(void)
{
/* Replace with your application code */
while (1)
{
SPI_MasterInit();
Display_ON();
SPI_MasterTransmit_Command(0xA5);
}
}
You also seem to have SS designated as pin 9. Is this what you want?
For debugging as well, don't be so hasty in dispensing with all the IDE trappings. Change int main() to void setup(), add an empty void loop() (keep the compiler happy) and initialize Serial.begin(38400) so you have the luxury of debug printing until your issues are sorted. You think you can make these changes?