Show Posts
Pages: 1 [2]
16  Using Arduino / Programming Questions / Re: Value differs for static / nonstatic function on: September 21, 2011, 08:25:26 pm
Apparently this is caused by Arduinos IDE not using -fno-split-wide-types with avr-gcc 4.5.3
Adding that optimizer flag resolves all problems.

Does anyone know how that could be the reason? Arduinos IDE should really have a config value to enter own CFLAGS.
17  Using Arduino / Programming Questions / Re: Value differs for static / nonstatic function on: September 18, 2011, 02:59:58 pm
Sorry, maybe i wasn't entirely clear in that section.

This is the code that should work, but doesnt:
Code:
uint16_t res = W5100.readSnRX_RSR(0);

This is the code that works:
Code:
uint16_t res = W5100.readSn(0, 0x0026);
res = (res << 8) + W5100.readSn(0, 0x0026 + 1);

readSnRX_RSR is defined as the two lines in the lower code block. Makes sense?
18  Using Arduino / Programming Questions / Value differs for static / nonstatic function on: September 18, 2011, 02:10:26 pm
Hey guys,

I'm programming for over 10 years now already, but I never saw this one. What I want to do, is run the WebServer example for the W5100 chip that is included in the standard Arduino IDE. The only difference is that I'm using my own bootloader, which I will make public soon, that allows you to upload sketches to the Arduino Ethernet via LAN.

The uploading works like a charm so far, but if I try to use the W5100 chip outside of the bootloader, here in the WebServer example, it doesn't work anymore. I can ping it, I can connect to it, but I get no reply.
After some debugging I found, that client.available() returns 1024-1280 before any read, even tho I'm only connection with telnet and not sending a single byte. The number goes down till it reaches 1024 when it will jump to 1280 and start over.

I traced the problem down to this:
Code:
uint16_t res = W5100.readSnRX_RSR(0);
// res is now 1024

res = W5100.readSn(0, 0x0026);
res = (res << 8) + W5100.readSn(0, 0x0026 + 1);
// res is now 0 as it should be

The lower part is the actual readSnRX_RSR(0) function.
So I defined my own function:
Code:
uint16_t readTest(SOCKET _s)
{
    uint16_t res = W5100.readSn(_s, 0x0026);                     
    res = (res << 8) +W5100. readSn(_s, 0x0026 + 1);             
    return res;         
}

uint16_t res = readTest(0); // returns 1024

If I change the definition of the function slightly, by adding the static keyword:
Code:
static uint16_t readTest(SOCKET _s)
then it returns 0 as it's supposed to.

Does anyone have a good suggestions what might cause this?
Note: I'm using a slimmed version of w5100.h/.c and socket.h/.c in the bootloader as well.

Thanks!
19  Using Arduino / Interfacing w/ Software on the Computer / Re: Redirecting serial port to PC via RedFly WiFi shield on: September 09, 2011, 06:48:52 pm
Ok, I think I've gotten closer to it. Maybe somebody can tell me, why the Arduino that I'm trying to program doesn't reply at all.

I connected TX/RX on the "master" to RX/TX on the "slave", ground +5V obvious, CTS to ground and DTR to digital pin 4.

Here's my code:
Code:
#include <RedFly.h>
uint8_t serversock, sock;

void setup()
{
  // virtual reset pin
  pinMode(4, OUTPUT); // reset pin for arduino / DTR on FTDI header
  digitalWrite(4, HIGH);

  //init the WiFi module on the shield
  /* wlan init is irrelevant => removed */
}

uint8_t buf[200];
int bp = 0;
bool resetDone = false;

void loop()
{
  /* read data from WiFi to buf - removed for easier read */
 
  RedFly.disable(); // disable WiFi card
  Serial.begin(115200); // change baudrate to Arduino bootloader baudrate

  // buffer pos != 0 -> data received   
  if (bp != 0)
  {
    if (!resetDone)
    {
      // reset slave before sending first data
      digitalWrite(4, LOW);
      delay(200);
      digitalWrite(4, HIGH);
      resetDone = true;
    }
   
    // print received buffer to boatloader
    for (int i = 0; i < bp; i++)
      Serial.print(buf[i], BYTE);
   
    bp = 0;
    // wait a bit for a reply
    delay(100);

    // read reply from bootloader
    while (Serial.available())
      buf[bp++] = Serial.read();
  }

  // change serial back to WiFi cards speed 
  Serial.begin(9600);

  // enable wifi card
  RedFly.enable();

  // we received data from bootloader -> send it via WiFi
  if (bp != 0)
    RedFly.socketSend(sock, buf, bp);
   
  // wait a bit for a reply
  delay(100);
}

The data from WiFi (the first bytes from avrdude, namely 30 20) gets received and redirected at the right baudrate, I checked that. But the bootloader does not respond.

What am I doing wrong?

Thx for any help!

PS:
Code:

~ $ avrdude -C/usr/share/arduino/hardware/tools/avrdude.conf -q -q -patmega328p -carduino -Pnet:192.168.0.178:19999 -b115200 -D -Uflash:w:wlanprog.cpp.hex:i -vvvv

avrdude: Version 5.10, compiled on Jun 29 2010 at 21:09:48
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/usr/share/arduino/hardware/tools/avrdude.conf"
         User configuration file is "/home/emmo/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : net:192.168.0.178:19999
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
ioctl("TIOCMGET"): Invalid argument
ioctl("TIOCMGET"): Invalid argument
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
ioctl("TIOCMGET"): Invalid argument

PPS:
Master = Arduino Uno w/ RedFly shield
Slave = Arduino Ethernet
20  Using Arduino / Interfacing w/ Software on the Computer / Redirecting serial port to PC via RedFly WiFi shield on: September 07, 2011, 08:10:11 pm
Hey guys,

I have a couple of Arduinos in different projects and I would like to be able to update them without unplugging them from their locations and bring them to my PC to upload new sketches.
For that reason, I want to be able to use one of my Arduino Unos with a RedFly WiFi shield from Watterott to proxy the data for me: the "master" Uno with the WiFi shield is connected to the "slaves" Arduinos FTDI (or ISP) header.

Now I would like to just click on upload in the Arduino IDE and have the data be sent to the master via WiFi which will send the data straight to the slave and program it via FTDI.

For that I want to use "socat" (I'm using linux) to create a fake serial port that sends everything to the ip & port of my master, but I can't seem to get that to work at all. I would be happy for now if I could even get avrdude to talk to my master using -Pnet:192.68.0.178:19999, but it only tells me that it times out after it connected.

I'm struggling to understand how the sketch on the master would have to look like. So far I used a simple sketch: read WiFi -> send on Serial (RX/TX connected to FTDI), read on Serial -> write on WiFi. But that apparently isn't enough. I also tried running the BitLash telnet example but had no success as well (I rewrote it to work(?) with the RedFly lib, which is very similar to the Ethernet lib).

So does anyone have tips for me how I could get this running? I already tried googling all over the place for 3 days now, but wasn't able to find something that worked.

Thanks!
21  Using Arduino / Programming Questions / Re: Ethernet lib conflicting with ADC interrupts on: September 06, 2011, 04:37:58 am
Ahh I managed by now, your tip with the buffer helped me realize that I should use two buffers at least.

Here's my code if anyone's interested. It basically can be used as a network osciloscope or to record audio over network. Sampling rate is ~ 53kHz with the applied settings.
Still a nonfinished code tho, so use at own risk.

Code:
#include <SPI.h>
#include <Ethernet.h>
#include <utility/w5100.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0, 177 };
byte gw[] = { 192,168,0, 1 };

#define DATA_BUFFER_SIZE 512
uint8_t buffer2[2][DATA_BUFFER_SIZE];
int bytes = 0;
int active = 0;

// Initialize the Ethernet server library
Server server(18844);

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

void addToBuffer(SOCKET s, volatile uint8_t * buf, uint16_t len)
{
  // copy data
  W5100.send_data_processing(s, (uint8_t *)buf, len);
}

void sendBuffer(SOCKET s)
{
  W5100.execCmdSn(s, Sock_SEND);
}

volatile bool needSend[2] = { false, false };
// ADC interrupt
ISR(ADC_vect)
{
  buffer2[active][bytes++] = ADCH;
 
  // buffer filled -> change buffer
  if (bytes == DATA_BUFFER_SIZE)
  {
    bytes = 0;
    needSend[active] = true;
    active = active ? 0 : 1;
  }
}

void setup()
{
  // start the Ethernet connection and the server: 
  Ethernet.begin(mac, ip, gw);
  server.begin();
 
  interrupts();

  // ADC setup (see atmega datasheet for reference)
  sbi(ADCSRA, ADEN);
  cbi(ADCSRA, ADSC);
  sbi(ADCSRA, ADATE);
  cbi(ADCSRA, ADIF);
  sbi(ADCSRA, ADIE);
  sbi(ADCSRA, ADPS2);
  cbi(ADCSRA, ADPS1);
  cbi(ADCSRA, ADPS0);
 
//  sbi(ADCSRB, ??);
  cbi(ADCSRB, ACME);
//  sbi(ADCSRB, ??);
//  sbi(ADCSRB, ??);
//  sbi(ADCSRB, ??);
  cbi(ADCSRB, ADTS2);
  cbi(ADCSRB, ADTS1);
  cbi(ADCSRB, ADTS0);
 
  cbi(ADMUX, REFS1);
  sbi(ADMUX, REFS0);
  sbi(ADMUX, ADLAR);
  //sbi(ADMUX, ??);
  cbi(ADMUX, MUX3);
  cbi(ADMUX, MUX2);
  sbi(ADMUX, MUX1);
  sbi(ADMUX, MUX0);
 
  // start measuring
  sbi(ADCSRA, ADSC);
}

int nonactive;
void loop()
{
  nonactive = active ? 0 : 1;
 
  if (needSend[nonactive])
  {
    addToBuffer(0, buffer2[nonactive], DATA_BUFFER_SIZE);
    sendBuffer(0);
    needSend[nonactive] = false;
  }
}
22  Using Arduino / Programming Questions / [solved] Howto build a network sound recorder / osciloscope on: September 06, 2011, 02:13:36 am
Hey guys,

I'm currently trying to write an audio recorder on the Arduino Ethernet, that streams data from it's A3 input to a network client.
So far I changed the prescaler of the ADC to get a higher sample rate (currently ~40kHz), also using interrupts for the ADC, to speed up the process.

It works pretty nicely together with a little program that I coded in Qt, to print out the results.

But unfortunately the interrupts from the ADC conflict with the Ethernet libs Server::write function, so that the Arduino crashes after sending the first packet of data (I'm buffering 1024 bytes before sending).

This code stopped it from crashing:
Code:
noInterrupts();
bufferPos = 0;
server.write(buffer, BUFFERSIZE);
interrupts();

But this causes my data to have little holes, which lead to a noise and distortion in the audible signal.

How can I speed up the write process? Shouldn't it simply be a simple buffer copy and send command? Why does it crash if I don't protect it from interrupts?

Thx,
Emmeran

23  Using Arduino / Programming Questions / Re: [solved] ADC Free Running Mode in ATMEGA 328 on Arduino Ethernet not working on: September 06, 2011, 02:06:15 am
Seems like the registers of the atmega 328 aren't aligned with the 8 bit grid.

Using the makros sbi & cbi for all flags of ADCSRA I was able to achieve using the ADC with interrupts.

Thx for your help, guys!
24  Using Arduino / Programming Questions / Re: ADC Free Running Mode in ATMEGA 328 on Arduino Ethernet not working on: September 05, 2011, 10:43:05 pm
Thanks a lot for pointing that out. This did not change anything tho; I already removed sbi & cbi completely.

I stripped the code to the bare minimum:
Code:
const int debugPin = 9;
void dbg(int del, int num = 1)
{
  for (int i = 0; i < num; i++)
  {
    digitalWrite(debugPin, HIGH);
    delay(del);
    digitalWrite(debugPin, LOW);
    delay(del);
  }
}

bool test = true;
ISR(ADC_vect)
{
  test = true;
}

void setup()
{
  pinMode(debugPin, OUTPUT);
  interrupts();

  ADCSRA = ADEN | ADATE | ADIE | ADPS2 | ADPS1 | ADPS0;
  ADCSRB = 0;
  ADMUX = REFS0 | ADLAR | MUX1 | MUX0;

  ADCSRA |= ADSC;
}

void loop()
{
    if (test)
    {
      test = false;
      dbg(100, 5);
    }
}

Maybe someone can test how this code works on their Arduino. Mine blinks 5 times then never again. (i.e. no measurement is done)
25  Using Arduino / Programming Questions / Re: ADC Free Running Mode in ATMEGA 328 on Arduino Ethernet not working on: September 05, 2011, 07:37:57 pm
Sorry, I uploaded the wrong code. This one should be easier to understand (edited original post)

I can't use serial tho, since I use the Arduino Ethernet which doesn't have a USB plug. I'm using the LED to test stuff.
26  Using Arduino / Programming Questions / [solved] ADC Free Running Mode in ATMEGA 328 on Arduino Ethernet not working on: September 05, 2011, 06:08:07 pm
Hey guys,

I'm trying to get the ADC on the Arduino Ethernet (atmega 328) to run in "Free Running Mode" (i.e. sample continuously without being asked to).
Basically I want to record a audio signal with at least 10kHz sampling rate and send out that information via Ethernet. So far I've achieved only 6300 Sa/s.

I'm setting the ADATE bit in the control register A and start the measurement (control register B is set to 0). It makes one ADC measurement and then just stops.
Here's my code:
Code:
// declarations removed to make this smaller
#define DATA_BUFFER_SIZE 1024
uint8_t buffer2[DATA_BUFFER_SIZE];
int bytes = 0;

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(18844);

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= ~_BV(bit))

// blink with "del" ms delays "num" times
void dbg(int del, int num = 1)
{
  for (int i = 0; i < num; i++)
  {
    digitalWrite(debugPin, HIGH);
    delay(del);
    digitalWrite(debugPin, LOW);
    delay(del);
  }
}

bool test = false;
// ADC interrupt, called when ADC finished measurement
ISR(ADC_vect)
{
  buffer2[bytes++] = ADCH;
  test = true;
}

// start conversion
void analogStart(unsigned char pin)
{
  //ADMUX = (ADMUX & 0xf0) | pin;

  sbi(ADCSRA, ADSC);
}

void setup()
{
  // set pins to output (irrelevant)
  pinMode(pin_relais1, OUTPUT);
  pinMode(pin_relais2, OUTPUT);
  pinMode(debugPin, OUTPUT);
  
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gw);
  server.begin();

  // enable interrupts
  interrupts();

  //analogSetup(4, 1, 1);
  // enable ADC
  // enable external triggers
  // enable interrupts
  // set prescaler to 16
  ADCSRA = ADEN | ADATE | ADIE | ADPS2;
  
    // free running mode
  ADCSRB = 0;
  
  // set reference, left adjust and channel to 3 ( 0 0 1 1)
  ADMUX = REFS0 | ADLAR | MUX1 | MUX0;

  delay(1);

  // start ADC
  analogStart(3);
}

void loop()
{
/*part of code removed for shorter code*/
  
    if (test)
    {
     // blink once for debug purposes
      dbg(100, 1);
      test = false;
    }
      
    if (bytes == DATA_BUFFER_SIZE)
    {
      bytes = 0;
      server.write(buffer2, DATA_BUFFER_SIZE);
    }
}

Thanks for any help,

I already tried lots of stuff, but nothing seems to work.
Pages: 1 [2]