cancel
Showing results for 
Search instead for 
Did you mean: 

SPI and SSB1322

samcharnet
Associate II
Posted on January 24, 2013 at 12:14

Hello,

I try to get a ssb1322 oled display working with a stm32f4 board. The display is NHD-2.8-25664UCY2 from new heaven. The recurrent problem with this display is power, so I power it with an atx 3.3v. I also use freertos, but it just blink a led on port C. For delay, I use timer5. I use last ST lib for hardware spi. With multimeter, all lines seems to ok. I receive an oscilloscope tomorow to check that. Before I want to verify my spi init and using, this is the init (I use different port for SCK and MOSI) :

void prvSPI1_Config()
{
GPIO_InitTypeDef GPIO_InitStructure;
//NVIC_InitTypeDef NVIC_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
/* Peripheral Clock Enable -------------------------------------------------*/
/* Enable the SPI clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
/* Enable GPIO clocks */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB, ENABLE);
////CS (portA, pin 4) et DC (portA, pin 6)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
//GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
//GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
////RESET (portB, pin 6)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//This is SSB1322 reset
GPIO_SetBits(GPIOB, GPIO_Pin_7);
OLED_Delay(300);
////SCK (portA pin 5)
GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);
////MOSI (portB, pin 5)
GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI1);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
//GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
/* SPI SCK pin configuration (portA, pin 5) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* SPI MOSI pin configuration (portB, pin 5)*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* SPI configuration -------------------------------------------------------*/
SPI_I2S_DeInit(SPI1);
//SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32; //72/16 = 4.5 Mhz
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);
}

And this send functions :

u8 SPI_OLED_SendByte(u8 byte)
{
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
// Send byte through the SPI1 peripheral 
SPI_I2S_SendData(SPI1, byte);
}
void oled_Command_25664(unsigned char Data)
{
////CS Low (portA pin 4)
GPIO_ResetBits(GPIOA, GPIO_Pin_4);
/////DC Low (portA pin 6)
GPIO_ResetBits(GPIOA, GPIO_Pin_6);
SPI_OLED_SendByte(Data);
////CS High (portA pin 4)
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);
GPIO_SetBits(GPIOA, GPIO_Pin_4); 
}
void oled_Data_25664(unsigned char Data)
{
////CS Low (portA pin 4)
GPIO_ResetBits(GPIOA, GPIO_Pin_4);
/////DC High (portA pin 6)
GPIO_SetBits(GPIOA, GPIO_Pin_6);
SPI_OLED_SendByte(Data);
////CS High (portA pin 4)
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);
GPIO_SetBits(GPIOA, GPIO_Pin_4);
}

Many help ? I begin with stm32, be indulgent ^^
12 REPLIES 12
Posted on January 24, 2013 at 15:15

It appears roughly OK, except I can't see where do you release the display's reset. Having an oscilloscope or a LA at hand is always a good idea.

JW PS. It's always lots of fun when you lie in the comment and then later reading the code you believe it... 🙂

////RESET (portB, pin 6)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;

samcharnet
Associate II
Posted on January 24, 2013 at 16:08

It's a /RES, so it is active at startup, I set it high to stop reset.

Ps : I never lie 🙂 but you are right, i don't take a risk and correct that !

Posted on January 24, 2013 at 17:34

SSD1322

new haven

If it continues to not work provide a schematic of how YOU have wired it up.

Use a scope or logic analyzer to check signalling and timing.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 24, 2013 at 17:42

> It's a /RES, so it is active at startup, I set it high to stop reset.

It's ''active'' only since you turn it to output, which is immediately before you set it to 1. According to SSD1322 datasheet you need to keep it active for at least 2us.

I doubt this is the root of your problem, but you ought to do it right.

JW

samcharnet
Associate II
Posted on January 25, 2013 at 12:25

I have added a 50ms delay before setting /res

And changed the comment I saw I am not the only one having trouble with this display. This is my oled connector :

1 Gnd
2 +3.3v external (atx 620w)
3 nc
4 DC on port A pin 6
5 - 6 Gnd
7 SCK on port A pin 5 (spi1clk)
8 SDIN on port B pin 5 (spi1mosi)
9 nc
10 - 14 Gnd
15 nc
16 /Res sur port B pin 7
17 /Cs sur port A pin 4
18 nc
19 Gnd (spi 4wires)
20 Gnd (spi 4wires)

I just trying oscilloscope and I have no SCK and CS signal, always low.. I investiguate..
samcharnet
Associate II
Posted on January 25, 2013 at 16:58

And this is screenshot from all pins

SCK seems broken. If i am right, there should be one pulse per bit ?

Reset :

0690X00000602nJQAQ.jpg

CS :

0690X00000602k1QAA.jpg

DC :

0690X00000602nTQAQ.jpg

MOSI :

0690X00000602gUQAQ.jpg

And SCK :

0690X00000602niQAA.jpg

Posted on January 25, 2013 at 18:03

What kind is the scope you used? It would be nice to know the timebase, too.

While the slow rising/falling edges and missing pusles might be the limitation of the scope/probe, it is suspicious. Why are there two pulses on Reset? And why that outrageously slow trailing ''edge''? Some of it might be attributed also to

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

which you should revise; but it's still suspicious. It also appears that you have messed up the pins somehow. While SCK and MOSI should toggle like crazy, CS should pulse once per byte and DC - depending on your code - should be mostly static. JW
samcharnet
Associate II
Posted on January 25, 2013 at 18:52

I use a velleman hps 40 (10Mhz) with rs232 software for screenshot, the timebase is on the top of the picture. In this case : 0.2s, 2V

The double reset is ok, I have pressed twice the button. DC is not static, it take high for sending command and low for sending data I checked again all connexion, it's ok, like the list I have posted before. I just tested the

GPIO_Speed = GPIO_Speed_50MHz

for all gpio, it is the same
samcharnet
Associate II
Posted on January 25, 2013 at 21:38

In fact, I can see SCK pulses at 125ns/div.

The result is crapy but coherent. I will look for a better oscilloscope if I want to check pin synchronisation..

I have tried with a software spi on same pins, the result is the same, the display still black. Can I deduce it is not a spi probleme ?