Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 45 of 45

Thread: One Teensy 4.1 to send/receive information to six Teensy 4.1s

  1. #26
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    327
    the PIC18F26Q84 is a microcontroller just like the Teensy
    it's made by microchip who also now own the microcontrollers used in most of the Arduino boards.

    the PIC18F26Q84-I/SP is 28pin through hole which makes it easy to solder and use in breadboards,
    the downside is that it needs a programmer, the cheapest one is called PicKit3.

    to connect a PIC18F26Q84 to a CAN network you will still need a SN65HVD230 CAN Bus Transceiver.

    example code is here
    https://github.com/microchip-pic-avr...asic-operation

  2. #27
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    So I would connect a small sensor to PIC18F26Q84 that would connect to SN65HVD230 CAN Bus Transceiver that connects to a CAN 2.0 network of SN65HVD230 CAN Bus Transceiver in which each is connected to a Teensy 4.1?

  3. #28
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,905
    yes, all devices (teensies, pics, or sensors) need a transceiver if they don't already have one. but yeah all run in parallel transceiver to transceiver

    if a sensor isn't CAN capable, you could just put it on one of your teensies and have that teensy act as the device on the network hosting the data you need

  4. #29
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    327
    I just think it's overkill and high price to use a teensy 4.x for such a simple task,
    not to mention the power requirements.
    I don't say that the Teensy 4.x have a high price (I really like the price), but for that task it is.

    Ok then it's easier to program a teensy with a simple SDK, but small 8-bit PIC micros are not that complicated either.

    I believe that a Teeensy should take care of more heavy things,
    not be used as a "blink a led" project.

    It's also better to use a smaller cheaper MCU, as they can easily be replaced when they break,
    and you don't have to cry about the money loss.

    note. the PIC18F26Q84 (just like other new variants of PIC) have a internal oscillator, so that the required external components can be kept to a minimum.

  5. #30
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    @tonton81

    I tried using code from https://forum.pjrc.com/threads/56035...eensy-4/page13 with the image setup I have. I am using the latest CAN code so I think the reason it isn't work for me is due to incompatibility.

    Click image for larger version. 

Name:	20211128_140837.jpg 
Views:	14 
Size:	208.2 KB 
ID:	26696

    Click image for larger version. 

