This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Porting SSD1306 for Oled

I need to port ssd1306 library for oled to nrf51822.

so i tested following code. but it's not worked.

main(){
    if (!twi_master_init())
    {
        return false;
     }
     ssd1306_init();
}
static bool ssd1306_lcd_set_instruction(uint8_t instr)
{
    nrf_delay_us(10000);
    data_buffer[0] = 0x00;
    data_buffer[1] = instr;
    return twi_master_transfer(SSD1306_SA << 1, data_buffer, 2, TWI_ISSUE_STOP);
}
bool ssd1306_init(void)
{
if (!ssd1306_lcd_set_instruction(0xAE)) <- not worked , returns false
    return false;
	if (!ssd1306_lcd_set_instruction(0x00)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0x10)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0x40))
    return false;
	if (!ssd1306_lcd_set_instruction(0x81)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0xCF)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0xA1)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0xC8))
    return false;
	if (!ssd1306_lcd_set_instruction(0xA6))
    return false;
	if (!ssd1306_lcd_set_instruction(0xA8)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0x3F)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0xD3)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0x00)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0xD5)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0x80)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0xD9)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0xF1)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0xDA)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0x12)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0xDB)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0x40)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0x20)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0x02)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0x8D))
    return false;
	if (!ssd1306_lcd_set_instruction(0x14)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0xA4)) 
    return false;
	if (!ssd1306_lcd_set_instruction(0xA6)) 
    return false;

return ssd1306_lcd_set_instruction(0xAF);               
}

Another question. How can I draw screen? Thank you all..

void ssd1306_fillscreen(uint8_t fill_Data)
 {
uint8_t m,n;
for(m=0;m<8;m++)
{
	ssd1306_lcd_set_instruction(0xb0+m);	//page0-page1
	ssd1306_lcd_set_instruction(0x00);		//low column start address
	ssd1306_lcd_set_instruction(0x10);		//high column start address
	
	nrf_delay_us(1000);
	data_buffer[0] = DATA_SET; // 0x40
	twi_master_transfer(SSD1306_SA << 1, data_buffer, 1, TWI_DONT_ISSUE_STOP);
	for(n=0;n<127;n++)
	{
		data_buffer[0] = fill_Data;
		twi_master_transfer(SSD1306_SA << 1, data_buffer, 1, TWI_DONT_ISSUE_STOP);
		//ssd1306_send_byte(fill_Data);
	}
	data_buffer[0] = fill_Data;
	twi_master_transfer(SSD1306_SA << 1, data_buffer, 1, TWI_ISSUE_STOP);
	
	//ssd1306_send_data_stop();
}
 }
Parents
  • What is your SSD1306_SA? 0x3C? I use very similar code and SSD1306 based display and it works well for me, but I use 0x78 directly (the shift might have been already factored in the datasheet, IIRC)

  • In this function:

    return twi_master_transfer(SSD1306_SA << 1, data_buffer, 2, TWI_ISSUE_STOP);
    

    you are shifting the address 1 bit left. In the SSD1306 documentation, the address should be in this form:

    0 1 1 1 1 0 SA0 R/W

    Which is 0x3C shifted one bit left. (As long as SA0 and R/W is 0)

    You can set SSD1306_SA to be 0x3C, or write 0x78 directly like this, as Nenik suggests:

    return twi_master_transfer(0x78, data_buffer, 2, TWI_ISSUE_STOP);
    
Reply
  • In this function:

    return twi_master_transfer(SSD1306_SA << 1, data_buffer, 2, TWI_ISSUE_STOP);
    

    you are shifting the address 1 bit left. In the SSD1306 documentation, the address should be in this form:

    0 1 1 1 1 0 SA0 R/W

    Which is 0x3C shifted one bit left. (As long as SA0 and R/W is 0)

    You can set SSD1306_SA to be 0x3C, or write 0x78 directly like this, as Nenik suggests:

    return twi_master_transfer(0x78, data_buffer, 2, TWI_ISSUE_STOP);
    
Children
No Data
Related