Moteino crahes with ADA fruit gxf library

Started by SvendP, September 19, 2016, 12:34:17 PM

SvendP

Hi

I have a problem with using a Moteino together with a 2,2" SPI TFT display.
TFT works fine and I can do radio.receiveDone() until I fire up a transmitter.
As soon as there is some actual data in the air the thing crashes and the display goes all blank.

Any help would very helpful, but I suspect it has to do with the SPI bus that can't work with the two devices.

Here's the code:
#include <RFM69.h>
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"

#define TFT_RST 6
#define TFT_DC 7
#define TFT_CS 5

RFM69 radio;
Adafruit_ILI9340 tft = Adafruit_ILI9340(TFT_CS, TFT_DC, TFT_RST);

int x;

void setup() {
  radio.initialize(RF69_868MHZ,1,33);
  tft.begin();
  tft.fillScreen(ILI9340_BLACK);
  tft.setTextColor(ILI9340_BLUE, ILI9340_BLACK);
  tft.setTextSize(3);
  tft.setRotation(3); 
}

void loop() {
tft.setCursor(120, 120);
tft.print(x);
x +=1;
  if (radio.receiveDone())
  {
  tft.setCursor(0, 0);
  }
}

Felix

Usually this is a tale of SPI transactions stepping on each other.

SvendP

Hi Felix

Do you know of anyone having this combo running.
I must admit that the inner programming part of SPI is not my strong side.
So I have no hope of understanding the problem.
Theoretically it should work, but in real life, thing are often different.
Thanks for you input.

Felix

What is the CS line used by that library/screen? Ie how is the device wired?

SvendP

Hi

It's set up like this:
#define TFT_RST 6
#define TFT_DC 7
#define TFT_CS 5

From the Moteino overview picture, none of these pins should conflict with radio.
That's what's causing the headache.

Felix

Try pulling UP your CS line for the TFT. Do it also for the radio just in case, although that should not be necessary. 10k resistors should work.
Does only the TFT crash when you use the radio or the Moteino hangs entirely?

SvendP

Hi Felix

As you can see from the code the only thing that is going on is printing a number to the TFT and if something is received move the TFT cursor to 0,0. Adding 10K pull-ups to both the TFT and the radio made no difference. The TFT is counting up the number until I fire up the transmitter. Then the counter freezes up. The going blank thing was from a piece of code that tried to display some remote data on the TFT, removed that to be minimal.

Felix


TomWS

I would try two things:
1. After the tft.print() line, put in
digitalWrite(TFT_CS,HIGH);  // this would take care of CS being left low by the tft code

2. After receiveDone(), inside the brackets and before the tft call, put in
  delay(100);      // this should allow any radio interrupts (and subsequent radio accesses) to settle out before accessing the tft.


Alternative to number 2, is to put
  
  noInterrupts(); 
   ... 
  interrupts();

around the groups of tft calls so that you do not get the radio trampling on the tft operation due to interrupts.

Once you've done this and it works, remove one or the other and see which one causes it to fail.  Then we'll know...   My suspicion is that you need SPItransactions enabled and I doubt Adafruit's library has this incorporated...

Tom

SvendP

#9
The digitalWrite(TFT_CS,HIGH); trick made no difference.
The delay(100); made no difference.
The noInt/Int trick made no difference.
Trying the ILI9341 library witch seems to have the SPItransactions things in it, still the thing hangs on the first data in the air.

Felix

Does the U8glib support your TFT screen?
I have had great success with this lib and I really like it, it works without a glitch and it's rock solid. See the MightyHat example on how it's used.

SvendP

U8glib does not support the ILI9340/ILI9341.
But lesson is learnt, do breadboard before you do PCB.  :o
I will have to think up some other combo and try that.
Thanks for your help.  :)