Hiya,
What module are you using? The thoughts below are with regards to the Q2686 and Q2698 modules.
Make sure that the GPIO is
- not used by another module - eg not a GPIO used by the UART as (in the case of the UART) ALL 9 GPIO are used by the UART module even if you’re only using UART 5 wire or 2 wire mode. You can how the UARTs are assigned by using AT+WMFM. If the uart is ‘open’ that means it is under control of the firmware, and all the GPIO are assigned to the UART hardware.
- If the module is Q2686/Q2687 make sure that the GPIO keyboard functionality is not enabled - see AT+WHCNF
- If the GPIO is otherwise used by the Firmware - see AT+WIOM
All that said, from your code you are trying to use GPIO20 (hardware pin 48) as your CS - and my reading of the Q2686 and Q2698 PTS documents indicate that this GPIO is not shared between modules.
I’m also not sure if your Clock speed of 0 is correct - although the ADL guide says that it is. I use the following:
#define PCLK 13000 // Max Clock Freq in kHz)
#define SPICLK 6000 // desired clock freq (in kHz)
// SPI bus subscription data
// SPI2
const adl_busSPISettings_t SpiLcdConfig =
{
(PCLK/(1 + SPICLK)), // SPI bus speed (should be 6000kHz)
ADL_BUS_SPI_CLK_MODE_3, // SPI Bus mode (CLK idle HI, Data read on Rising Edge)
ADL_BUS_SPI_ADDR_CS_GPIO, // Set up chip select pin (use GPIO pin)
ADL_BUS_SPI_CS_POL_LOW, // chip select Active state (LOW)
ADL_BUS_SPI_MSB_FIRST, // data are sent MSB first
ADL_IO_GPIO | 35, // GPIO to use for CS - not applicable for CS_HARD
ADL_BUS_SPI_LOAD_UNUSED, // LOAD Signal
ADL_BUS_SPI_DATA_BIDIR, // DataLinesConf
ADL_BUS_SPI_MASTER_MODE, // Master Node
ADL_BUS_SPI_BUSY_UNUSED // Busy Signal
};
// BUS Handle
s32 SpiLcdHandle = ERROR;
s32 spiOpen( void )
{
u32 maxClock;
// subscribe to SPI bus (SPI2 for LCD)
adl_regGetHWInteger("spi_02_Master_MaxFreqClock", (s32 *)&maxClock);
TRACE (( 1, "spiInit: max SPI Clock [%d] ", maxClock ));
SpiLcdHandle = adl_busSubscribe( ADL_BUS_ID_SPI, 2, (adl_busSettings_u *) &SpiLcdConfig);
TRACE (( 1, "spiInit: SpiLcdHandle [%d] ", SpiLcdHandle ));
return SpiLcdHandle;
}
to set up to talk to a SPI LCD on a Q2686 module.
Just out of interest, can you use GPIO31 (pin 22) as your CS line?
Let us all know how you get on.
ciao, Dave