Name:	Screenshot 2021-11-28 142554.jpg 
Views:	8 
Size:	84.3 KB 
ID:	26697

    Receiver Code
    Code:
    #include <FlexCAN_T4.h>
    FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_64> Can0;
    
    void setup(void) {
      Serial.begin(115200); delay(400);
      pinMode(6, OUTPUT); digitalWrite(6, LOW); /* optional tranceiver enable pin */
      Can0.begin();
      Can0.setBaudRate(500000);
      Can0.setMaxMB(16);
      Can0.enableFIFO();
      Can0.enableFIFOInterrupt();
      Can0.onReceive(canSniff);
      Can0.mailboxStatus();
      Can0.enableMBInterrupts();
      pinMode(13, OUTPUT);
    }
    
    void canSniff(const CAN_message_t &msg) {
      Serial.print("MB "); Serial.print(msg.mb);
      Serial.print("  OVERRUN: "); Serial.print(msg.flags.overrun);
      Serial.print("  LEN: "); Serial.print(msg.len);
      Serial.print(" EXT: "); Serial.print(msg.flags.extended);
      Serial.print(" RTR: "); Serial.print(msg.flags.remote);
      Serial.print(" TS: "); Serial.print(msg.timestamp);
      Serial.print(" ID: "); Serial.print(msg.id, HEX);
      Serial.print(" Buffer: ");
      for ( uint8_t i = 0; i < msg.len; i++ ) {
        Serial.print(msg.buf[i], HEX); Serial.print(" ");
      } Serial.println();
      static uint32_t _time = millis();
      Serial.print("Time between frames: ");
      Serial.println(millis() - _time);
      _time = millis();
    }
    
    
    void loop() {
    }
    Sender

    Code:
    #include <FlexCAN_T4.h>
    #include <elapsedMillis.h>
    
    FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_128> LCAN;
    elapsedMillis tsk1000msCounter;
    CAN_message_t msg0E0;
    
    void setup() {
      LCAN.begin();
      LCAN.setClock(CLK_60MHz);
      LCAN.setBaudRate(500000);
      LCAN.setMaxMB(10);
      LCAN.setMB(MB0, RX);   /* Set Mailbox RX Direction */
      LCAN.setMB(MB1, RX);   /* Set Mailbox RX Direction */
      LCAN.setMB(MB2, RX);   /* Set Mailbox RX Direction */
      for (int i = 4; i < 10; i++) LCAN.setMB((FLEXCAN_MAILBOX)(i), TX); /* Set Mailbox TX Direction */
    
      msg0E0.id = 0x0E0;
      msg0E0.len = 5;     // Data length
    
      Serial.begin(500000); delay(1000);
      LCAN.onReceive(canSniff);
      LCAN.enableMBInterrupts();
      Serial.print("LCAN Setup: ");
      LCAN.mailboxStatus();
    }
    
    void loop() {
      if (tsk1000msCounter >= 1000) {
        tsk1000msCounter = 0;  // Reset 1000ms timer
        msg0E0.buf[0]++;
        LCAN.write(msg0E0);
      }
    }
    
    void canSniff(const CAN_message_t &msg) {
      Serial.print("MB "); Serial.print(msg.mb);
      Serial.print("  OVERRUN: "); Serial.print(msg.flags.overrun);
      Serial.print("  LEN: "); Serial.print(msg.len);
      Serial.print(" EXT: "); Serial.print(msg.flags.extended);
      Serial.print(" RTR: "); Serial.print(msg.flags.remote);
      Serial.print(" TS: "); Serial.print(msg.timestamp);
      Serial.print(" ID: "); Serial.print(msg.id, HEX);
      Serial.print(" Buffer: ");
      for ( uint8_t i = 0; i < msg.len; i++ ) {
        Serial.print(msg.buf[i], HEX); Serial.print(" ");
      } Serial.println();
      static uint32_t _time = millis();
      Serial.print("Time between frames: ");
      Serial.println(millis() - _time);
      _time = millis();
    }

  6. #31
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,905
    pins 0 and 1 is CAN2
    pins 22 and 23 is CAN1
    pins 30 and 31 is CAN3

    You should be using CAN1 on constructor

    also i don't think your transceivers are wired to 3.3v, they're left unconnected in the photo
    Last edited by tonton81; 11-28-2021 at 08:10 PM.

  7. #32
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    I wired my transceivers to 3.3volts.

    Click image for larger version. 

Name:	20211128_160206.jpg 
Views:	8 
Size:	199.3 KB 
ID:	26698

    I am not sure what you meant by CAN1 on constructor. I instead tried changing all CAN0s to CAN1. Still produced no results.

  8. #33
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,905
    Code:
    FlexCAN_T4<CAN3, RX_SIZE_256, TX_SIZE_128> LCAN;
    That is the peripheral BUS specifier in the constructor (CAN1,CAN2,CAN3). It has no relation to Can0/Can1/LCAN. Those are just your custom name of the object that uses that specific bus.

    Should be CAN1 (on both teensies)

  9. #34
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    I changed the peripheral BUS specifier to both be CAN1. I am getting the same result below.

    Click image for larger version. 

