Show Posts
Pages: 1 [2] 3 4 ... 8
16  Products / Arduino Due / Suggestions for SPI api on: June 24, 2013, 03:36:33 pm
I noticed one is working on the SPI api's. I thought this is the moment to post some remarks.

1. Both SPI begin() api's, reset the data mode, bit order and divider to their defaults. This invalidates any previous calls to setDataMode(), setBitOrder() and setClockDivider(). The doc does not state that you should call these setters after begin(), and that would be counter intuitive too. Also there is avr code out there that calls the setters before begin(). Better would be to have begin() set data mode and friends from the values recorded in the mode[], ... data fields. (and initialize these correctly).
 
2. I find the following a bit counter intuitive:
Code:
static const uint8_t SS   = BOARD_SPI_SS0;

I relate the names MISO, MOSI and SCK to SS and therefore I would expect that e.g. SPI.setBitorder(SS, order) is the as SPI.setBitOrder(order), which is not the case.

I would suggest this:
Code:
static const uint8_t SS0   = BOARD_SPI_SS0;
static const uint8_t SS  = BOARD_SPI_DEFAULT_SS ;
(I know it would break some sketches, but now it can still be changed)
 
3. What about two macro's:
for sam:
 
Code:
#define SPI_CLOCK_MIN 1
#define SPI_CLOCK_MAX 255
for avr:
 
Code:
#define SPI_CLOCK_MIN SPI_CLOCK_DIV4
#define SPI_CLOCK_MAX SPI_CLOCK_DIV128

Nothing world shocking but a sketch that just wants to be conservative could use SPI_CLOCK_MAX ant that would compile for sam and avr.


17  Products / Arduino Due / Re: Data loss when sending to native USB port (SerialUSB) on: June 16, 2013, 04:17:35 pm
Did you replace the three files  Stimmer attached to his post?
18  Using Arduino / Microcontrollers / Re: Comparing crunching power or serial troughput of Uno and Micro boards on: June 14, 2013, 04:12:38 pm
Interesting, I did not know the max baudrate is that high, but it is indeed ok with the datasheet.

Time is easily lost if at some point in the chain the arrival of data is not noticed soon enough or not forwarded immediately.
This can be anywhere in the chain: pc -> 16u2 usb -> 16u2 uart -> 328 uart (HardwareSerial.cpp) -> sketch -> 328 uart -> 16u2 uart -> 16u2 usb -> pc

The 328p uart (HardwareSerial.cpp) parts looks ok to me.
The sketch: do you use flush() when sending? Do you use write()?
I would certainly also check out the 16u2 firmware.

What transfer rates do you achieve with my sketch, at 1M baud? Even for this one directional test the chain is already rather long.

I don't have an Uno but can do tests with my Due.
Maybe post your test?
19  Using Arduino / Microcontrollers / Re: Comparing crunching power or serial troughput of Uno and Micro boards on: June 14, 2013, 01:17:53 pm
Quote
I think there are errors in the sketch you uploaded because it doesn't make use of the parameter chunk_size.
Doooooh! Thanks for pointing this out. I edited the post to correct the sketch.

Quote
10 bytes per msec is 10,000 per second which, I think, is about what one would expect at 115200 baud.
Sure. That is normal for an Uno, its uart is the limit. But this thread is about the difference in throughput between a classic arduino and one with native usb (Leonardo, Micro, ... Teensy).

Quote
though I want to send and receive data.
Ok, but I first want to check out the send path, the receive part  (of coarse)  follows a completely different code path.




20  Using Arduino / Microcontrollers / Re: Comparing crunching power or serial troughput of Uno and Micro boards on: June 13, 2013, 03:57:21 pm
I wonder how usb serial port speed compares to the teensy implementation, which is completely different.
Would a teensy owner care to run the test sketch below on a teensy?

Or can I run a sketch comiled for teensy2.0 on my leonardo? Since this sketch needs only the usb controller, no other pins ... I thought this should work and uploaded the hex file as is to my Leo. The sketch seems not to run, well the device is not enumerated...

Here is the sketch. On a Leo it prints results like this:

Leonardo, chunk size 16, sent 4096 bytes in 84 millis (46)KBpsec
Leonardo, chunk size 64, sent 4096 bytes in 74 millis (53)KBpsec


Quote
#define DATA_SIZE  4096

void setup() {
 //Initialize serial and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
}

void loop() {
 
  Serial.println("*** HEADER ***");
  Serial.flush();
 
  test(16);
  test(64);
 
  while(true)
     ; 
}

#ifdef __AVR_ATmega32U4__
#ifdef CORE_TEENSY
  static const char model[] = "Teensy 2.0";
#else
  static const char model[] = "Leonardo";
#endif
#else
  static const char model[] = "not an atmega32u4";
#endif

 
void test(unsigned int chunk_size) {
 
  unsigned long t0, t1;
  unsigned int i;
 
  t0 = millis();
  for (i=0; i<(DATA_SIZE/chunk_size); i++) {
    unsigned char j;
    for (j='!'; j < '!' + chunk_size - 1; j++)
      Serial.write(j);
    Serial.write('\n');
    Serial.flush();
  }
  t1 = millis();
 
  Serial.print(model);
  Serial.print(", chunk size ");
  Serial.print(chunk_size);
  Serial.print(", sent ");
  Serial.print(DATA_SIZE);
  Serial.print(" bytes in ");
  Serial.print(t1-t0);
  Serial.print(" millis (");
  Serial.print(  ((DATA_SIZE / (t1 - t0))  * 1000u) / 1024u );
  Serial.print(")KBpsec");
}

21  Using Arduino / Microcontrollers / Re: Due as ISP Programmer for Leonardo/AtMega32u4 on: June 11, 2013, 03:59:16 pm
Allow me to come up with a solution for what was once the subject of this thread: "Due as ISP Programmer for Leonardo/AtMega32u4": http://petervanhoyweghen.wordpress.com/2013/06/11/arduinoisp-on-the-due
22  Using Arduino / Microcontrollers / Re: ArduinoISP on Arduino DUE on: June 11, 2013, 03:48:12 pm
It works pretty stable now. I have an ArduinoISP sketch that runs out of the box on the Due. There is a mini howto here: http://petervanhoyweghen.wordpress.com/2013/06/11/arduinoisp-on-the-due
23  Using Arduino / Microcontrollers / Re: Comparing crunching power or serial troughput of Uno and Micro boards on: June 10, 2013, 04:09:16 pm
I did some measurements with a (borrowed) usb analyzer. I took the ASCIITable example, changed the baudrate to 115200, compiled it with ide 1.0.5 and uploaded it to a Duemilanove and a Leonardo. (It is a pity I don't have an Uno). 

The dataflow looks like this:

The Duemilanove sends 4974 bytes in 368 msec (13.52KBps). About every msec ~14 bytes get sent.
(The duemilanove has to send more data because the ftdi protocol sends two bytes protocol header upon every chunk of data. So the 14 bytes are only 12 bytes useful payload)

The Leonardo sends 4224 bytes in 151 msec (27.14KBps). About every msec ~30 bytes get sent.

So the native USB is indeed faster, but not spectacularly and nohere near the theoretical upperbound of 12Mbps. 

But actually I expected even worse, I noticed the code in CDC.cpp sends out one byte at a time, but fortunately the lower level puts the single bytes into the hw fifo. When the fifo is full, it gets send out as one chunk over USB.

The chunks are 64 bytes (max packet size) (not 256). No idea why I see only 30 bytes. Will do a test sending out 1 byte in loop to avoid effects/delays imposed by formatting code...

More importantly the fifo is flushed only once per frame of1 msec. The analyzer shows that the host is polling ~75 times more for new data during the rest of the frame...  I think this is the first place to look for improvements
24  Using Arduino / Microcontrollers / Re: Comparing crunching power or serial troughput of Uno and Micro boards on: June 07, 2013, 02:50:06 pm
On the other hand, using the micro's native USB there is no real uart in the game that is normally the bottleneck.

I think the core's implementation for sending from the arduino is simple but not optimized. WIth a little tweaking I expect this can be made much faster than the classic uart.

Can you tell us how at what pace data becomes available, and how many bytes it are? Then with a simple sketch we could measure performance difference real uart versus virtual com port over native usb.

25  Using Arduino / Microcontrollers / Re: Auto-reset not working on modified Leonardo bootloader on: June 05, 2013, 03:42:08 pm
Once the sketch runs, the usb code from the core is in action, not that from the bootloader.
Does the board show up correctly in device manager once the sketch runs?

The autoreset code is in CDC.cpp. You might want to instrument it to see whether linestate changes whilst baud rate is 1200bps.

Auto reset uses the watchdog timer. I think this needs the WDTON fuse bit. Compare high fuse byte against what is in boards.txt: 0xd8.
26  Products / Arduino Due / Re: SPI.end() causes SPI.transfer() to hang even after a new SPI.begin() on: June 04, 2013, 05:11:57 pm
Almost, the initcb() (which is SPI_0_Init()) has to be called too.
Thanks!
27  Products / Arduino Due / Re: SPI.end() causes SPI.transfer() to hang even after a new SPI.begin() on: June 04, 2013, 03:00:20 pm
I am using the old AVR compatible api's.
I can confirm the above work around works for me too.

But after calling SPI.end(), I want to tristate SCK and MOSI. How do I do that? I tried adding
Code:
pinMode(MOSI, INPUT);
pinMode(SCK, INPUT);
But after that SPI.begin() does not work anymore.
I dare not configuring them as output before calling SPI.begin() because I noticed that SPIClass::begin() does not have code in it to do so, that is probably done for a reason.
28  Using Arduino / Microcontrollers / Re: Due as ISP Programmer for Leonardo/AtMega32u4 on: June 04, 2013, 02:40:08 pm
@coolf: I normally use linux, but for verification I tried the command line myself on windows 7 SP1 64bit.
As  explained we can use the avrdude (and later the leo bootloader) from the 1.0.3 ide:
Code:
arduino-1.0.3\hardware\tools\avr\bin>avrdude.exe -C ..\etc\avrdude.conf -c arduino -P COM10 -p m32u4  -U signature:r:test.hex:h

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude.exe: Device signature = 0x1e9587
avrdude.exe: reading signature memory:

Reading | ################################################## | 100% 0.04s

avrdude.exe: writing output file "test.hex"

avrdude.exe: safemode: Fuses OK

avrdude.exe done.  Thank you.
29  Using Arduino / Microcontrollers / Re: Due as ISP Programmer for Leonardo/AtMega32u4 on: June 04, 2013, 02:13:24 pm
@reinaldoaff: just specify 255 instead.
(actually I noticed it gets overwritten anyway by SPI::begin(), so we'll be spi!ing at 4MHz anyway, but this is ok, it works)
30  Using Arduino / Microcontrollers / Re: Due as ISP Programmer for Leonardo/AtMega32u4 on: June 04, 2013, 11:08:24 am
Don't give up.
I have the same Due and the same Leo, if it works for me it must work for you too.

Try to work incrementally. First make isp work from the command line.
Go to the arduino-1.5.2/hardware/tool directory and enter this command:
Code:
avrdude.exe -C avrdude.conf -c arduino -P YOURDUECOMPORT  -p m32u4 -vvvv -U signature:r:test.hex:h

I assume you use the native usb port.

Post the output here.
Pages: 1 [2] 3 4 ... 8