Show Posts
Pages: 1 2 [3] 4 5 ... 10
31  Using Arduino / Storage / Very large bitmap to SD problem. on: February 15, 2013, 12:02:22 pm
I have a 5" TFT (800x480) w/ SD card (128MB), a Mega 1280 and a Mega 2560 (DUE on the way). I want to save a full screen bitmap to the SD card. However, none of the arduino's have enough memory (RAM or Flash) to store the bitmap to write it to the card. I noticed if I write a small bitmap to the card with the arduino and also write the same file to the card with my PC, it is not the same format. The data in the two files are different. Is there a way I can write a large bitmat to the card with my PC and be able to read the file with the arduino? I have very little experience with SD cards, but I learn quickly.

Thanks for any help,
DJ
32  Development / Other Software Development / Re: External Memory Interface library for the Mega. (can someone review my code?) on: December 31, 2012, 08:37:19 pm
@slomobile
I looked at the data sheet for the AT90USB1286 and the register names are the same so it should work.

DJ
33  Development / Other Software Development / External Memory Interface library for the Mega. (can someone review my code?) on: December 07, 2012, 10:30:00 am
  I've just finished a library to use the External Memory Interface module on the Mega1280/2560. You can use it to access external memory via parallel address/data bus. The address bus width is from 8-bits upto 16-bits and the data bus width is 8-bits. You'll need a 74AHC573 transparent latch to multiplex the Port A address/data lines. I've tested the library with ti's bq3287EA RTC and an Atmel AT28HC256 EEPROM both connected. I could access the RTC as the lower sector and the EEPROM as the upper sector. The library has four functions; enable(), disable(), read() write(). The library can read/write to any valid data type (including string literals) to any external memory address. The lirary zip file is on google code here: http://code.google.com/p/arduino-exmem-library/downloads/list and attached below. If anyone can review my code or better yet test it out and let me know what they think, I would apreciate it. Enjoy! smiley-wink

Thanks for your time,
DigitalJohnson
34  Using Arduino / Programming Questions / Re: Using templates in a library (SOLVED) on: December 06, 2012, 06:33:22 am
@tuxduino
All I need to do is e.g.:
Code:
#include <ExMem.h>

void setup()
{
    Serial.begin(115200);
    ExMem.enable(8, 0x0000, 0, 0);
    char* textToMemory = "Hello World!";
    char* textFromMemory;
    ExMem.write(LOWER, 0x0000, textToMemory); // Will return size of pointer(2).
    ExMem.read(LOWER, 0x0000, textFromMemory); // Will return size of pointer(2).
    Serial.println(textFromMemory);
}

void loop()
{
}

// Will print "Hello World!" to the serial monitor.

The library is on google code here: http://code.google.com/p/arduino-exmem-library/downloads/list. If anyone has the time can you please review or better yet test the library and let me know what you think.

Thanks for your time,
DigitalJohnson
35  Using Arduino / Programming Questions / Re: Using templates in a library (SOLVED) on: December 03, 2012, 07:57:44 pm
@PaulS
I suspected it had to do with the pointer to the string. Thanks for the reply.

@tuxduino
With this library I only need to know the location of the first address of the string. The write function, or I believe the string literal variable I pass to the function already adds the terminating null for me and the function writes all of it to memory. All I have to do to read the string back is pass the read function the first address of the string and an empty string literal variable to hold it. The read function puts every byte from the first address to the null byte into the variable. I only need to know the length of the string when writing to keep track of where the next unused address is at for the next write to avoid overlap.

Thanks guys, you've help me a lot,
DJ

BTW How can I add karma for you.

Never mind, just click on karma. Duh. smiley-roll
36  Using Arduino / Programming Questions / Re: Using templates in a library (SOLVED) on: December 03, 2012, 05:56:49 pm
I've found a small bug. If I pass data type char* to the write function, say char *c1 = "hello world", it will return with a value of 2, meaning it wrote 2 bytes. Then I pass the read function a variable of char*, say char *c2, and read from the same address written to. It also returns with 2, meaning it read 2 bytes. But when I use Serial.print(c2), It prints "hello world" as it should. Why is it returning a value of 2 when it clearly is more. Float returns 4, as do double, long long returns 8, and uint8_t = 1 and uint16_t = 2, all as expected. So what's with char*?

