Canbus Shield/ BN880 Serial Conflict (SPI Transaction help maybe?)

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <mcp_can.h>
#include <SPI.h>

#include <dht.h>

#include “TinyGPS++.h”
#include “NeoSWSerial.h”
TinyGPSPlus gps;
NeoSWSerial in(51, 50);
dht DHT;

unsigned long time = 0;

unsigned long key_value = 0;
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 10;
const int ledHIGH = 1;
const int ledLOW = 0;

MCP_CAN CAN(SPI_CS_PIN);

void setup()
{
{
// put your setup code here, to run once:
Serial.begin(9600);

time = millis();

Serial.println(“Serial started!”);
}
while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
in.begin(9600);
}

}
void loop() {
// put your main code here, to run repeatedly:
while (in.available() > 0)
gps.encode(in.read());
{
Serial.print(“LAT=”); Serial.println(gps.location.lat(), 6);
Serial.print(“LONG=”); Serial.println(gps.location.lng(), 6);
}
}

Hi there! I was hoping I could get some help with this? When CAN.begin(CAN_500KBPS) (Canbus Shield on Arduino Mega) Is enabled, The serial communications no longer can take place to the GPS module (Serial pins 51,52) I suspect this is in part how the Canbus driver uses serial and conflicts with the Neoswserial. But I dont know how to go about solving this issue. I was hoping for some guidance?

agentgengar:
Hi there! I was hoping I could get some help with this? When CAN.begin(CAN_500KBPS) (Canbus Shield on Arduino Mega) Is enabled, The serial communications no longer can take place to the GPS module (Serial pins 51,52) I suspect this is in part how the Canbus driver uses serial and conflicts with the Neoswserial. But I dont know how to go about solving this issue. I was hoping for some guidance?

On the MEGA,SPI pins (which the CAN bus shield SPI pins NEED to be connected to) are 50,51,52 and 53 which mean you would need to use a difference set of pin to connect your GPS module to if you can you use it along with the CANbus sheild.

hope that helps....

sherzaad:
On the MEGA,SPI pins (which the CAN bus shield SPI pins NEED to be connected to) are 50,51,52 and 53 which mean you would need to use a difference set of pin to connect your GPS module to if you can you use it along with the CANbus sheild.

hope that helps....

Unfortunately no, I tried remapping to pins A14, and A15 for the GPS. GPS working confirmed but only with Canbus shield disabled. Some sort of conflict still seems to exist

I from what I can tell, I think I need to do something with SPI transactions? Could someone help me with what that would look like? I need to define a master and slave I think and allow control of the SPI channel to the devices? Hopefully someone skimming by will call me out on this or give an easy lesson on it. Please and thank you.

Tried digging into SPI abilities, BN 880 doesnt appear to have any SPI abilities other than to the compass itself. While Canbus is enabled it appears to be transmitting no data from the GPS

Problem was resolved. Turned out that they have been communicating properly, but when CANBUS was enabled, it took longer to run serial read checks.

Say it successfully reads once about every 500 tries. This normally went unnoticed due to the number of attempts that could be made when it was the only thing running.

When canbus was enabled 500 tries took much longer and thus appeared to be not working. Solution was to create a static void with a while statement that got called to update GPS info.

static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (GPSSerial.available())
gps.encode(GPSSerial.read());
} while (millis() - start < ms);
}

I dont know if this is the right way to solve the problem or not but its a solution that appears to be working for my application. I hope that anyone else that finds this, finds it useful or helpful!

Hi,

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile: