Hardware SPI

Working libraries, libraries being ported and related hardware
User avatar
BennehBoy
Posts: 385
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Hardware SPI

Postby BennehBoy » Fri Feb 03, 2017 4:45 pm

Epic fail, can't get the screens to work with HW SPI.

Well, they display garbage... I've paired the code right back.

Is there any pin preparation I need to do first?
-------------------------------------
https://github.com/BennehBoy

stevestrong
Posts: 723
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Hardware SPI

Postby stevestrong » Fri Feb 03, 2017 5:02 pm

Any code available how did you initialize the SPI? Lower the clock frequency?

User avatar
BennehBoy
Posts: 385
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Hardware SPI

Postby BennehBoy » Fri Feb 03, 2017 5:18 pm

The library initialises the SPI...

Code: Select all

    if (hwSPI){
      SPI.begin();
#ifdef SPI_HAS_TRANSACTION
      SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
#else
      SPI.setClockDivider (4);
#endif
    }


I thought it may be because a clock divisor of 4 would be 18mhz and the transaction line is setting 8mhz - sqitching transaction one to 18mhz doesn't fix it.

Is that setClockDivider method flawed on stm32?

Code is a copy of my main project with a lot of stuff commented so would be a bit messy to attach.
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 385
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Hardware SPI

Postby BennehBoy » Fri Feb 03, 2017 5:37 pm

Software SPI over the exact same pins works fine.

With HW all the display is compressed into the bottom 8 lines of pixels, I can see it drawing some things correctly but something is up.

I've hacked the clocks about to no avail so far.
-------------------------------------
https://github.com/BennehBoy

stevestrong
Posts: 723
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Hardware SPI

Postby stevestrong » Fri Feb 03, 2017 6:46 pm

Im afraid there is more to adapt in the display library than you expect.
Specially the begin() function and the data writing functions.
Without checking the whole code is difficult to see where the problem is.
Which display library are you using?

EDIT
I already see a problem: you don't need begin() if you use beginTransaction().
If you use beginTransaction(), you don't need setClockDivider().
So I would re-write your code part this way:

Code: Select all

 if (hwSPI){
#ifdef SPI_HAS_TRANSACTION
      SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
#else
      SPI.begin();
      SPI.setClockDivider (4);
#endif
    }

User avatar
BennehBoy
Posts: 385
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Hardware SPI

Postby BennehBoy » Fri Feb 03, 2017 7:39 pm

OK thanks, that's all part of the adafruit_SSD1306 library.

I'll play some more tomorrow, I've been tearing my hair out for 2 hours trying to figure out why 2 identically wired and programmed setups give me different results. If I swap the controllers between the 2 boards the issue stays on the same board, have tested all wires, swapped in different OLED's etc.

Anyway, I've had enough and I'm going to the pub :D
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 385
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Hardware SPI

Postby BennehBoy » Sat Feb 04, 2017 11:28 am

I know that hangovers are not conducive with productivity, but today both boards are behaving exactly as expected... I've changed nothing.

Oddly when I now try to upload to the paired back test system the IDE hangs on:

maple_loader v0.1
Resetting to bootloader via DTR pulse

And I can see the LED pulsing on the board - is this due to the R10 issue? not sure what's cuasing this but I can't get a new sketch on now.
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 385
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Hardware SPI

Postby BennehBoy » Sat Feb 04, 2017 3:36 pm

Flashed back to original bootloaders and can upload again - clearly some quirk of v2 that I've not read about - boot pins need to be manually configured?

Anyhow, now of course the bloody thing is displaying garbage again.

I know I'm doing something really dumb here, but just what is evading me.
-------------------------------------
https://github.com/BennehBoy

User avatar
ahull
Posts: 1398
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Hardware SPI

Postby ahull » Sat Feb 04, 2017 3:38 pm

BennehBoy wrote:Flashed back to original bootloaders and can upload again - clearly some quirk of v2 that I've not read about - boot pins need to be manually configured?

Anyhow, now of course the bloody thing is displaying garbage again.

I know I'm doing something really dumb here, but just what is evading me.

Check for dodgy "du pont" wires, loose connections... it might not be software.
- Andy Hull -

User avatar
BennehBoy
Posts: 385
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Hardware SPI

Postby BennehBoy » Sat Feb 04, 2017 4:35 pm

Well I got it working,

Scrapped the wiring and started again - must've got something wrong somehow, even though I checked the wires umpteen times.

So anyway, twiddled the suggestions into the 1306 library and HWSPI still not functional.

I'm going to test the library on a nano with HWSPI in case it's an inherent fault.
-------------------------------------
https://github.com/BennehBoy


Return to “Libraries & Hardware”

Who is online

Users browsing this forum: No registered users and 1 guest