Can anyone shed some light on this?

DJ
37  Using Arduino / Programming Questions / Re: Using templates in a library (SOLVED) on: December 03, 2012, 12:36:32 pm
After I get all the comments back in I'll post it on google code. Enjoy.

DJ
38  Using Arduino / Programming Questions / Re: Using templates in a library (solved(almost)) on: December 03, 2012, 12:24:03 pm
@tuxduino

 smiley-grin Thank you very much! It finally works. As for the double cast, I'm not sure. Copied it from EEPROMWriteAnything. You've been a big help. If there's anything I can do for you...

Thanks again,
DigitalJohnson

PS. I'll share for anyone that can use it.

External Memory library

ExMem.h
Code:
#ifndef EXMEM_H
#define EXMEM_H

#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

#include <inttypes.h>
#include <avr/io.h>

class exmem
{
    public:
    exmem();
    void enable(uint8_t addressWidth = 16,
    uint16_t lowerLimit = 0x0000,
    uint8_t upperSectorWaitState = 0x00,
    uint8_t lowerSectorWaitState = 0x00);
    void disable(void);
    template <class TYPE> uint16_t write(bool sector, uint16_t address, const TYPE &data);
    template <class TYPE> uint16_t read(bool sector, uint16_t address, TYPE &store);
};


extern exmem ExMem;

static uint16_t upperSectorOffset = 0x0000;
static uint16_t upperLimit = 0xFFFF;
static uint16_t upperSize = 0xDE00;
static uint16_t lowerSize = 0xDE00;

exmem::exmem()
{
}

void exmem::enable(uint8_t addressWidth, uint16_t upperSectorBoundry,
uint8_t upperSectorWaitState, uint8_t lowerSectorWaitState)
{
    switch (addressWidth)
    {
        XMCRB &= 0xF8;
        case 8:
        upperLimit = 0x00FF;
        XMCRB = 0x07;
        break;
        case 10:
        upperLimit = 0x03FF;
        XMCRB = 0x06;
        break;
        case 11:
        upperLimit = 0x07FF;
        XMCRB = 0x05;
        break;
        case 12:
        upperLimit = 0x0FFF;
        XMCRB = 0x04;
        break;
        case 13:
        upperLimit = 0x1FFF;
        XMCRB = 0x03;
        break;
        case 14:
        upperLimit = 0x3FFF;
        XMCRB = 0x02;
        break;
        case 15:
        upperLimit = 0x7FFF;
        XMCRB = 0x01;
        break;
        default:
        upperLimit = 0xFFFF;
        break;
    }
    uint16_t boundry;
    if (addressWidth < 15)
    {
        boundry = 0x0000;
    }
    else if (addressWidth < 16)
    {
        boundry = constrain(upperSectorBoundry, 0x0000, 0x6000);
    }
    else
    {
        boundry = upperSectorBoundry;
    }
    XMCRA &= 0x8F;
    switch (boundry)
    {
        case 0x4000:
        upperSectorOffset = 0x1E00;
        XMCRA |= 0x20;
        break;
        case 0x6000:
        upperSectorOffset = 0x3E00;
        XMCRA |= 0x30;
        break;
        case 0x8000:
        upperSectorOffset = 0x5E00;
        XMCRA |= 0x40;
        break;
        case 0xA000:
        upperSectorOffset = 0x7E00;
        XMCRA |= 0x50;
        break;
        case 0xC000:
        upperSectorOffset = 0x9E00;
        XMCRA |= 0x60;
        break;
        case 0xE000:
        upperSectorOffset = 0xBE00;
        XMCRA |= 0x70;
        break;
        default:
        upperSectorOffset = 0x0000;
        break;
    }
    if (0 < upperSectorOffset)
    {
        lowerSize = upperSectorOffset;
        upperSize = ((1 + upperLimit) - (0x2200 + upperSectorOffset));
    }
    else
    {
        lowerSize = upperSize = ((1 + upperLimit) - 0x2200);
    }
    switch (upperSectorWaitState)
    {
        XMCRA &= 0xF3;
        case 1:
        XMCRA |= 0x04;
        break;
        case 2:
        XMCRA |= 0x08;
        break;
        case 3:
        XMCRA |= 0x0C;
        break;
        default:
        break;
    }
    switch (lowerSectorWaitState)
    {
       
        XMCRA &= 0xFC;
        case 1:
        XMCRA |= 0x01;
        break;
        case 2:
        XMCRA |= 0x02;
        break;
        case 3:
        XMCRA |= 0x03;
        break;
        default:
        break;
    }
    XMCRA |= 0x80;
}

