This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

OLED 2864 I2C communication help..

I try to trun on the Display

uint8_t Setting [20] = {0xA8, 0x3F, 0xD3, 0x00, 0x40, 0xA0, 0xA1, 0xC0, 0xC8, 0xDA, 0x02, 0x81, 0x7F, 0xA4, 0xA6, 0xD5, 0x80, 0x8D, 0x14, 0xAF};

int main(void) { nrf_delay_ms(400);

if(twi_master_init()) // twi_master_init
	{
		  for(int i = 0; i<20; i++)
		 {
		       twi_master_transfer(0x3C, &Setting[i],1,true);
			     nrf_delay_us(1000); 
		 }
	 }

} image description image description image description

But still off.

I connected SCL - SCL, SDA-SDA, D/C -GND, CS - Non, Res - Non, VCC - 3.3v(out 3.2xx), GND -GND DS_SSD1306.pdf DS_IM130625003_128x64_OLED_Module.pdf

I don't know how can I do

    • I assume when you write 'Non', you mean not connected. So: Reset (RES) is active high, and ChipSelect (CS) is active low.
    • You need to shift the address 1 bit left, since the address is 7 bits and the last bit is the R/W bit (As written in section 8.1.5.2 in the SSD1306 documentation, R/W bit should be 0 when writing):

    .

    twi_master_transfer( ( 0x3C << 1 ), data, length, stop_condidtion)
    
    • If you look at the TWI data format in figure 8-7 in the SSD1306 documentation, there is a control byte before the data byte, which tells if the data byte is a Command or Data. Further, the flow diagram you included in your post for initializing the display shows it needs a command first and then the data for that command. For example, the first 'Set MUX ratio' command (A8h, 3Fh) would need to be sent like this (maybe):

    .

    DATA1[2] = {0b10000000, 0xA8};
    DATA2[2] = {0b11000000, 0x3F};
    twi_master_transfer( ( 0x3C << 1 ), DATA1, 2, false);
    twi_master_transfer( ( 0x3C << 1 ), DATA2, 2, true);
    

    First the D/C bit is 0 to indicate a command, then a 1 to indicate data. This is just how I think it should be done after reading the datasheet for a few minutes, and it may be wrong. But it's all written in the data sheet.

    Just want to say that the code you wrote will send one byte of data, and then issue a stop condition, regardless of it being a command or not. And it doesn't seem right to me if you read section 8.1.5.1 in the datasheet.

Related