Go Down

Topic: GD23Z and FlexCAN library issue (Read 53 times) previous topic - next topic

desiredshoe

Hi everyone,

I'm having an issue with my HotMCU display running Lightcalamar's GD23Z library along with the flexCAN library.  It's being run on a Teensy 3.5. 

With my current code, the display works fine with a potentiometer connected to the input, the readings update pretty fast.  If I add in the flexCAN code, the can bus readings are really slow, like 30 seconds to update.  If I print the data to the serial monitor, it's also slow.  The data is being fed via CAN bus from a Megasquirt 2 ECU.

Now if I cut out the GD23Z code and just run the flexCAN code, the serial monitor prints the data instantly so it's leading me to believe that the GD code is causing the lag.  I'm using the GD.finish(); command at the end of the code and I've tried GD.flush(); with the same results.

Also, unrelated issue but I've noticed that if I run a 800x480 jpg as a background, it causes the gauges and numbers to not run as smoothly as it does with just a solid color background.  The display still works but I would love to have it be smooth.

Here's the sample of my code,

Code: [Select]

#include <SPI.h>
#include <GD23Z.h>
#include <FlexCAN.h>

static CAN_message_t rxmsg;

File loadScreen;

SdFatSdioEX SD;

int analogPIN = 33;
int val = 0;
int KPA = 0;

float MAP, RPM, CLT, TPS, SPKADV, AFR, BATTV, IAT;


void setup() {
  Can0.begin(500000);
  Serial.begin(9600);
  Serial4.begin(115200);

  pinMode(SD_PIN, OUTPUT);
  digitalWrite(SD_PIN, HIGH); 
  delay(20);
  digitalWrite(SD_PIN, LOW);
  delay(20);
  digitalWrite(SD_PIN, HIGH);
  delay(20);

  GD.begin(1);
  SD.begin();

}

void loop() {
 
  GD.Clear();
  loadScreen = SD.open("main2.jpg");
  GD.cmd_loadimage(0, 0);
  GD.loadSDIO(loadScreen);
  GD.Begin(BITMAPS);
  GD.Vertex2ii(0, 0);

  GD.ColorRGB(0xFFFFFF);
  GD.cmd_number(240,28,31,OPT_RIGHTX,(MAP/10));
  GD.cmd_number(240,75,31,OPT_RIGHTX,(IAT/10));
  GD.cmd_number(240,125,31,OPT_RIGHTX,KPA);

  GD.swap();
  GD.finish();

  canData();

  Serial.println(IAT);
 
 }

 void canData() {
      if ( Can0.read(rxmsg) ) {
    switch (rxmsg.id) { // Using IDs from 1512 as Megasquirt CAN broadcast frames for Simplified Dash Broadcasting.
      // EAch frame represents a data group http://www.msextra.com/doc/pdf/Megasquirt_CAN_Broadcast.pdf
      case 1512:
        MAP = (float)(word(rxmsg.buf[0], rxmsg.buf[1]));
        //RPM = (float)(word(rxmsg.buf[2], rxmsg.buf[3]));
        CLT = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
        TPS = (float)(word(rxmsg.buf[6], rxmsg.buf[7]));
        //CLT = FtoC(CLT / 10);
        break;
      case 1513:
        IAT = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
        //SPKADV = (float)(word(rxmsg.buf[6], rxmsg.buf[6]));
        break;
      case 1514:
        AFR = (float)(word(0x00, rxmsg.buf[1]));
        break;
      case 1515:
        //BATTV = (float)(word(rxmsg.buf[0], rxmsg.buf[1]));
        //generic1 = (float)(word(rxmsg.buf[2], rxmsg.buf[3]));
        //generic2 = (float)(word(rxmsg.buf[4], rxmsg.buf[5]));
        break;
    }
  }
}

Go Up