Hello Guys,
I'm developping and st7789 IPS screen driver and i'm having problem with SPI0 . I'm using NRF52840 DK 2.0.1
First I took SPI example from sdk 17.0.2 configured it to Eclipse IDE .
Tested the example is working.
Reworked the spi example for my need like this
static void ST7789_HwInit(void){
/* Configure DCX and RST PIN as output */
nrf_gpio_cfg_output(LLDISPLAY_RST_PIN);
nrf_gpio_cfg_output(LLDISPLAY_DCX_PIN);
/* Set DCX and RST PIN accoridng to ST7789 datasheet */
nrf_gpio_pin_clear(LLDISPLAY_RST_PIN);
nrf_gpio_pin_set(LLDISPLAY_DCX_PIN);
/* Configure SPI instance with 1MHZ and Mode0 */
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.mosi_pin = LLDISPLAY_MOSI_PIN;
spi_config.sck_pin = LLDISPLAY_SCK_PIN;
spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
spi_config.mode = NRF_DRV_SPI_MODE_0;
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));
}
Here's the end of transmission event handler :
void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
void * p_context)
{
spi_xfer_done = true;
}
Here's the functions I use for data/command sending :
/**
* @brief Write command to ST7789 controller
* @param cmd -> command to write
* @param buff -> pointer of data buffer
* @param buff_size -> size of the data buffer
* @return none
*/
static void ST7789_WriteFullCommand(uint8_t cmd, uint8_t const * pData, uint8_t dataLength)
{
nrf_gpio_pin_clear(LLDISPLAY_DCX_PIN);
spi_xfer_done = false;
nrf_drv_spi_transfer(&spi, &cmd, 1, NULL, 0);
while (!spi_xfer_done)
{
__WFE();
}
nrf_gpio_pin_set(LLDISPLAY_DCX_PIN);
spi_xfer_done = false;
nrf_drv_spi_transfer(&spi, pData, dataLength, NULL, 0);
while (!spi_xfer_done)
{
__WFE();
}
}
/**
* @brief Write data to ST7789 controller
* @param buff -> pointer of data buffer
* @param buff_size -> size of the data buffer
* @return none
*/
static void ST7789_WriteData(uint8_t *buff, size_t buff_size)
{
nrf_gpio_pin_set(LLDISPLAY_DCX_PIN);
spi_xfer_done = false;
nrf_drv_spi_transfer(&spi, buff, buff_size, NULL, 0);
while (!spi_xfer_done)
{
__WFE();
}
}
The pin definition are
#define LLDISPLAY_SCK_PIN 3
#define LLDISPLAY_MOSI_PIN 4
#define LLDISPLAY_DCX_PIN 29
#define LLDISPLAY_RST_PIN 30
So my code compiles well and I do receive a buffer which contains some corrupted bytes. For exapmle, in the initialisation sequence somewhere in the middle i send " ....0xB6 0x0A 0x82 0x3A 0x55...." how ever what i do receive in the logic analyser is " ....0xB6 0x0A 0x82 0x22 0x05...." with corrupted clock cycle(see the picture)