void exmem::disable(void)
{
    XMCRA &= 0x7F;
}

template <class TYPE>
uint16_t exmem::write(bool sector, uint16_t address, const TYPE &data)
{
    uint8_t *pExtMemory = reinterpret_cast <uint8_t *> (0x2200);
    const uint8_t *pData = (const uint8_t *)(const void *)&data;
    uint16_t i;
    i = 0;
    if (sector)
    {
        if (address >= upperSize)
        {
            return i;
        }
    }
    else
    {
        if (address >= lowerSize)
        {
            return i;
        }
    }
    for (; i < sizeof(data); i++)
    {
        if (sector)
        {
            uint8_t *pMemory;
            pMemory = (uint8_t *)(pExtMemory + upperSectorOffset + address++);
            *pMemory = (uint8_t)(*pData++);
        }
        else
        {
            uint8_t *pMemory;
            pMemory = (uint8_t *)(pExtMemory + address++);
            *pMemory = (uint8_t)(*pData++);
        }
    }
    return i;
}

template <class TYPE>
uint16_t exmem::read(bool sector, uint16_t address, TYPE &store)
{
    uint8_t *pExtMemory = reinterpret_cast <uint8_t *> (0x2200);
    uint8_t *pStore = (uint8_t *)(void *)&store;
    uint16_t i;
    i = 0;
    if (sector)
    {
        if (address >= upperSize)
        {
            return i;
        }
    }
    else
    {
        if (address >= lowerSize)
        {
            return i;
        }
    }
    for (; i < sizeof(store); i++)
    {
        if (sector)
        {
            uint8_t *pMemory = (pExtMemory + upperSectorOffset + address++);
            *pStore++ = (uint8_t)(*pMemory);
        }
        else
        {
            uint8_t *pMemory = (pExtMemory + address++);
            *pStore++ = (uint8_t)(*pMemory);
        }
    }
    return i;
}

exmem ExMem = exmem();

#endif
39  Using Arduino / Programming Questions / Re: Using templates in a library (solved(almost)) on: December 03, 2012, 11:28:36 am
If I break up the uint16_t type into two uint8_t types and write them seperately. It will read back in a uint16_t type as it should. So, the problem is in the write function. I've almost got it. I'll test some more and post back.

DJ 
40  Using Arduino / Programming Questions / Re: Using templates in a library (solved(almost)) on: December 03, 2012, 10:35:10 am
In the serial monitor, when I run the sketch, I get

1
20
2
0

I should get

1
20
2
256

If I change the second write from uint16_t to uint8_t type it returns correctly. As I stated earlier templates are very confusing to me, but I almost have this working. Frustrating! smiley-yell I really do apreciate any help on this. The functions in question are the last two in the library. The rest of the library works fine.

Again thanks for your time,
DJ
41  Using Arduino / Programming Questions / Re: Using templates in a library (solved(almost)) on: December 03, 2012, 10:31:25 am
Here's the library:
Code:
#ifndef EXMEM_H
#define EXMEM_H

#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

#include <inttypes.h>
#include <avr/io.h>

class exmem
{
    public:
        exmem();
        void enable(uint8_t addressWidth = 16,
        uint16_t lowerLimit = 0x0000,
        uint8_t upperSectorWaitState = 0x00,
        uint8_t lowerSectorWaitState = 0x00);
        void disable(void);
        template <class TYPE> uint16_t write(bool sector, uint16_t address, const TYPE &data);
        template <class TYPE> uint16_t read(bool sector, uint16_t address, TYPE &store);
};


extern exmem ExMem;

static uint16_t upperSectorOffset = 0x0000;
static uint16_t upperLimit = 0xFFFF;
static uint16_t upperSize = 0xDE00;
static uint16_t lowerSize = 0xDE00;

exmem::exmem()
{
}    

void exmem::enable(uint8_t addressWidth, uint16_t upperSectorBoundry,
                   uint8_t upperSectorWaitState, uint8_t lowerSectorWaitState)
{
    switch (addressWidth)
    {
        XMCRB &= 0xF8;
        case 8:
            upperLimit = 0x00FF;
            XMCRB = 0x07;
            break;
        case 10:
            upperLimit = 0x03FF;
            XMCRB = 0x06;
            break;
        case 11:
            upperLimit = 0x07FF;
            XMCRB = 0x05;
            break;
        case 12:
            upperLimit = 0x0FFF;
            XMCRB = 0x04;
            break;
        case 13:
            upperLimit = 0x1FFF;
            XMCRB = 0x03;
            break;
        case 14:
            upperLimit = 0x3FFF;
            XMCRB = 0x02;
            break;
        case 15:
            upperLimit = 0x7FFF;
            XMCRB = 0x01;
            break;
        default:
            upperLimit = 0xFFFF;
            break;
    }
    uint16_t boundry;
    if (addressWidth < 15)
    {
        boundry = 0x0000;
    }
    else if (addressWidth < 16)
    {
        boundry = constrain(upperSectorBoundry, 0x0000, 0x6000);
    }
    else
    {
        boundry = upperSectorBoundry;
    }
    XMCRA &= 0x8F;
    switch (boundry)
    {
        case 0x4000:
            upperSectorOffset = 0x1E00;
            XMCRA |= 0x20;
            break;
        case 0x6000:
            upperSectorOffset = 0x3E00;
            XMCRA |= 0x30;
            break;
        case 0x8000:
            upperSectorOffset = 0x5E00;
            XMCRA |= 0x40;
            break;
        case 0xA000:
            upperSectorOffset = 0x7E00;
            XMCRA |= 0x50;
            break;
        case 0xC000:
            upperSectorOffset = 0x9E00;
            XMCRA |= 0x60;
            break;
        case 0xE000:
            upperSectorOffset = 0xBE00;
            XMCRA |= 0x70;
            break;
        default:
            upperSectorOffset = 0x0000;
            break;
    }
    if (0 < upperSectorOffset)
    {
        lowerSize = upperSectorOffset;
        upperSize = ((1 + upperLimit) - (0x2200 + upperSectorOffset));
    }
    else
    {
        lowerSize = upperSize = ((1 + upperLimit) - 0x2200);
    }
    switch (upperSectorWaitState)
    {
        XMCRA &= 0xF3;
        case 1:
            XMCRA |= 0x04;
            break;
        case 2:
            XMCRA |= 0x08;
            break;
        case 3:
            XMCRA |= 0x0C;
            break;
        default:
            break;
    }
    switch (lowerSectorWaitState)
    {
        
            XMCRA &= 0xFC;
        case 1:
            XMCRA |= 0x01;
            break;
        case 2:
            XMCRA |= 0x02;
            break;
        case 3:
            XMCRA |= 0x03;
            break;
        default:
            break;
    }
    XMCRA |= 0x80;
}

void exmem::disable(void)
{
    XMCRA &= 0x7F;
}

template <class TYPE>
uint16_t exmem::write(bool sector, uint16_t address, const TYPE &data)
{
    uint8_t *pExtMemory = reinterpret_cast <uint8_t *> (0x2200);
    const uint8_t *pData = (const uint8_t *)(const void *)&data;
    uint16_t i;
    i = 0;
    if (sector)
    {
        if (address >= upperSize)
        {
            return i;
        }
    }
    else
    {
        if (address >= lowerSize)
        {
            return i;
        }
    }
    for (; i < sizeof(data); i++)
    {
        if (sector)
        {
            uint8_t *pMemory;
            pMemory = (uint8_t *)(pExtMemory + upperSectorOffset + address++);
            *pMemory = (uint8_t)(*pData);
        }
        else
        {
            uint8_t *pMemory;
            pMemory = (uint8_t *)(pExtMemory + address++);
            *pMemory = (uint8_t)(*pData);          
        }
    }
    return i;
}