Name:	Screenshot 2021-11-28 182505.jpg 
Views:	5 
Size:	91.8 KB 
ID:	26700

  10. #35
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,905
    is CTX to CTX and CRX to CRX correct? I can't tell from the image, unlike UART, they shouldn't be crossed, only direct

  11. #36
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    Yes as far as I can tell.

  12. #37
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,905
    it could either be a bad termination or bad transceiver at this point

  13. #38
    Junior Member
    Join Date
    Oct 2021
    Posts
    17
    I switched one of the CAN Bus Transceivers with no luck. Here are the code and the photos of what I have so far.
    Receiver:
    Code:
    #include <FlexCAN_T4.h>
    FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_64> Can0;
    
    void setup(void) {
      Serial.begin(115200); delay(400);
      pinMode(6, OUTPUT); digitalWrite(6, LOW); /* optional tranceiver enable pin */
      Can0.begin();
      Can0.setBaudRate(500000);
      Can0.setMaxMB(16);
      Can0.enableFIFO();
      Can0.enableFIFOInterrupt();
      Can0.onReceive(canSniff);
      Can0.mailboxStatus();
      Can0.enableMBInterrupts();
      pinMode(13, OUTPUT);
    }
    
    void canSniff(const CAN_message_t &msg) {
      Serial.print("MB "); Serial.print(msg.mb);
      Serial.print("  OVERRUN: "); Serial.print(msg.flags.overrun);
      Serial.print("  LEN: "); Serial.print(msg.len);
      Serial.print(" EXT: "); Serial.print(msg.flags.extended);
      Serial.print(" RTR: "); Serial.print(msg.flags.remote);
      Serial.print(" TS: "); Serial.print(msg.timestamp);
      Serial.print(" ID: "); Serial.print(msg.id, HEX);
      Serial.print(" Buffer: ");
      for ( uint8_t i = 0; i < msg.len; i++ ) {
        Serial.print(msg.buf[i], HEX); Serial.print(" ");
      } Serial.println();
      static uint32_t _time = millis();
      Serial.print("Time between frames: ");
      Serial.println(millis() - _time);
      _time = millis();
    }
    
    Sender:
    void loop() {
    }
    Code:
    #include <FlexCAN_T4.h>
    #include <elapsedMillis.h>
    
    FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_128> LCAN;
    elapsedMillis tsk1000msCounter;
    CAN_message_t msg0E0;
    
    void setup() {
      LCAN.begin();
      LCAN.setClock(CLK_60MHz);
      LCAN.setBaudRate(500000);
      LCAN.setMaxMB(10);
      LCAN.setMB(MB0, RX);   /* Set Mailbox RX Direction */
      LCAN.setMB(MB1, RX);   /* Set Mailbox RX Direction */
      LCAN.setMB(MB2, RX);   /* Set Mailbox RX Direction */
      for (int i = 4; i < 10; i++) LCAN.setMB((FLEXCAN_MAILBOX)(i), TX); /* Set Mailbox TX Direction */
    
      msg0E0.id = 0x0E0;
      msg0E0.len = 5;     // Data length
    
      Serial.begin(500000); delay(1000);
      LCAN.onReceive(canSniff);
      LCAN.enableMBInterrupts();
      Serial.print("LCAN Setup: ");
      LCAN.mailboxStatus();
    }
    
    void loop() {
      if (tsk1000msCounter >= 1000) {
        tsk1000msCounter = 0;  // Reset 1000ms timer
        msg0E0.buf[0]++;
        LCAN.write(msg0E0);
      }
    }
    
    void canSniff(const CAN_message_t &msg) {
      Serial.print("MB "); Serial.print(msg.mb);
      Serial.print("  OVERRUN: "); Serial.print(msg.flags.overrun);
      Serial.print("  LEN: "); Serial.print(msg.len);
      Serial.print(" EXT: "); Serial.print(msg.flags.extended);
      Serial.print(" RTR: "); Serial.print(msg.flags.remote);
      Serial.print(" TS: "); Serial.print(msg.timestamp);
      Serial.print(" ID: "); Serial.print(msg.id, HEX);
      Serial.print(" Buffer: ");
      for ( uint8_t i = 0; i < msg.len; i++ ) {
        Serial.print(msg.buf[i], HEX); Serial.print(" ");
      } Serial.println();
      static uint32_t _time = millis();
      Serial.print("Time between frames: ");
      Serial.println(millis() - _time);
      _time = millis();
    }
    Click image for larger version. 

