|
| 1 | +/* |
| 2 | + * This example has been tested with the Arduino 10BASE-T1S (T1TOS) shield and |
| 3 | + * can be used to control the value of various DIO output pins. |
| 4 | + * |
| 5 | + * Author: |
| 6 | + * Alexander Entinger |
| 7 | + */ |
| 8 | + |
| 9 | +/************************************************************************************** |
| 10 | + * INCLUDE |
| 11 | + **************************************************************************************/ |
| 12 | + |
| 13 | +#include <Arduino_10BASE_T1S.h> |
| 14 | + |
| 15 | +#include <SPI.h> |
| 16 | + |
| 17 | +/************************************************************************************** |
| 18 | + * CONSTANTS |
| 19 | + **************************************************************************************/ |
| 20 | + |
| 21 | +static uint8_t const T1S_PLCA_NODE_ID = 0; /* Doubles as PLCA coordinator. */ |
| 22 | + |
| 23 | +static IPAddress const ip_addr {192, 168, 42, 100 + T1S_PLCA_NODE_ID}; |
| 24 | +static IPAddress const network_mask{255, 255, 255, 0}; |
| 25 | +static IPAddress const gateway {192, 168, 42, 100}; |
| 26 | + |
| 27 | +static T1SPlcaSettings const t1s_plca_settings{T1S_PLCA_NODE_ID}; |
| 28 | +static T1SMacSettings const t1s_default_mac_settings; |
| 29 | + |
| 30 | +/************************************************************************************** |
| 31 | + * GLOBAL VARIABLES |
| 32 | + **************************************************************************************/ |
| 33 | + |
| 34 | +auto const tc6_io = new TC6::TC6_Io |
| 35 | + ( SPI |
| 36 | + , CS_PIN |
| 37 | + , RESET_PIN |
| 38 | + , IRQ_PIN); |
| 39 | +auto const tc6_inst = new TC6::TC6_Arduino_10BASE_T1S(tc6_io); |
| 40 | + |
| 41 | +/************************************************************************************** |
| 42 | + * SETUP/LOOP |
| 43 | + **************************************************************************************/ |
| 44 | + |
| 45 | +void setup() |
| 46 | +{ |
| 47 | + Serial.begin(115200); |
| 48 | + while (!Serial) { } |
| 49 | + delay(1000); |
| 50 | + |
| 51 | + /* Initialize digital IO interface for interfacing |
| 52 | + * with the LAN8651. |
| 53 | + */ |
| 54 | + pinMode(IRQ_PIN, INPUT_PULLUP); |
| 55 | + attachInterrupt(digitalPinToInterrupt(IRQ_PIN), |
| 56 | + []() { tc6_io->onInterrupt(); }, |
| 57 | + FALLING); |
| 58 | + |
| 59 | + /* Initialize IO module. */ |
| 60 | + if (!tc6_io->begin()) |
| 61 | + { |
| 62 | + Serial.println("'TC6_Io::begin(...)' failed."); |
| 63 | + for (;;) { } |
| 64 | + } |
| 65 | + |
| 66 | + MacAddress const mac_addr = MacAddress::create_from_uid(); |
| 67 | + |
| 68 | + if (!tc6_inst->begin(ip_addr |
| 69 | + , network_mask |
| 70 | + , gateway |
| 71 | + , mac_addr |
| 72 | + , t1s_plca_settings |
| 73 | + , t1s_default_mac_settings)) |
| 74 | + { |
| 75 | + Serial.println("'TC6::begin(...)' failed."); |
| 76 | + for (;;) { } |
| 77 | + } |
| 78 | + |
| 79 | + Serial.print("IP\t"); |
| 80 | + Serial.println(ip_addr); |
| 81 | + Serial.println(mac_addr); |
| 82 | + Serial.println(t1s_plca_settings); |
| 83 | + Serial.println(t1s_default_mac_settings); |
| 84 | + |
| 85 | + // If Power Provider, turn on LOCAL_ENABLE and turn on T1S_DISABLE |
| 86 | + //tc6_inst->digitalWrite(1,1,1); |
| 87 | + //tc6_inst->digitalWrite(0,0,0); |
| 88 | +} |
| 89 | + |
| 90 | +void loop() |
| 91 | +{ |
| 92 | + /* Services the hardware and the protocol stack. |
| 93 | + * Must be called cyclic. The faster the better. |
| 94 | + */ |
| 95 | + tc6_inst->service(); |
| 96 | + |
| 97 | + static unsigned long prev_dio_toogle = 0; |
| 98 | + auto const now = millis(); |
| 99 | + |
| 100 | + if ((now - prev_dio_toogle) > 5000) |
| 101 | + { |
| 102 | + prev_dio_toogle = now; |
| 103 | + |
| 104 | + static bool dio_val = true; |
| 105 | + |
| 106 | + Serial.print("DIO A0 = "); |
| 107 | + Serial.println(dio_val); |
| 108 | + |
| 109 | + /* Modify this function call parameter if you want |
| 110 | + * to test a different LAN8651 DIO. |
| 111 | + */ |
| 112 | + tc6_inst->digitalWrite(TC6::DIO::A0, dio_val); |
| 113 | + dio_val = !dio_val; |
| 114 | + } |
| 115 | +} |
0 commit comments