Show Posts
Pages: [1] 2 3
1  Using Arduino / Project Guidance / Re: Dual NIC Arduino on: July 12, 2014, 08:51:49 pm
Here is my post with the changes.
http://forum.arduino.cc/index.php?topic=217423.msg1601862#msg1601862

You would need to call Ethernet.select() with the slave select for the w5100 you wish to access each time you want to change NICs.



Thanks for your help and example code. I was able to successfully integrate everything together. I was wondering how you handle reusing the same W5100 class? I have a problem now that if you unplug one of the Ethernet cables the SNSR status kills my ability to use BOTH interfaces. If I plug it back in they immediately start responding.
2  Using Arduino / Networking, Protocols, and Devices / Re: New Modbus Master-Slave library on: July 07, 2014, 12:27:50 pm
It appears the dropbox link is down for your system, could you please upload again?
3  Using Arduino / Networking, Protocols, and Devices / Re: MODBUS TCP (MgsModbus) on: July 06, 2014, 10:30:30 pm
I'm working with this library now myself. It might help if you post your sketch here.

I'll let you know if I find anything, if you've fixed your problem it might be nice to post your example code anyway as the author doesn't provide any that I can see.
4  Using Arduino / Project Guidance / Re: Dual NIC Arduino on: July 05, 2014, 10:19:16 am
So stupid, I didn't have notify turned on and just saw your post today... ironically I found your other topic doing searches and PMd you. I'm working to try to test but am getting compile errors. I'll update more as I go.

I'd be interested if you had suggestions for how to integrate the W5200 chip into your 5100 code?
I had found this with an example of the 5200 integration well.
https://github.com/Wiznet/W5200_Arduino_Ethernet_Lib
5  Using Arduino / Project Guidance / Re: Dual ethernet ports Due on: July 05, 2014, 02:59:19 am
I stated a new topic in networking.
http://forum.arduino.cc/index.php?topic=253330.msg1793013#msg1793013
6  Using Arduino / Networking, Protocols, and Devices / Two Ethernet ports on Due W5200 on: July 05, 2014, 02:56:46 am
I started this topic
http://forum.arduino.cc/index.php?topic=253038.msg1791776#msg1791776
But it appears it might be better suited here.

I am attempting to get dual Ethernet working with the Ethernet library, like this post demonstrated:
http://forum.arduino.cc/index.php/topic,217423.0.html
But his libraries aren't compiling. Might someone have any input?
See his reply #9

They give me wprogram23 errors.


As a #2 I'd like to also see if someone might be able to help reconcile the w5100 &5200 library as mentioned in that post.

Sorry for brevity posting fromy phone.
7  Using Arduino / Installation & Troubleshooting / Re: Serial COM1 not found on: July 04, 2014, 04:14:01 pm
Which version of windows are you running?

It might be something to do with driver signing being enabled, you have to reboot and F8 to disable it if it's the problem I'm thinking of.
8  Using Arduino / Project Guidance / Re: Dual ethernet ports Due on: July 03, 2014, 10:25:54 pm
I guess my confusion came from the example sketches with Ethernet
It appeared that to have two simultaneous clients I needed  to have two instances of "Ethernet.h" since there doesn't appear to be a way to tell Ethernet.h / EthernetClient.h that you want to use a certain slave when you are trying to communicate...

a realization... do I just need to initialize both adapters and then manually control the SS pin from the sketch directly and hence pretend that it's the same interface?

At this time, I get both of my adapters configured, they now both respond to pings on the right addresses, but the loop part of the sketch is broken, I can't seem to get data from the interface.

I have reverted all files to original states except the below:
Here is my modification to Ethernet.cpp
Code:
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet,int spiSetPin)
{
  W5100.init(spiSetPin);
  W5100.setMACAddress(mac);
  W5100.setIPAddress(local_ip._address);
  W5100.setGatewayIp(gateway._address);
  W5100.setSubnetMask(subnet._address);
  _dnsServerAddress = dns_server;
}


and my sketch which I added some more comments to, mainly the TODO, I don't really have an idea how to trigger the DUE to switch the CS pin correctly.


Code:
/*
  Web client

 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe, based on work by Adrian McEwen

 */


#include <SPI.h>
#include <Ethernet.h>

const int eth0Pin = 4;
const int eth1Pin = 10;


// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac1[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte mac2[] = { 0xBE, 0xEF, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip1(10, 0, 0, 174);
IPAddress ip2(10, 0, 0, 175);

IPAddress dnsIPA(8, 8, 8, 8);
IPAddress gatewayIPA(10, 0, 0, 1);
IPAddress subnetIPA(10, 0, 0, 1);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

unsigned long lastConnectionTime = 0;             // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 5L * 1000L; // delay between updates, in milliseconds

boolean interfaceToogle = false;
// the "L" is needed to use long type numbers

void setup() {
  // Open serial communications and wait for port to open:
  Serial1.begin(57600);
  while (!Serial1) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  delay(1000);   
  Serial1.println("**********SETUP ETHERNET 1 **************");
  Ethernet.begin(mac1, ip1, dnsIPA, gatewayIPA, subnetIPA, eth0Pin);
  Serial1.println("1 Skipping DHCP");

 
  delay(1000);
  Serial1.println("**********SETUP ETHERNET 2 **************");
  Ethernet.begin(mac2, ip2, dnsIPA, gatewayIPA, subnetIPA, eth1Pin);
  Serial1.println("2 Skipping DHCP"); 
}


void loop() {
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (interfaceToogle)
  {
      ////TO DO figure this out?
  }
 
  if (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if ten seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();
    interfaceToogle =  !interfaceToogle;
  }

}

// this method makes a HTTP connection to the server:
void httpRequest() {
  // close any connection before send a new request.
  // This will free the socket on the WiFi shield
  client.stop();

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    client.println("GET /latest.txt HTTP/1.1");
    client.println("Host: www.arduino.cc");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();

    // note the time that the connection was made:
    lastConnectionTime = millis();
  }
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}



edit: sorry about edits, I've been refining the code and found some compile errors.
9  Using Arduino / Project Guidance / Re: Dual ethernet ports Due on: July 03, 2014, 07:47:17 pm
Sorry, yes SPI_CS

I've spent this time doing edits to files, and finding that I have to basically split the whole Ethernet library apart because all the functions are very linked. I was doing okay until I got to socket.h and then found that other classes were using virtual functions from it...

It seems it would actually be immensely easier to "just" figure out how to either
1) add a new device support (all the files #include "utility/w5100.h"), might be nice if they somehow knew to "just" include my modified version w5100v2.h when it was appropriate
OR
2) pass an argument through and have that pin be selected from a local variable. I'm hoping it doesn't require a constant or something stupid is why it is pre defined. We'll see...

Also thank you VERY much for being interested and helping me on this!
10  Using Arduino / Project Guidance / Re: Dual ethernet ports Due on: July 03, 2014, 05:14:41 pm
Thanks, I think the dual library feature is the best way to go right now since that thing is all over the file. It was included in the w5100.cpp file

Code:
/*
 * Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
 *
 * This file is free software; you can redistribute it and/or modify
 * it under the terms of either the GNU General Public License version 2
 * or the GNU Lesser General Public License version 2.1, both as
 * published by the Free Software Foundation.
 */

#include <stdio.h>
#include <string.h>

#include "w5100.h"

// W5100 controller instance
W5100Class W5100;

#define SPI_CS 10

#define TX_RX_MAX_BUF_SIZE 2048
#define TX_BUF 0x1100
#define RX_BUF (TX_BUF + TX_RX_MAX_BUF_SIZE)

#ifdef W5200
#define TXBUF_BASE 0x8000
#define RXBUF_BASE 0xC000
#else
#define TXBUF_BASE 0x4000
#define RXBUF_BASE 0x6000
#endif

void W5100Class::init(void)
{
  delay(300);

  SPI.begin(SPI_CS);
 
  #ifdef W5200
  // should be ok with no divider, W5200 support 80Mhz and SAM3X8E is cadenced to 84Mhz..
  //have tried with webserver sample and it's ok but require more tests
 
  // Set clock to 42Mhz (W5200 should support up to 80Mhz)
  //SPI.setClockDivider(SPI_CS, 2);
  #else
  // Set clock to 4Mhz (W5100 should support up to 14Mhz)
  SPI.setClockDivider(SPI_CS, 21);
  #endif
 
  SPI.setDataMode(SPI_CS, SPI_MODE0);
  writeMR(1<<RST);
 
  #ifdef W5200
  for (int i=0; i<MAX_SOCK_NUM; i++) {
    write((0x4000 + i * 0x100 + 0x001F), 2);
    write((0x4000 + i * 0x100 + 0x001E), 2);
  }
  #else
  writeTMSR(0x55);
  writeRMSR(0x55);
  #endif

  for (int i=0; i<MAX_SOCK_NUM; i++) {
    SBASE[i] = TXBUF_BASE + SSIZE * i;
    RBASE[i] = RXBUF_BASE + RSIZE * i;
  }
}

uint16_t W5100Class::getTXFreeSize(SOCKET s)
{
  uint16_t val=0, val1=0;
  do {
    val1 = readSnTX_FSR(s);
    if (val1 != 0)
      val = readSnTX_FSR(s);
  }
  while (val != val1);
  return val;
}

uint16_t W5100Class::getRXReceivedSize(SOCKET s)
{
  uint16_t val=0,val1=0;
  do {
    val1 = readSnRX_RSR(s);
    if (val1 != 0)
      val = readSnRX_RSR(s);
  }
  while (val != val1);
  return val;
}


void W5100Class::send_data_processing(SOCKET s, const uint8_t *data, uint16_t len)
{
  // This is same as having no offset in a call to send_data_processing_offset
  send_data_processing_offset(s, 0, data, len);
}

void W5100Class::send_data_processing_offset(SOCKET s, uint16_t data_offset, const uint8_t *data, uint16_t len)
{
  uint16_t ptr = readSnTX_WR(s);
  ptr += data_offset;
  uint16_t offset = ptr & SMASK;
  uint16_t dstAddr = offset + SBASE[s];

  if (offset + len > SSIZE)
  {
    // Wrap around circular buffer
    uint16_t size = SSIZE - offset;
    write(dstAddr, data, size);
    write(SBASE[s], data + size, len - size);
  }
  else {
    write(dstAddr, data, len);
  }

  ptr += len;
  writeSnTX_WR(s, ptr);
}


void W5100Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek)
{
  uint16_t ptr;
  ptr = readSnRX_RD(s);
  read_data(s, ptr, data, len);
  if (!peek)
  {
    ptr += len;
    writeSnRX_RD(s, ptr);
  }
}

void W5100Class::read_data(SOCKET s, volatile uint16_t src, volatile uint8_t *dst, uint16_t len)
{
  uint16_t size;
  uint16_t src_mask;
  uint16_t src_ptr;

  src_mask = src & RMASK;
  src_ptr = RBASE[s] + src_mask;

  if( (src_mask + len) > RSIZE )
  {
    size = RSIZE - src_mask;
    read(src_ptr, (uint8_t *)dst, size);
    dst += size;
    read(RBASE[s], (uint8_t *) dst, len - size);
  }
  else
    read(src_ptr, (uint8_t *) dst, len);
}


uint8_t W5100Class::write(uint16_t _addr, uint8_t _data)
{
#ifdef W5200
  SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);
  SPI.transfer(SPI_CS, _addr & 0xFF, SPI_CONTINUE);
  SPI.transfer(SPI_CS, 0x80, SPI_CONTINUE);
  SPI.transfer(SPI_CS, 0x01, SPI_CONTINUE);
#else
  SPI.transfer(SPI_CS, 0xF0, SPI_CONTINUE);
  SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);
  SPI.transfer(SPI_CS, _addr & 0xFF, SPI_CONTINUE);
#endif

  SPI.transfer(SPI_CS, _data);
  return 1; 
}

uint16_t W5100Class::write(uint16_t _addr, const uint8_t *_buf, uint16_t _len)
{
#ifdef W5200
  SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);
  SPI.transfer(SPI_CS, _addr & 0xFF, SPI_CONTINUE);
  SPI.transfer(SPI_CS, (0x80 | ((_len & 0x7F00) >> 8)), SPI_CONTINUE);
  SPI.transfer(SPI_CS, _len & 0x00FF, SPI_CONTINUE);

  for (uint16_t i=0; i<_len; i++)
  {
    SPI.transfer(SPI_CS, _buf[i], SPI_CONTINUE);

  }
#else
  for (uint16_t i=0; i<_len; i++)
  {
SPI.transfer(SPI_CS, 0xF0, SPI_CONTINUE);
SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);
SPI.transfer(SPI_CS, _addr & 0xFF, SPI_CONTINUE);
SPI.transfer(SPI_CS, _buf[i]);
    _addr++;
  }
