I am trying to connect the HY28A LCD module, which uses the ILI9320 display driver, to the STM32F discovery board.
However, I cannot get the LCD to draw anything.
I have verified that the SPI pins are sending signals by probing them.
My main.cs and board file are posted below.
Any advice on how to get the display running is appreciated.
main.c
Code: Select all
#include "ch.h"
#include "hal.h"
#include "gfx.h"
/*
* Application entry point.
*/
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
coord_t width, height;
coord_t i, j;
/* Initialize and clear the display */
gfxInit();
/*
sdStart(&SD2, NULL);
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
*/
// Get the screen size
width = gdispGetWidth();
height = gdispGetHeight();
// Code Here
gdispDrawBox(10, 10, width/2, height/2, Yellow);
gdispFillArea(width/2, height/2, width/2-10, height/2-10, Blue);
gdispDrawLine(5, 30, width-50, height-40, Red);
for(i = 5, j = 0; i < width && j < height; i += 7, j += i/20)
gdispDrawPixel (i, j, Blue);
while(TRUE) {
gfxSleepMilliseconds(1000);
}
}
gdisp_lld_board.h
Code: Select all
/**
* @file drivers/gdisp/ILI9320/gdisp_lld_board_example.h
* @brief GDISP Graphic Driver subsystem board interface for the ILI9320 display.
*
* @addtogroup GDISP
* @{
*/
#ifndef GDISP_LLD_BOARD_H
#define GDISP_LLD_BOARD_H
#define SET_RST palSetPad(GPIOB, 8);
#define CLR_RST palClearPad(GPIOB, 8);
// Peripherial Clock 42MHz SPI2 SPI3
// Peripherial Clock 84MHz SPI1 SPI1 SPI2/3
//#define SPI_BaudRatePrescaler_2 ((uint16_t)0x0000) // 42 MHz 21 MHZ
//#define SPI_BaudRatePrescaler_4 ((uint16_t)0x0008) // 21 MHz 10.5 MHz
//#define SPI_BaudRatePrescaler_8 ((uint16_t)0x0010) // 10.5 MHz 5.25 MHz
//#define SPI_BaudRatePrescaler_16 ((uint16_t)0x0018) // 5.25 MHz 2.626 MHz
//#define SPI_BaudRatePrescaler_32 ((uint16_t)0x0020) // 2.626 MHz 1.3125 MHz
//#define SPI_BaudRatePrescaler_64 ((uint16_t)0x0028) // 1.3125 MHz 656.25 KHz
//#define SPI_BaudRatePrescaler_128 ((uint16_t)0x0030) // 656.25 KHz 328.125 KHz
//#define SPI_BaudRatePrescaler_256 ((uint16_t)0x0038) // 328.125 KHz 164.06 KHz
/*
*
* 10.5MHz, CPHA=1, CPOL=0, MSb first, 16 - bits
*
*/
static const SPIConfig spi2cfg1 = {
NULL,
/* HW dependent part.*/
GPIOB,
12,
SPI_CR1_DFF | SPI_CR1_CPHA | SPI_CR1_BR_0
};
static inline void gdisp_lld_init_board(void) {
palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* New SCK. */
palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* New MISO. */
palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* New MOSI. */
palSetPadMode(GPIOB, 12, PAL_MODE_OUTPUT_PUSHPULL |
PAL_STM32_OSPEED_HIGHEST); /* New CS. */
palSetPad(GPIOB, 12);
palSetPad(GPIOB, 8);
spiStart(&SPID2, &spi2cfg1);
}
static inline void gdisp_lld_reset_pin(bool_t state) {
if (state) {
palClearPad(GPIOB, 8);
} else {
palSetPad(GPIOB, 8);
}
}
static inline void acquire_bus(void) {
spiAcquireBus(&SPID2);
}
static inline void release_bus(void) {
spiReleaseBus(&SPID2);
}
static inline void gdisp_lld_write_index(uint16_t data) {
palClearPad(GPIOB, 12);
static uint16_t txbuf[1] = {0};
//txbuf[0] = 0x70 | 0x00 | 0x00;
txbuf[0] = data;
//txbuf[0] = data >> 8;
//txbuf[1] = data & 0xFF;
while((SPI2->SR & SPI_SR_TXE) == 0);
spiSend(&SPID2, 1, txbuf);
while(((SPI2->SR & SPI_SR_TXE) == 0) || ((SPI2->SR & SPI_SR_BSY) != 0));
palSetPad(GPIOB, 12);
}
static inline void gdisp_lld_write_data(uint16_t data) {
palClearPad(GPIOB, 12);
static uint8_t txbuf[2] = {0};
//txbuf[0] = data;
//txbuf[0] = 0x70 | 0x00 | 0x02;
txbuf[0] = (data >> 8);
txbuf[1] = (data & 0xFF);
spiSend(&SPID2, 2, txbuf);
while(((SPI2->SR & SPI_SR_TXE) == 0) || ((SPI2->SR & SPI_SR_BSY) != 0));
palSetPad(GPIOB, 12);
}
static inline uint16_t gdisp_lld_read_data(void) {
palClearPad(GPIOB, 12);
//while((SPI2->SR & SPI_SR_TXE) == 0);
//static uint8_t txbuf[1] = {0};
//txbuf[0] = 0x70 | 0x01 | 0x02;
//spiSend(&SPID2, 1, txbuf);
while(((SPI2->SR & SPI_SR_TXE) == 0) || ((SPI2->SR & SPI_SR_BSY) != 0));
static uint8_t rxbuf[2] = {0};
spiReceive(&SPID2, 2, rxbuf);
while(((SPI2->SR & SPI_SR_TXE) == 0) || ((SPI2->SR & SPI_SR_BSY) != 0));
palSetPad(GPIOB, 12);
static uint16_t value = 0;
value = rxbuf[0] << 8 | rxbuf[1];
//test_println((char*)value);
return value;
}
/* if not available, just ignore the argument and return */
static inline uint16_t gdisp_lld_backlight(uint8_t percentage) {
//pwmEnableChannel(&PWMD4, 1, percentage);
}
#endif /* GDISP_LLD_BOARD_H */
/** @} */
Thanks,
David