Name:	20211128_200635.jpg 
Views:	6 
Size:	177.9 KB 
ID:	26701

    Click image for larger version. 

Name:	20211128_200643.jpg 
Views:	6 
Size:	153.3 KB 
ID:	26702

    Click image for larger version. 

Name:	20211128_200648.jpg 
Views:	6 
Size:	174.7 KB 
ID:	26703

    Click image for larger version. 

Name:	20211128_200653.jpg 
Views:	5 
Size:	170.2 KB 
ID:	26704

  14. #39
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    327
    But the RT1062 datasheet (page2518) defines can1rx as a input and can1tx as output.
    Then they must be crossed as the canrx of the hvd230 is an input.
    (Or is that a error in the datasheet?)

    Also in the "description" of can2rx it say this is the CAN transmit signal ( is that a error in the datasheet?)

    Which case is the correct description? It's very confusing.

  15. #40
    I have 6 slave teensy 4.1 and one master teensy 4.1. Each slave needs to be able to receive commands from the master and be able to send information to the master if requested. However, each slave needs to be able to send information to the master when there is an issue without the master requesting it. This means I need to prevent collisions if multiple slaves detect issues. From how I understand each proposal so far, I will need each teensy to communicate equivalently and not as a master/slave configuration. I could be wrong so correct me here, I need a full-duplex RS485 configuration with what @manicksan suggested or a CAN network as both mentioned before. Which would be more appropriate for my application?
    I think point-to-point serial links would be so much easier. You can prototype and develop software with direct connections from Teensy-to-Teensy (no other chips). The host T4.1 can easily support simultaneous point-to-point serial links with each of the 6 or 7 other micros, probably at 115200 baud. Is there any description of how much and how often data needs to be transmitted? Maybe a T4.1 in the middle and the others T3.2 or even TLC would work, and you would just be using UARTs and eventually RS-232. No need to mess with CAN, which is a bus, and can never be "simultaneous" for all 6 or 7 devices.

  16. #41
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,905
    No need to mess with CAN, which is a bus, and can never be "simultaneous" for all 6 or 7 devices.
    It can read/write to hundreds of devices simultaneously even if one goes down, what happens when you pull the power on a serial version when others talk to it? if it's wired in series the remaining nodes are lost, and traffic ends there

  17. #42
    What I was suggesting is 7 point-to-point serial links, as opposed to a bus. The host T4.1 would dedicate a separate UART to each of the other micros. That could be wired up on a breadboard with no additional chips. It's true that CAN is capable of connecting many devices, but they can't all communicate simultaneously, simply because it's a bus. It does support multi-master, which is fine, but there is only one master at a time. If the T4.1 host wants to get data from all 7 of the other micros, it must do so sequentially. I agree that's probably fast enough, but the OP used the word "simultaneous", so I thought I would ask.

  18. #43
    Throw this out there... why not use the Ethernet adapters? ( unless missed it in this thread )

    Static IP setup each device and A simple network switch? or DHCP things with A simple router?

    I am using the NativeEthernet, ArduinoJson ... and using XML and JSON in the mix to things with pretty good results.

    Using simple TCPIP to handle the communications?

    Then what is nice, I can use my dev PC to connect in and monitor and debug/test things too. As the teensy doesn't care... its tcpip traffic.

    Seems fast and when I don't write bad code, it seems pretty reliable too.

  19. #44
    That could work. It's really a question of what the OP is trying to do. One thing is clear, there are many options!

  20. #45
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    327
    I did try your transmitter code on my teensy 4.1
    even the example code from
    https://github.com/tonton81/FlexCAN_...ith_interrupts

    but both examples don't output anything when measuring with my oscilloscope,
    the output is a steady high level so the CAN module is active.

    I have tried all CAN interfaces (CAN1, CAN2, CAN3)
    but same result on the respective pins (both RX & TX)

    I can see sent data on Serial2 (pin8) so nothing is wrong with the connections (or a bad scope wire)

    I'm using TD 1.55 with fresh "install" of Arduino 1.8.13

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •