Coder Social home page Coder Social logo

morcibacsi / arduino_tss463_van Goto Github PK

View Code? Open in Web Editor NEW
16.0 5.0 5.0 1.27 MB

Arduino TSS463/TSS461 VAN interface library

License: GNU General Public License v3.0

C++ 97.98% C 2.02%
van-bus arduino-library can-bus can automotive car peugeot citroen esp32 esp32-arduino

arduino_tss463_van's Introduction

Arduino TSS463/TSS461 VAN interface library

This is an Arduino library for the Atmel TSS463/TSS461 VAN Datalink Controller.

VAN bus is pretty similar to CAN bus. It was used in many cars (Peugeot, Citroen) made by PSA.

It is capable of reading and writing the VAN bus. To understand the VAN protocol and the library I strongly recommend to read the datasheet of the TSS463C or the TSS461 VAN Datalink Controller. It is included in the repository inside the extras folder. The library contains references to the pages of the document to have a better understanding on what is going on.

Message types

Understanding the various message types is essential (see page 19-21 and 42-45 in the datasheet of the TSS463C). Some messages are pretty straightforward: they have a source and destination(s), but there are others which are like queries: a device (for example the display) asks another one (like the BSI or the CD changer or the head unit) for some data. So when you are testing and a message does not appear it could mean that you don't have the initiator in your setup (or maybe you are missing the device which should answer for the query). Or it could also mean that you misconfigured the receiver channels.

Because of the various message types and the way the TSS46x works, configuring the channels properly is very important. You can easily miss messages if you don't pay attention to the message types and the channel configuration.

So if you just want to have a working VAN bus reader and don't want to have your hands dirty I recommend my VAN bus reader library for ESP32 as it just dumps everything from the bus regardless of the message types and states. And also that requires less (and more easy to obtain) hardware parts. But that library has reading capabilities only compared to this one which also can transmit messages on the bus safely.

Schematics

To have the library working, you need to build a shield first as such thing does not exists on the market for the VAN bus. To build the hardware you need to buy a TSS463C VAN controller and a REMQ 0339 VAN line driver (this is also known as Alcatel 2840). Unfortunately these are pretty hard to find but if you are lucky you can buy them on aliexpress (or you can also extract them from an old headunit or display).

TSS463C + Remq0339 VAN line driver

schema_tss463c_remq0339

TSS463C + MCP2551 CAN transceiver

Instead of the Remq 0339 it is also possible to use a CAN transceiver, for example the MCP2551

schema_tss463c_mcp2551

TSS461C + TJA1040 CAN transceiver

The library supports the TSS461 controller with a parallel port in Intel mode as well. You can use the schematics below. You need to connect the AD0-AD7, ALE, CS, WR, RD, RES, IRQ pins either to your microcontroller or you can also use an MCP23S17 port extender as well. When you use the port extender then you have to have Majenko's excellent library installed

schema_tss461_mcp23s17_intel_mode_tja_1040

Initialization examples

In version 2.0.0 support was added for TSS461. To have a common codebase for the register setup the actual hardware handling was abstracted away. This means an extra step is required to instantiate the hardware which causes a breaking change from prior versions.

TSS463

#include <SPI.h>
#include <itss46x.h>
#include <tss46x_van.h>
#include <tss463.h>

SPIClass* spi;
ITss46x* vanSender;
TSS46X_VAN* VANInterface;

void setup()
{
  SPIClass* spi;
  spi = new SPIClass();
  spi->begin();

  vanSender = new Tss463(VAN_PIN, spi);
  VANInterface = new TSS46X_VAN(vanSender, VAN_125KBPS);
  VANInterface->begin();
}

TSS461

#include <itss46x.h>
#include <tss46x_van.h>
#include <tss461_intel.h>

ITss46x* vanSender;
TSS46X_VAN* VANInterface;

void setup()
{
    pinSetup = new TSSPinSetup();
    pinSetup->TSS_ALE_PIN   = PB13;
    pinSetup->TSS_WRITE_PIN = PB15;
    pinSetup->TSS_CS_PIN    = PB12;
    pinSetup->TSS_READ_PIN  = PA8;
    pinSetup->TSS_RESET_PIN = PB14;
    
    pinSetup->TSS_AD0_PIN   = PA0;
    pinSetup->TSS_AD1_PIN   = PA1;
    pinSetup->TSS_AD2_PIN   = PA2;
    pinSetup->TSS_AD3_PIN   = PA3;
    pinSetup->TSS_AD4_PIN   = PA4;
    pinSetup->TSS_AD5_PIN   = PA5;
    pinSetup->TSS_AD6_PIN   = PA6;
    pinSetup->TSS_AD7_PIN   = PA7;
    
    vanSender = new Tss461Intel(pinSetup);  
    VANInterface = new TSS46X_VAN(vanSender, VAN_125KBPS);
    VANInterface->begin();
}

TSS461 with MCP23S17

#include <SPI.h>
#include <itss46x.h>
#include <tss46x_van.h>
#include "tss461_with_mcp23s17_intel.h"

SPIClass* spi;
ITss46x* vanSender;
TSS46X_VAN* VANInterface;

void setup()
{
  SPIClass* spi;
  spi = new SPIClass();
  spi->begin();

  //check tss461_intel.h file for pin assignment
  vanSender = new Tss461WithMcp23s17Intel(VAN_PIN, spi);
  VANInterface = new TSS46X_VAN(vanSender, VAN_125KBPS);
  VANInterface->begin();
}