template <class TYPE>
uint16_t exmem::read(bool sector, uint16_t address, TYPE &store)
{
    uint8_t *pExtMemory = reinterpret_cast <uint8_t *> (0x2200);
    uint8_t *pStore = (uint8_t *)(void *)&store;
    uint16_t i;
    i = 0;
    if (sector)
    {
        if (address >= upperSize)
        {
            return i;
        }
    }
    else
    {
        if (address >= lowerSize)
        {
            return i;
        }
    }
    for (; i < sizeof(store); i++)
    {
        if (sector)
        {
            uint8_t *pMemory = (pExtMemory + upperSectorOffset + address++);
            *pStore++ = (TYPE)(*pMemory);
        }
        else
        {
            uint8_t *pMemory = (pExtMemory + address++);
            *pStore++ = (TYPE)(*pMemory);
        }
    }
    return i;
}

exmem ExMem = exmem();

#endif

Can someone please tell me why the second read returns incorrectly.

Thanks for your time,
DJ
42  Using Arduino / Programming Questions / Using templates in a library (SOLVED) on: December 03, 2012, 10:29:30 am
I wrote a library for the External Memory interface module on the mega1280/2560. I wanted to incorperate templates into the library so I can pass any type as an argument to the functions. Someone suggested EEPROMWriteAnything from the Arduino Playground. I used the template parts of it in my library. My library and sketch are below. I really don't understand templates. I just copied that part into my library. I got it to compile and work, almost. In the sketch I write to external memory twice. The first time I pass a uint8_t type (20) to the write function, the second time I pass a uint16_t type (256). Then I read back the data from the same two addresses I had written to. In the case of the uint8_t type the data returns correctly (20). In the case of the uint16_t type it returns incorrectly (0).

Here's the sketch:
Code:
#include <ExMem.h>

void setup()
{
    Serial.begin(115200);
    // Enables the interface with two sectors with the upper/lower boundry at 0x8000 and no wait-states
    ExMem.enable(16, 0x8000, 0, 0);
    uint8_t x1 = 20;
    uint16_t y1 = 256;
    ExMem.write(0, 0x0020, x1); // write to lower sector address 0x0020
    ExMem.write(0, 0x0030, y1); // write to lower sector address 0x0030
    // varibles to hold data read
    uint8_t x2;
    uint16_t y2;
    // The function places the data in the supplied variable
    // and returns the number of bytes read.
    Serial.println(ExMem.read(0, 0x0020, x2), DEC);
    Serial.println(x2, DEC);
    Serial.println(ExMem.read(0, 0x0030, y2), DEC);
    Serial.println(y2, DEC);
}

void loop()
{
}

Sorry, I have to post twice, due to the size of the library.
43  Using Arduino / Programming Questions / Re: how to create original interrupts [ ISR() ] on: November 28, 2012, 05:18:47 am
The avrFreaks tutorial above states:
Quote
There are two main sources of interrupts:

Hardware Interrupts, which occur in response to a changing external event such as a pin going low, or a timer reaching a preset value
 Software Interrupts, which occur in response to a command issued in software

The 8-bit AVRs lack software interrupts, which are usually used for special operating system tasks like switching between user and kernel space, or for handling exceptions.

From the ATmega1280/2560 datasheet:
Quote
The External Interrupts are triggered by the INT7:0 pin or any of the PCINT23..0 pins.
Observe that, if enabled, the interrupts will trigger even if the INT7:0 or PCINT23..0 pins
are configured as outputs. This feature provides a way of generating a software
interrupt.

On the arduino (mega1280/2560, I'm not sure of others), there are pins on the MCU that aren't brought out to headers. Some of those pins also serve as interrupt sources. So, if you set one of those pins to output, you can use software to set the state of the pin and trigger an interrupt to occur (hardware interrupt triggered by software). This can also be done with (external interrupt) pins that are brought out to headers. If anyone else has anything to add/corrections, please do.

DigitalJohnson
44  Using Arduino / Programming Questions / Re: Help using templates. on: November 28, 2012, 04:01:46 am
@WizenedEE
You forgot Serial.begin();
To be honest I have no idea how your example works. smiley-confuse I'm not that good at coding yet. But thanks for it anyway. I'll study it some more and see if I can figure it out.

DJ
45  Using Arduino / Programming Questions / Re: Help using templates. on: November 28, 2012, 01:12:52 am
Thanks Nick, that worked. I didn't know the template was part of the function declaration.

Quote
By the time you get to templates, this should be second nature.

Does this mean I'm in over my head?... You're probably right. smiley-razz

Thanks for the replies,
DJ
Pages: 1 2 [3] 4 5 ... 10