Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Added possibility to use alternative TX/RX pins
Updated the Readme
  • Loading branch information
pawelsky committed Nov 13, 2016
1 parent 5e0ef70 commit 2d27761
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
19 changes: 14 additions & 5 deletions FlexCAN.cpp
Expand Up @@ -22,7 +22,7 @@ static const int rxb = 0;
#define FLEXCANb_IDFLT_TAB(b, n) (*(vuint32_t*)(b+0xE0+(n*4)))

// -------------------------------------------------------------
FlexCAN::FlexCAN(uint32_t baud, uint8_t id)
FlexCAN::FlexCAN(uint32_t baud, uint8_t id, uint8_t txAlt, uint8_t rxAlt)
{
flexcanBase = FLEXCAN0_BASE;
#ifdef __MK66FX1M0__
Expand All @@ -32,14 +32,23 @@ FlexCAN::FlexCAN(uint32_t baud, uint8_t id)
// set up the pins
if(flexcanBase == FLEXCAN0_BASE)
{
// 3=PTA12=CAN0_TX, 4=PTA13=CAN0_RX
CORE_PIN3_CONFIG = PORT_PCR_MUX(2);
CORE_PIN4_CONFIG = PORT_PCR_MUX(2);// | PORT_PCR_PE | PORT_PCR_PS;
#ifdef __MK66FX1M0__
// 3=PTA12=CAN0_TX, 4=PTA13=CAN0_RX (default)
// 29=PTB18=CAN0_TX, 30=PTB19=CAN0_RX (alternative)
if(txAlt == 1) CORE_PIN29_CONFIG = PORT_PCR_MUX(2); else CORE_PIN3_CONFIG = PORT_PCR_MUX(2);
if(rxAlt == 1) CORE_PIN30_CONFIG = PORT_PCR_MUX(2); else CORE_PIN4_CONFIG = PORT_PCR_MUX(2);// | PORT_PCR_PE | PORT_PCR_PS;
#else
// 3=PTA12=CAN0_TX, 4=PTA13=CAN0_RX (default)
// 32=PTB18=CAN0_TX, 25=PTB19=CAN0_RX (alternative)
if(txAlt == 1) CORE_PIN32_CONFIG = PORT_PCR_MUX(2); else CORE_PIN3_CONFIG = PORT_PCR_MUX(2);
if(rxAlt == 1) CORE_PIN25_CONFIG = PORT_PCR_MUX(2); else CORE_PIN4_CONFIG = PORT_PCR_MUX(2);// | PORT_PCR_PE | PORT_PCR_PS;
#endif
}
#ifdef __MK66FX1M0__
else if(flexcanBase == FLEXCAN1_BASE)
{
// 33=PTE24=CAN1_TX, 34=PTE25=CAN1_RX
// 33=PTE24=CAN1_TX, 34=PTE25=CAN1_RX (default)
// NOTE: Alternative CAN1 pins are not broken out on Teensy 3.6
CORE_PIN33_CONFIG = PORT_PCR_MUX(2);
CORE_PIN34_CONFIG = PORT_PCR_MUX(2);// | PORT_PCR_PE | PORT_PCR_PS;
}
Expand Down
2 changes: 1 addition & 1 deletion FlexCAN.h
Expand Up @@ -30,7 +30,7 @@ class FlexCAN
uint32_t flexcanBase;

public:
FlexCAN(uint32_t baud = 125000, uint8_t id = 0);
FlexCAN(uint32_t baud = 125000, uint8_t id = 0, uint8_t txAlt = 0, uint8_t rxAlt = 0);
void begin(const CAN_filter_t &mask);
inline void begin()
{
Expand Down
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -29,6 +29,16 @@ Please add parts you are using successfully with Teensy 3.1 to this list.
- Linear LT1796 on 5V (not speedtested)

###Driver API
**FlexCAN(baud, id, txAlt, rxAlt)**
Create the FlexCAN object. The table below describes each parameter together with allowed values. Defaults are marked **bold**. When a non-allowed value is used default will be taken instead.

| Parameter | Description | Allowed values
|-----------|----------------------|------------------------------------------------------------------------
| baud | baudrate [bps] | Teensy 3.1/3.2/3.6: 50000, 100000, **125000**, 250000, 500000, 1000000
| id | FlexCAN interface ID | Teensy 3.1/3.2: **0** (CAN0)<br>Teensy 3.6: **0** (CAN0), 1 (CAN1)
| txAlt | Alternative TX pin | Teensy 3.1/3.2: **0** (PIN3), 1 (PIN32)<br>Teensy 3.6 CAN0: **0** (PIN3), 1 (PIN29)<br>Teensy 3.6 CAN1: **0** (PIN33)
| rxAlt | Alternative RX pin | Teensy 3.1/3.2: **0** (PIN4), 1 (PIN25)<br>Teensy 3.6 CAN0: **0** (PIN4), 1 (PIN30)<br>Teensy 3.6 CAN1: **0** (PIN34)

**begin()**
Enable the CAN to start actively participating on the CANbus.

Expand Down

0 comments on commit 2d27761

Please sign in to comment.