Git Product home page Git Product logo

stm32duino_can_library's Introduction

STM32duino_CAN_Library

CanBus library for STM32F103 running on STM32duino, tested on F103C8T6 variant. Key advantages:

  • Object-oriented programming style
  • Support for inline Can::Frame initialization
  • Support for 33.3KBPS CAN (GMLAN/SWCAN)

Inner workings based on nopnop2002's sketch.

Supported board / Can-Bus parameters:

STM32F103 pinouts:

enum Can::Pinout {
  RX_PA11_TX_PA12,  // 36/48/64/100/144 pin packages
  RX_PB8_TX_PB9,    // 48/64/100/144 pin packages
  RX_PD0_TX_PD1,    // 100/144 pin packages
};

Bitrates:

enum Can::Bitrate {
  CAN_33K3BPS,
  CAN_50KBPS,
  CAN_100KBPS,
  CAN_125KBPS,
  CAN_250KBPS,
  CAN_500KBPS,
  CAN_1000KBPS,
};

Can-Bus frame:

class Can::Frame {
public:
  uint32_t id;
  uint8_t length;
  uint8_t data[8];
  FrameFormat format;
  FrameType type;
}

Types and formats:

enum Can::FrameFormat {
  Standard,
  Extended, 
};

enum Can::FrameType {
  Data,
  Remote,
};

Example usage:

#include "CanBus.hpp"
using namespace Can;
CanBus can0;

void setup() {
  Serial.begin(9600);

  bool ret = can0.begin(Bitrate::CAN_33K3BPS, Pinout::RX_PB8_TX_PB9);
  Serial.println(ret ? "BOOT OK" : "BOOT FAILURE");
  if (!ret) while(true);
}

Frame rx;
Frame tx = { 0x7FF, 3, {0x01, 0x02, 0x03} };

void loop() {

  if(can0.checkReceive()) {
    can0.receive(&rx);
    rx.print();
  }

  tx = { 0x17FF, 3, {0x01, 0x02, 0x03}, FrameFormat::Extended, FrameType::Data };
  can0.send(&tx);
}

stm32duino_can_library's People

Contributors

adamczykpiotr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.