Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ST7920: SW SPI does not work, 2ND HW SPI requested #767

Closed
olikraus opened this issue Dec 20, 2018 · 27 comments
Closed

ST7920: SW SPI does not work, 2ND HW SPI requested #767

olikraus opened this issue Dec 20, 2018 · 27 comments
Milestone

Comments

@olikraus
Copy link
Owner

is it possible to use the second SPI interface for the ST7920? Combined with the mySensors library I can't use the first SPI. The u8g2lib with the STM32F103C8T6 and first hardware SPI without mySensor library works very good, the software spi doesn't work for me I don't know why.

Best regards

Elmar Faber

Originally posted by @elmarfaber in #244 (comment)

@olikraus
Copy link
Owner Author

olikraus commented Dec 20, 2018

yes, can be done, but this is probably a bigger effort. I would need some time for this.

Todo:
Add new interface for ST7920 in codebuild.c:1754

I am confused, that the SW SPI interface doesn't work (is this related to #749) --> needs to be checked.

@olikraus olikraus added this to the 2.25 milestone Dec 20, 2018
@elmarfaber
Copy link

Hello,

it would be nice if you can do this, thank you very much

Best regards

@olikraus olikraus changed the title Dear Olikraus, ST7920: SW SPI does not work, 2ND HW SPI requested Dec 20, 2018
@olikraus
Copy link
Owner Author

The new constructor includes 2ND: U8G2_ST7920_128X64_1_2ND_HW_SPI and is available for 1, 2 and F constructors.

All new constructors are listed here:
https://github.com/olikraus/u8g2/wiki/u8g2setupcpp#st7920-128x64

olikraus added a commit that referenced this issue Dec 21, 2018
@olikraus
Copy link
Owner Author

I have created beta release 2.25.2

