SPI bus sharing protocol #1569
-
Hi, I was using the protected data members locked and inTransaction in a derived class to follow the same protocol used by the library when accessing the same SPI bus, but now with commit Add filled rectangles with gradient they've been made private. Any recommendations on how to guard access to the bus and play nicely with the library? I didn't get to test yet if anything bad happens if I don't check or set them. And maybe a feature request, I'd like to use a 74HC138 line decoder to get 7 chip selects from 3 pins, or 4 chip selects from 2 pins. I was thinking maybe defining the CS_ macros outside the library would do? Like in platformio.ini. Mainly using ESP32 here, but trying to keep projects compile for other targets too. Thanks for this comprehensive library btw, it's great! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The library supports transactions for multiple SPI users so access to those flags should not be necessary. The flags simply ensure that SPI access requests and releases are always paired, otherwise the ESP32 will crash (though this may be fixed in the board package now). |
Beta Was this translation helpful? Give feedback.
-
Thanks, I'll make sure I don't intersperse SPI calls without pairing them. About the other request, I think I can add 4 additional SPI devices to the bus with just one more GPIO pin with a 74HC138, without any library modifications. For example if the 138 binary selection pins are A2, A1 and A0, and we use A0 as TFT_CS, A1 as TOUCH_CS and A2 for disambiguation, the truth table would be
|
Beta Was this translation helpful? Give feedback.
The library supports transactions for multiple SPI users so access to those flags should not be necessary. The flags simply ensure that SPI access requests and releases are always paired, otherwise the ESP32 will crash (though this may be fixed in the board package now).
The only time that you might have a problem is if you use tft.startWrite() which holds the chip select permanently low, in that case when tft.EndWrite is used then it waits for any ongoing SPI transaction to complete before releasing the chip select.