#endif
 
  return _len;
}

uint8_t W5100Class::read(uint16_t _addr)

#ifdef W5200
  SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);
  SPI.transfer(SPI_CS, _addr & 0xFF, SPI_CONTINUE);
  SPI.transfer(SPI_CS, 0x00, SPI_CONTINUE);
  SPI.transfer(SPI_CS, 0x01, SPI_CONTINUE);
#else
  SPI.transfer(SPI_CS, 0x0F, SPI_CONTINUE);
  SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);
  SPI.transfer(SPI_CS, _addr & 0xFF, SPI_CONTINUE);
#endif
 
  uint8_t _data = SPI.transfer(SPI_CS, 0);
  return _data;
}

uint16_t W5100Class::read(uint16_t _addr, uint8_t *_buf, uint16_t _len)
{
#ifdef W5200
  SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);
  SPI.transfer(SPI_CS, _addr & 0xFF, SPI_CONTINUE);
  SPI.transfer(SPI_CS, (0x00 | ((_len & 0x7F00) >> 8)), SPI_CONTINUE);
  SPI.transfer(SPI_CS, _len & 0x00FF, SPI_CONTINUE);

  for (uint16_t i=0; i<_len; i++)
  {
    _buf[i] = SPI.transfer(SPI_CS, 0, SPI_CONTINUE);

  }
#else
  for (uint16_t i=0; i<_len; i++)
  {
SPI.transfer(SPI_CS, 0x0F, SPI_CONTINUE);
SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);
SPI.transfer(SPI_CS, _addr & 0xFF, SPI_CONTINUE);
    _buf[i] = SPI.transfer(SPI_CS, 0);
    _addr++;
  }
#endif 
  return _len;
}

void W5100Class::execCmdSn(SOCKET s, SockCMD _cmd) {
  // Send command to socket
  writeSnCR(s, _cmd);
  // Wait for command to complete
  while (readSnCR(s))
    ;
}
11  Using Arduino / Project Guidance / Dual ethernet ports Due on: July 03, 2014, 02:13:42 pm
Good day!

using the modified libraries https://github.com/Wiznet/W5200_Arduino_Ethernet_Lib for the wiz820io chip I found I am successfully able to connect with a single one to the google homepage download demo.


Now I am trying to add a second wiz820io to my Due, and having difficulty figuring out how to make a separate instance of the Ethernet library that can use another SS pin. It seems that the w5100.h file defines the SS_PIN so I'm not sure how to make another one and then tell the sketch that it needs to make another client using the different hardware.

The reason for all this: I have two other devices that need direct connections to and absolutely will not be able to use a switch.

Thanks!



Code:
#include <stdio.h>
#include <string.h>

#include "w5100.h"

// W5100 controller instance
W5100Class W5100;

#define SPI_CS 9

#define TX_RX_MAX_BUF_SIZE 2048
#define TX_BUF 0x1100
#define RX_BUF (TX_BUF + TX_RX_MAX_BUF_SIZE)


12  Using Arduino / Project Guidance / Re: Dual NIC Arduino on: June 29, 2014, 08:42:29 pm
I think it is beyond theory now. I'm testing my new ethernet library function "Ethernet.select()". I can access the ethernet shield with D10 bent and the slave select jumpered to D9, and all works well. It required a few library mods, but not too bad.

Would you like to test it? I can post the changes if you are interested.


I would be interested in what you've found.
Thanks!
13  Using Arduino / Programming Questions / Re: DUE: Reading Serial data into two dimensional array, it skips every other index. on: December 09, 2013, 12:51:54 am
No offense taken. Reading it now, I will try to make it more understandable before resubmitting.
14  Using Arduino / Programming Questions / Re: DUE: Reading Serial data into two dimensional array, it skips every other index. on: December 09, 2013, 12:19:06 am
Dang, I knew there was a way to get the code to interpret the data for you. I will use the ' ' for sure.

With regard to the looping 42 times, I have a break when it detects my "start" char, basically a way to ensure that I am starting at a known point, I realize now though that since I am reading through the data with different letters to index, I can really start anywhere one of those chars exist. Thanks for the pointer there.
Code:
    if (state == 0){
      for(i=0;i<43;i++)
      {
        serialChar = Serial1.read();
        if (serialChar == 32){
          state = 1;
          serialProcess(state);
          break;


Anyway, I am still having the problem here

Code:
                else if ((serialChar != 32) && (serialChar !=255))
                {
Serial.print("Echoing State before print state: ");
Serial.println(state);
Serial.print("Char: ");
Serial.write(serialChar);
                    Serial.print("");
                    serialData[(state-1)][i2] = serialChar;
                    i2++;
                }

This line
                   
Code:
serialData[(state-1)][i2] = serialChar;
Is supposed to put the currently read char at the [state-1][increment] of the char array, but for some reason [state] is doing weird things and data is only getting stored in the 0,2,4 arrays of the the first dimension.
When I do 
Code:
Serial.print("Echoing State before print state: ");
Serial.println(state);
I get matching states with the data they belong to.
15  Using Arduino / Programming Questions / DUE: Reading Serial data into two dimensional array, it skips every other index. on: December 08, 2013, 11:27:31 pm
As the title says I have a two dimensional array that I am attempting to read data into.
byte serialData[6][6]

If you look at the code below the idea is that I'm trying to take this
Quote
 123456B789012C345678D012345E555555F666666
data and parse it. What I am doing appears to work great,
I use the SPACE char at the beginning to start the parse and then the B-F char to split the 6 bytes of data. Each time I get a new alpha char I am incrementing the first index of the array and then taking the data chars into the 2nd index.

When I print the values of serialData[i] I get the below results


Code:
[0]   = 111111
[0][1][2][3][4][5]
[1] = NULL
[0][1][2][3][4][5]
[2] = 222222
[0][1][2][3][4][5]
[3] = NULL
[0][1][2][3][4][5]
[4] = 333333
[0][1][2][3][4][5]
[5] = NULL
[0][1][2][3][4][5]

If I print even farther than I am even defining in the array...
Code:
serialData[6] = 444444
serialData[7] = NULL
serialData[8] = 555555



What the heck am I doing wrong? Why is it incrementing twice?!?

Thank you!


Code:
// State machine values
int state =0;

byte serialData[6][6] = {0};

//serial data
byte serialChar =0;
boolean newData =0;
byte i2 = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Serial 1 Good Morning");
  Serial1.begin(115200);
  Serial1.println("Serial 2 Good Morning");
}

void loop() {
  
          if (Serial1.available() > 42) {
            newData = true;
            Serial.write("***** BEGIN DATA state = ");
            if (state == 0){
              for(i=0;i<43;i++)
              {
                serialChar = Serial1.read();
                if (serialChar == 32){
                  state = 1;
                  serialProcess(state);
                  break;
                }
              }
                      
            }            
          }


          delay(250);
  
  if (newData){
    Serial.write("{t1:");
    Serial.print(serialData[0]);
    
    Serial.write(",t2:");
    Serial.print(serialData[1]);
    
    Serial.write(",t3:");
    Serial.print(serialData[2]);
    
    Serial.write(",lat:");
    Serial.print(serialData[3]);
    
    Serial.write(",lon:");
    Serial.print(serialData[4]);
  
    Serial.write(",rpm:");
    Serial.print(serialData[5]);
  
    Serial.write("}");
    Serial.println("");
    
    newData =false;
  }

}
          
void serialProcess(int st){
      Serial.println("");
      Serial.print("State of: ");
      Serial.println(state);
      for (byte i=0; i<7; i++) {
                serialChar = Serial1.read();

                
                if ((serialChar > 65) && (serialChar < 71)){
                  if (serialChar == 66){state = 2;}
                  if (serialChar == 67){state = 3;}
                  if (serialChar == 68){state = 4;}
                  if (serialChar == 69){state = 5;}
                  if (serialChar == 70){state = 6;}
                  serialProcess(state);
                  i2=0;
                  break;
                }
                else if ((serialChar != 32) && (serialChar !=255))
                {
Serial.print("Echoing State before print state: ");
Serial.println(state);
Serial.print("Char: ");
Serial.write(serialChar);
                    Serial.print("");
                    serialData[(state-1)][i2] = serialChar;
                    i2++;
                }
                else if (serialChar == 13){
                  i2=0;
                  state=0;
                  Serial.println("");
                  Serial.println("***END OF DATA***");
                  break;
                }
      }
      
}


Moderator edit: [code] ... [/code] tags added to debug output. (Nick Gammon)
Pages: [1] 2 3