Posted on October 20, 2013 at 04:11Hi all,
I'm at my wit's end with this little project I'm working on. I'm new to MCUs and had a few ideas on small projects that I would like to make. I've been following a guide on the STM32 and modifying bits and pieces to get it working with my particular board (STM32F4Discovery). As part of every project I would like to utilize an LCD for status output so that's where I've started to learn all things MCU. I bought a tiny LCD screen... a ''Mini 1.8'' Serial SPI TFT LCD Module Display with PCB Adapter ST7735B IC'' to be exact but I can't for the life of me understand how to get it working. I started by first learning SPI with a simple loopback setup and watched the results on my Open Bench Logic Analyzer. It was straight forward and worked without too much pain. I then applied that knowledge to getting the LCD working and I've got myself in a tangle.
Here's some observations I've made:
- My logic analyzer has crapped itself.... it no longer works. It gets pretty hot and doesn't capture any signals.. 50% of the time it just locks up and I need to reboot my machine before it releases the COM port. I'm essentially dead in the water without it. I can no longer verify I have setup clocks correctly or if my chip select is actually working. Without knowing everything has been setup correctly I can't really begin to debug my LCD and the commands I send it. Is there an alternative to this or do I just bin it and buy something better?<br/>
- The LCD is horrible confusing when it comes to pin assignments. It says it uses SPI in the title but the pins on the back say ''CS, SCK, AO, SDA''. From googling around I managed to find out SDA is MOSI and AO is MISO. However, that makes absolutely no sense at all when it comes to sample code. From what I can gather, AO is used to tell the LCD driver if there's data about to arrive or a control message. Pseudo code would be something like:
<pre>
Set_AO_Pin(LOW) // Command
SPI_Write(LCD_ON_CMD)
Set_AO_Pin(LOW) // Command
SPI_Write(LCD_Write_Pixel_1)
Set_AO_Ping(HIGH) // Data
SPI_Write(RED_COLOR)
</pre>
In this example, AO is not even remotely like MISO is it? The data sheet says you send and receive on SDA which confuses the crap out of me.
- Given point 2. Here's my GPIO setup code:
<code>
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_SDA | GPIO_Pin_SCK; // MOSI and SCK
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_CS | GPIO_Pin_AO; // Chip Select and AO
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
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);
// Does GPIO_Pin_CS or GPIO_Pin_AO need to be mapped here?
GPIO_PinAFConfig(GPIOA, GPIO_Pin_SDA , GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOA, GPIO_Pin_SCK, GPIO_AF_SPI1);
</code>
This code is a little different from a typical SPI setup. The MISO pin is missing and instead there's GPIO_Pin_AO is setup the opposite way a MISO pin is. When I call my SPI initialization code, will it barf because there's a missing MOSI pin? Or will it just ignore it and assume it won't be needed?
And finally, my delay method which uses SysTick_Config(SystemCoreClock / 1000) and increments a variable every time SysTick_Handler is executed doesn't seem to be giving me milliseconds at all. My best guess is it's roughly double or possibly even triple the time. Eg. delay(1000) is 2 or 3 seconds.
Hope I've explained myself and someone can help.
Thanks