Installing

Copy the files to your documents\Arduino\libraries\tss46x_van folder or install it via the Arduino library manager

Check the tss463_van_monitor and tss463_van_dashboard_experiment folders inside the extras folder for examples on how to read and write messages on the bus.

Tested boards

  • Arduino UNO/Nano/Pro Mini
  • ESP32
  • STM32 BluePill

See also

Thanks

I would like to thank lazarov-g without his help and sketch this library would never exists.

arduino_tss463_van's People

Contributors

doiiido avatar morcibacsi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

arduino_tss463_van's Issues

Read DATA from the VAN BUS with the TSS463C and arduino NANO

Salut,

  • I am trying to test a Arduino NANO + (TSS463C + MCP2551 CAN transceiver)
  • I use your library for the TSS463C
  • I connected the Arduino to the TSS463C according to your diagram (SPI)
  • I use the following code (from your example tss46x_van_reader)
  • I would like to read the IDEN 0xE24 which corresponds to the VIN of the vehicle
//tss46x_van_reader.ino
#include <SPI.h>
#include <itss46x.h>
#include <tss46x_van.h>

#include <tss463.h>
#include <tss461_intel.h>
#include <tss46x_with_serial.h>

uint8_t VAN_PIN = 7;

TSSPinSetup* pinSetup;

SPIClass* spi;
ITss46x* vanSender;
TSS46X_VAN* VANInterface;

uint8_t vanMessageLength;
uint8_t vanMessage[32];

uint8_t headerByte = 0x80;
uint8_t check = 0x00;

char incomingByte;


int a = 0;
int  *b = &a;
void InitTss463()
{
    // initialize SPI
    spi = new SPIClass();//*spi

#ifdef ARDUINO_ARCH_AVR
    // start spi on Arduino boards
    spi->begin();
#endif
#ifdef ARDUINO_SAM_DUE
    // start spi on Arduino boards
    spi->begin();
#endif

#ifdef ARDUINO_ARCH_ESP32
    // You can select which pins to use as SPI on ESP32 boards by passing the SCK, MISO, MOSI, SS as arguments (in this order) to the spi->begin() method
    const uint8_t SCK_PIN = 25;
    const uint8_t MISO_PIN = 5;
    const uint8_t MOSI_PIN = 33;
    VAN_PIN = 32;

    spi->begin(SCK_PIN, MISO_PIN, MOSI_PIN, VAN_PIN);
#endif

    // instantiate the VAN message sender for a TSS463
    vanSender = new Tss463(VAN_PIN, spi);
}



void setup()
{
    Serial.begin(500000);
    delay(3000);
    Serial.println("Arduino VAN bus monitor using TSS463C");

    InitTss463();
    //InitTss461();
    //InitTssSerial();

    VANInterface = new TSS46X_VAN(vanSender, VAN_125KBPS);
    VANInterface->begin();

    // Data read *VIN CAR* Exemple
    // IDENTIFIER = 0XE24 
    /*
    SOF: 0x0E
    IDEN: 0xE24
    COM: 0x08
    DATA(0): 0x56
    DATA(1): 0x45
    DATA(2): 0x33
    DATA(3): 0x38
    DATA(4): 0x43
    DATA(5): 0x52
    DATA(6): 0x46
    DATA(7): 0x52
    DATA(8): 0x45
    DATA(9): 0x38
    DATA(10): 0x30
    DATA(11): 0x30
    DATA(12): 0x30
    DATA(13): 0x30
    DATA(14): 0x35
    DATA(15): 0x34
    DATA(16): 0x34
    DATA(17): 0x69
    DATA(18): 0xE6
    EOF: 0xFF
    */

    VANInterface->set_channel_for_receive_message(1, 0xE2, 23, 0); // It's Good ?
}

void loop() {
    MessageLengthAndStatusRegister messageAvailable = VANInterface->message_available(1);
    if (messageAvailable.data.CHRx || messageAvailable.data.CHTx || messageAvailable.data.CHER)
    {
        VANInterface->read_message(1, &vanMessageLength, vanMessage);

        Serial.print("Channel: ");
        Serial.print(1, DEC);
        Serial.print(": ");

        char tmp[3];

        for (size_t i = 0; i < vanMessageLength; i++)
        {
            snprintf(tmp, 3, "%02X", vanMessage[i]);
            Serial.print(" ");
            Serial.print(tmp);
        }
        Serial.println();

        VANInterface->reactivate_channel(1);
    }
}

roma6868_breadboard_monting

  • The data is sent to the TSS463C according to the oscilloscope, but there is no answer from the TSS463C.
  • In the serial monitor i read this Channel: 1: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 21

roma6868_TSS463C + MCP2551

Question related to the schematic

Hi Peter,

I have been following your project for a while now. And was interested in recreating the circuit. I have opened up an old replacement Sagem PP-T40 clock (the one the can be found in Peugeot 206 from 2003). In it I found the TSS461C and the Alcatel 2840 (mine is designated as: 0217 REMQ. Is it possible to use these chips together? Or do I have to look for a TJA1040?

PS: Is Y1 a resonator or a oscillator?

Kind regards,

Rik

Arduino UNO keeps restarting

Hi, thanks for your awesome work on this library.

I am using the Arduino UNO, TSS463C + MCP2551. Read & Write works fine, but my Arduino Uno keeps restarting or hanging randomly. Can be a problem that my Arduino is not genuine? Or maybe memory issues?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.