SPI Driver issue

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
georgecpr
Posts: 2
Joined: Wed Jan 16, 2013 12:57 pm

SPI Driver issue

Post by georgecpr »

Hi All,

I'm using a 7" LCD SSD1963 display with an on-board SPI Flash memory (W25Q16V), SPI Touch Screen controller (XPT2046), and SPI microSD.
The microSD is accessed using the MMC over SPI driver, the TouchScreen uses the driver provided by the Chibios/GFX lib, and the flash driver is implemented by me.

I've tested all these modules separately and they are working ok.
The problem is that I cannot use all 3 at the same time (every one of them has a separate CS). All modules are using the SPI driver from ChibiOS HAL.

Is there a way to configure the SPI driver to access multiple devices on the same SPI bus?

The workaround found was to call spiStart() every time the SPI bus was accessed (I had to modify the MMC over SPI driver for this). This way the spiconfig is set properly before every access.

The spiAcquireBus/spiReleaseBus functions are not helping me in this situation (all 3 modules are accessed from the same thread).

Thanks,
George
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: SPI Driver issue

Post by Giovanni »

Hi,

You can reprogram the SPI on the fly by using spiStart() repeatedly (no need to do spiStop()), doing this is the way it is meant to work so it is not a workaround. Changing the configuration structure alone would not work because there are operations to be done at registers level, spiStart() does exactly that.

If you have changes for the mmc_spi driver in order to support this please submit the patch, I thought it already supported the scenario but I never tested it that way.

Giovanni
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: SPI Driver issue

Post by Tectu »

Just one more thing so that it has been said: It's very not recommended using the touchscreen controller and something like an SD card on the same SPI bus. The SD card needs the highest SPI frequency as possible you can read and write to/from it quickly. But the touchscreen controller must be accessed with the lowest frequency possible to reduce the noise (internal seattling time, SPI generated spikes etc). If you really really need to use them on the same bus, make sure you change the SPI frequency whenever you access the other device.

The noise thing you can test yourself very easily: In your main loop, write simple function which does set a pixel at that position which is touched. Now use the lowest SPI frequency. You'll see that you'll get quite nice results. But as soon as you increase the SPI speed, you get a lot more noise and worse results.


~ Tectu
georgecpr
Posts: 2
Joined: Wed Jan 16, 2013 12:57 pm

Re: SPI Driver issue

Post by georgecpr »

Hi,

Giovanni, thank you for your clarification. I think the documentation regarding the usage of spiStart() can be improved. I've decided to use this function only after I've read the source code. The MMC over SPI works OK in this configuration, with one exception: mmcDisconnect().
A spiStart() must be inserted before calling the sync() function, otherwise the SPI will stop working.

Tectu, each device on the SPI bus has it's own configuration structure and they are using different SPI speeds. The TOUCHSCREEN_SPI_PROLOGUE() macro is calling spiStart(tsDriver->spicfg) which will set the right speed before the SPI communication will begin. Currently I'm using the spicfg provided in the GFX demo. I wanted to increase the communication speed, but thanks to your explanation I'll leave it as it is.

George
Post Reply