You can download the latest U8g2 beta release from here: https://github.com/olikraus/U8g2_Arduino/archive/master.zip

  1. Remove the existing U8g2_Arduino library (https://stackoverflow.com/questions/16752806/how-do-i-remove-a-library-from-the-arduino-environment)
  2. Install the U8g2_Arduino Zip file via Arduino IDE, add zip library menu (https://www.arduino.cc/en/Guide/Libraries).

@elmarfaber
Copy link

Hello,
first, I want to thank you for the great help. I try the beta release under PlatformIO (Visual Studio Code), platform = ststm32, board = genericSTM32F103C8 and the framework = arduino. The board is a bluepill. With SPI1 it works fine but with SPI2 (PB13 - SCK, PB15 - MOSI) it doesn't work.

Best regards

@olikraus
Copy link
Owner Author

which constructor did you use? How does it look like?

@elmarfaber
Copy link

elmarfaber commented Dec 22, 2018

#define displ_cs PA4
U8G2_ST7920_128X64_F_2ND_HW_SPI u8g2(U8G2_R0, displ_cs);

@olikraus
Copy link
Owner Author

From my perspective it is difficult why this doesn't work. There could be several reasons.

One important point is this: Your board files must define SPI_INTERFACES_COUNT (see here for example the mkrzero: https://github.com/arduino/ArduinoCore-samd/blob/master/variants/mkrzero/variant.h#L91).
U8g2 will check for this flag and will create a proper 2ND interface if this flag is 2 or higher.

@elmarfaber
Copy link

The variant.h is a little bit smaller then the sample above:

#ifndef VARIANT_ARDUINO_STM32
#define VARIANT_ARDUINO_STM32

#define digitalPinToPort(P) ( PIN_MAP[P].gpio_device )
#define digitalPinToBitMask(P) ( BIT(PIN_MAP[P].gpio_bit) )
#define portOutputRegister(port) ( &(port->regs->ODR) )
#define portInputRegister(port) ( &(port->regs->IDR) )

#define portSetRegister(pin) ( &(PIN_MAP[pin].gpio_device->regs->BSRR) )
#define portClearRegister(pin) ( &(PIN_MAP[pin].gpio_device->regs->BRR) )

#define portConfigRegister(pin) ( &(PIN_MAP[pin].gpio_device->regs->CRL) )

static const uint8_t SS = BOARD_SPI1_NSS_PIN;
static const uint8_t SS1 = BOARD_SPI2_NSS_PIN;
static const uint8_t MOSI = BOARD_SPI1_MOSI_PIN;
static const uint8_t MISO = BOARD_SPI1_MISO_PIN;
static const uint8_t SCK = BOARD_SPI1_SCK_PIN;

#endif /* VARIANT_ARDUINO_STM32 */

So it wouldn't work for me

@olikraus
Copy link
Owner Author

Hmm... Guess, this needs to be requested from the STM32 Arduino people

@elmarfaber
Copy link

So I found another possibility, in version 4.5 of the platform "ST STM32" there was a function to change the SPI interface. With SPI.setModule(2); I could change the interface to SPI 2 and then then constructor
U8G2_ST7920_128X64_F_HW_SPI u8g2(U8G2_R0, displ_cs); works fine on the second SPI. With the mySensor it doesn't work but with a SDCard on SPI1 it works fine. Thank you very much for this great library and your help. I hope the work for the new function was not in vain and helps others!

olikraus added a commit that referenced this issue Jan 23, 2019
@XNinety9
Copy link

XNinety9 commented Jan 24, 2019

I have the very same problem using an ST7920 and MCP41010. ST7920 alone is ok, MCPs alone is ok too, but both results is one of them not working at all.

See #794

Edit: I just closed #794 , beta 2.25.2 works just fine, using this constructor:

U8G2_ST7920_128X64_2_HW_SPI u8g2(U8G2_R0, 30, U8X8_PIN_NONE);

Thanks a lots @elmarfaber for bringing up the issue and to @olikraus for the quick response. Without it I would have faces a lots of issues and certainly would have to source another display for my project. Kudos!!

@olikraus
Copy link
Owner Author

:)

@olikraus olikraus closed this as completed Feb 9, 2019
@Andy2No
Copy link

Andy2No commented Sep 8, 2019

All new constructors are listed here:
https://github.com/olikraus/u8g2/wiki/u8g2setupcpp#st7920-128x64

Thanks. Please update the page linked to by the library example "hello world" program, which gives this link in a comment for choosing the constructor:

The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8x8setupcpp

The ST7920 does not seem to be on that list so it's taken me a while to find the correct information.

@olikraus
Copy link
Owner Author

olikraus commented Sep 8, 2019

Not clear what you mean...

library example "hello world" program

Which example do you mean? There are many...

The ST7920 does not seem to be on that list

Yes, u8x8 is not available for ST7920

@Andy2No
Copy link

Andy2No commented Sep 8, 2019

Okay. I guess there must be more than one library, and I have installed the wrong one, in that case.

I'm still baffled, but I'm sure I'll work it out eventually.

@logiclayer
Copy link

Hardware and Software communication has a big performance difference on ST7920 chip and LCD ?

@olikraus
Copy link
Owner Author

yes

@logiclayer
Copy link

logiclayer commented Jan 10, 2020

I've created my own XBM icons for segment digits. It looks like it shows a bit slow via SW mode. But I could not make it work via HW interface. That's my constructor. How can I make it work ? (I'm using SPI2)
u8g2_Setup_st7920_s_128x64_f(&u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8g2_gpio_and_delay_stm32);

@olikraus
Copy link
Owner Author

Which board do you use? It does not look like an Arduino Environment.
Basically you need to replace u8x8_byte_4wire_sw_spi with a version which writes to your SPI subsystem.
See: https://github.com/olikraus/u8g2/wiki/Porting-to-new-MCU-platform#hardware-spi-communication

@logiclayer
Copy link

I use STM32F103C8T6 and STM32CubeIDE. So please give me a sample about it.

@olikraus
Copy link
Owner Author

U8g2 is a Arduino Lib. I do not know these environments and I do not know your controller. I also do not know u8g2_gpio_and_delay_stm32. Maybe approach the person who wrote this. Or write your own code.

@logiclayer
Copy link

Arduino users are mostly beginner level of hardware and software programmers. STMCube or Keil users are more professional. You have a very good library for LCD. And if you can make it work in these platforms then your library users will grow up much faster. Your library will be like a brand for LCD displays. So my advice is you focus on that. These are my thoughts :)

@olikraus
Copy link
Owner Author

STMCube or Keil users are more professional.

Then you should be able to follow the instructions from here and implement a callback function for your uC.

You have a very good library for LCD

Thanks

And if you can make it work in these platforms then your library users will grow up much faster. Your library will be like a brand for LCD displays.

This is a spare time lib with exactly zero commercial interest. Do you really think I am interested in any growth?

So my advice is you focus on that.

:-D The good thing about a complete private, nc, open source project is: I can ignore advices. You have all the sources and instructions here. Please go ahead and implement the HW SPI callback. Let me know if you have any specific questions. I am usually always there to help (although i have to spent my personal spare time for this)

@delgadosouza
Copy link

Dear Olikraus, thank you for this great library!

I have a bluepill STM32F103C8T6 and I would like to use a ST7920 display on the SPI2 (pins PB12 to PB15). On the SPI1 I have another sensor.

I used the SW constructor on those pins and it works fine but slow. Unfortunately, because my project is interactive I can't use it with this speed.

I am using the official Arduino_Core_STM32.

The constructor for the second SPI would be

SPIClass mySPI_2(uint8_t mosi, uint8_t miso, uint8_t sclk, uint8_t ssel)

by the documentation in their wiki.

I tried the HW version:

U8G2_ST7920_128X64_F_2ND_HW_SPI disp(LCDROTATION, SS_RS_CS, RST_RESET);

and it compiles but nothing is shown on the screen.

So I tried defining SPI_INTERFACES_COUNT 2 on the beggining of the U8x8lib.h file and got the error:

\src\U8x8lib.cpp:1000:7: error: request for member 'transfer' in '(SPI_TypeDef*)((1073741824 + 65536) + 12288)', which is of pointer type 'SPI_TypeDef*' (maybe you meant to use '->' ?)

So I openned the U8x8lib.cpp file and tried to hardcode the mentioned constructor for the second SPI and exchanged all occurrences of SPI1 by mySPI_2 and it compiled but the screen was blank.

I have sill a lot to learn so I have no ideas how to solve this... Is it really a problem with the core I am using that don't follow the Arduino standard? Do you have any suggestions for a workaround?

@delgadosouza
Copy link

I just received and tried the STM32F401CCU (Black Pill) and have exactly the same behaviour.
I openned a new issue, I hope you can help me...

@olikraus
Copy link
Owner Author

olikraus commented Jun 5, 2020

Two devices could share the same SPI port of the CS line is different. Maybe you could use SPI1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants