Show Posts
Pages: 1 [2] 3 4 ... 121
16  Using Arduino / Programming Questions / Re: Strange error message on: April 15, 2014, 12:29:02 pm
That sketch was just an example, you do not need anything from it.

For the ISR that is having problems, create a prototype for it and add __attribute__ ((section (".text"))).

The function can be where ever you like, and you need to manually add the prototype to add the attribute to as it cannot go on the definition.
17  Using Arduino / Programming Questions / Re: Strange error message on: April 15, 2014, 12:08:37 pm
I do not think an ISR can be put into the init sections, the .initn sections are run like one big function init0-init9 and aren't callable.
You could use v1.5.5 of the IDE and specify a custom location in the command line by editing platform.txt.

However, maybe some good news.

Using the code above I added a .text section to loop() and it moved to the first item.
Code:
__attribute__ ((section (".text"))) void loop();

Without .text
Quote
0000020c 000000a0 t do_random
000002a0 00000006 T random_r
000002a2 0000000a T random
000002a8 00000012 T srandom
000002ba 00000090 T __vector_23
0000034a 00000026 T loop
0000036a 00000012 T main

With .text
Quote
0000020c 00000026 T loop
0000022c 000000a0 t do_random
000002c0 00000006 T random_r
000002c2 0000000a T random
000002c8 00000012 T srandom
000002da 00000090 T __vector_23
0000036a 00000012 T main

Maybe try it on the offending ISR.
18  Using Arduino / Programming Questions / Re: Strange error message on: April 15, 2014, 11:40:19 am
I just had a go myself,
here is a sketch that replicates the Arduino setup, just smaller ( compiled size ).

init is run before setup, just like Arduinos default.

I could have used .init3 for init, however setup must be after .init6 so global libraries can construct. Including wiring.c is just a hack to avoid copying some code.

Code:
int main() __attribute__ ((naked));
__attribute__ ((naked)) __attribute__ ((section (".init7"))) void init();
#include "wiring.c"
__attribute__ ((naked)) __attribute__ ((section (".init8")))  void setup();

int main(){

  #if defined(USBCON)
  USBDevice.attach();
  #endif
 
  while( true ){
    loop();
    if (serialEventRun) serialEventRun();
  }
  return 0;
}

void setup(){

}

void loop(){

}
19  Using Arduino / Programming Questions / Re: Strange error message on: April 15, 2014, 10:50:12 am
BTW is it possible to assign data to an area of memory as pYro_65 suggested in the arduino IDE?

Yes, http://www.nongnu.org/avr-libc/user-manual/mem_sections.html
20  Using Arduino / Programming Questions / Re: Strange error message on: April 15, 2014, 01:10:35 am
Delete the temp compile folder, If I compile for Due then switch to an AVR, the SAM files can sometimes cause errors.

Is this the interrupt: Timer/Counter2 Compare Match B

Can you post the interrupt function.
21  Using Arduino / Programming Questions / Re: Strange error message on: April 15, 2014, 01:03:27 am
Quote
Would it make a difference if I didn't use attachInterrupt() and instead set the registers myself

I do not think so, the linker decides where everything goes, which happens after the code is compiled. This is only a guess, give it  a try.

22  Using Arduino / Programming Questions / Re: Strange error message on: April 15, 2014, 12:40:16 am
Putting the data in far progmem could solve it. The data at the moment is probably sitting between the interrupt vector table and the actual ISR. As the data size is greater than 4Kb, the RJMP, and RCALL instructions fail.

When the data is moved into far memory, the linker could take the opportunity and move the ISR closer, within range.

There are many memory sections available for use, you could possibly declare your ISR to be inside a closer section.
If all else fails, you can use AVR studio /manually edit command lines and specify the locations you want your data sections, even create new ones. A section could be created at the end of near memory for your data, avoiding the far memory overhead, and remaining compatible with current near progmem helper functions.
23  Using Arduino / Programming Questions / Re: Using the .net framework with the arduino on: April 15, 2014, 12:28:13 am
You can write a windows program using .NET to interact with the Arduino. If you want to use the .NET framework on a microcontroller, you should have a look at the .netduino, it is programmed in C#.
24  Using Arduino / Programming Questions / Re: Strange error message on: April 14, 2014, 11:43:46 pm
With a smaller sketch it can still occur.

I did a quick search and someone has posted a nice answer:
The AVR devices support two kinds of jump/call instructions: JMP vs. RJMP, and CALL vs. RCALL. The R variants make calls relative to the current location and are more efficient both in usage of program memory and execution time. This comes at a cost though: RJMP and RCALL can only be used for addresses in the range of +/-4kb from their location in program memory. This is never a problem on devices with no more than 8kb of program memory because the whole 8kb range can be addressed from any location via RCALL or RJMP.

On devices with more than 8kb of program memory, however, this is not true for all possible locations. Therefore, if the linker decides it can put the code to be called within the +/-4kb range from the RJMP/RCALL there will be no problem, but if the linker fails to (re-)locate the code to be within that range, RJMP/RCALL cannot be used to reach the code's new address, the address is thus truncated (just like when doing uint16_t value = 12345; uint8_t truncatedValue = value; in C) and the generated code breaks.

The ISR is called from the vector table using the relative versions.
25  Development / Other Software Development / Re: Save data to file on: April 14, 2014, 11:05:12 pm
HTerm is the best, it has the connect + save data buttons right next to each other. All the main functionality you'd expect is on the main screen.  Nothing to install either, it is one file.

Their homepage below has the download link at the top, it is in german, but the application is in English.
http://www.der-hammer.info/terminal/
 
26  Using Arduino / Programming Questions / Re: Strange error message on: April 14, 2014, 10:15:36 pm
Is your code over or close to 64K, I'll assume it is.

Quote
(.vectors+0x3c): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_15' defined in .text section

Your PROGMEM data ( or simply a large sketch ), like whats defined in Arial_Bold_14.h is pushing some ISR vectors into far memory.

AVR pointers are 16 bits, far memory requires 18 bits to address fully. You can only read half the Mega using conventional pointers.

Your vector is placed in far memory, thus given a 32 bit pointer, however vectors only support 16 bit pointer addresses causing the truncation. The result is, the ISR cannot be reached.

I recently helped someone out with a similar problem, a way to locate the PROGMEM data in far memory instead of the vector can be found here: http://forum.arduino.cc/index.php?topic=232724.msg1680144#msg1680144
27  Using Arduino / Displays / Re: Strange bug with myGLCD.drawBitmap when called 6 times on: April 14, 2014, 09:20:54 pm
Quote
Thank you very much, Pyro.
No worries. smiley

Quote
I'm a newcomer to arduino and to programming and I never heard of near/far Progmem before.
It is quite rare for people to run into the far range of memory ( while using Arduino ), but there is a load of information out there about it.

If you are using loads of images/sprites it may be better to use an SD to store large sets of images.  It is far slower than PROGMEM, but writing them as one large file might speed things up when it comes around to reading the data back.

Not to worry though, at 100k you still have a fair bit of PROGMEM room on a Mega 2560
28  Using Arduino / Displays / Re: Strange bug with myGLCD.drawBitmap when called 6 times on: April 14, 2014, 02:43:04 pm
Creating your own extension to the glcd library makes it easy.

Code:
class GlcdEx : public glcd{
 
  public:
 
    void DrawBitmapFar( uint_farptr_t bitmap, uint8_t x, uint8_t y, uint8_t color= BLACK ){

      uint8_t width, height;
      uint8_t i, j;

      width = pgm_read_byte_far(bitmap++);
      height = pgm_read_byte_far(bitmap++);

      #ifdef BITMAP_FIX
        if( (y & 7) || (height & 7))
        {
        this->FillRect(x, y, width, height, WHITE);
        }
      #endif

      for(j = 0; j < height / 8; j++) {
        glcd_Device::GotoXY(x, y + (j*8) );
        for(i = 0; i < width; i++) {
  uint8_t displayData = pgm_read_byte_far(bitmap++);
  if(color == BLACK)
      this->WriteData(displayData);
          else
            this->WriteData(~displayData);
      }
      }
    }
};

GlcdEx GLCDEX;

byte data0[] PROGMEM = { 3,3,1,2,3,4,5,6,7,8,9 };
byte data1[] PROGMEM = { 3,3,1,2,3,4,5,6,7,8,9 };
byte data2[] PROGMEM_FAR = { 3,3,1,2,3,4,5,6,7,8,9 };

void setup() {
 
    GLCDEX.Init();
    GLCDEX.DrawBitmap( data0, 0, 0 );
    GLCDEX.DrawBitmap( data1, 0, 3 );
    GLCDEX.DrawBitmapFar( GET_FAR_ADDRESS( data2 ), 0, 6 );
}

void loop() {}
29  Using Arduino / Displays / Re: Strange bug with myGLCD.drawBitmap when called 6 times on: April 14, 2014, 02:06:15 pm
Your 6 icons in PROGMEM are 41kb

If your sketch size is close to, or greater than 64kb, you could be pushing certain functions to far into memory.
You can work around it by putting some or all icons into far progmem space ( you are using near progmem space. ), which leaves the near range free for code.

Your 6th icon is most probably removed during compilation when you do not reference it. By adding the myGLCD.drawBitmap it is left in pushing the sketch over 64k.

The code below shows how to read from the FAR PROGMEM range. The GET_FAR_ADDRESS macro converts the 16bit pointer to a 32bit pointer.

Like the SD card option, you probably will have to manually write the image. Or you could modify the glcd function to accept another parameter to decide weather to use near or far progmem.

Code:
//#include <avr\pgmspace.h>

#define GET_FAR_ADDRESS(var)                          \
({                                                    \
    uint_farptr_t tmp;                                \
                                                      \
    __asm__ __volatile__(                             \
                                                      \
            "ldi    %A0, lo8(%1)"           "\n\t"    \
            "ldi    %B0, hi8(%1)"           "\n\t"    \
            "ldi    %C0, hh8(%1)"           "\n\t"    \
            "clr    %D0"                    "\n\t"    \
        :                                             \
            "=d" (tmp)                                \
        :                                             \
            "p"  (&(var))                             \
    );                                                \
    tmp;                                              \
})

#define PROGMEM_FAR  __attribute__((section(".fini7")))

char pgmData[] PROGMEM_FAR = { 'T', 'e', 's', 't', 'i', 'n', 'g', ' ', 'P', 'G', 'M', '\0' };

void setup() {
  Serial.begin( 9600 ); 

  byte c, i =0;
  while( c = pgm_read_byte_far( GET_FAR_ADDRESS( pgmData  ) + i++ ) ){
     Serial.print( ( char ) c );
  }
}

void loop() {}
30  Using Arduino / Programming Questions / Re: How many Sketches can be loaded onto Uno on: April 14, 2014, 12:40:08 pm
A sketch is the Arduino term for project, it can have many files ( .ino, .cpp, .h ). You cannot load multiple whole sketches, however you can combine the functionality into one large sketch.

Each module/component could be implemented in a .h/.cpp combo, you can also write re-usable libraries to extend your projects/sketches.
Pages: 1 [2] 3 4 ... 121