Show Posts
Pages: 1 2 3 [4] 5 6 ... 10
46  Using Arduino / Programming Questions / Help using templates. on: November 26, 2012, 06:53:02 am
I'm trying to learn templates. smiley-confuse I've been reading a tutorial (Web page: http://www.codeproject.com/Articles/257589/An-Idiots-Guide-to-Cplusplus-Templates-Part-1 ). I copied an example from the tutorial but when I compile I get an error: 'TYPE' does not name a type, it highlights the error line as the first line, the line declaring the template.

Here's my sketch:
Code:
template<class TYPE>
TYPE Add(TYPE n1, TYPE n2)
{
    TYPE result;
    result = n1 + n2;
    return result;
}

void setup()
{
    float x = 2.1;
    float y = 5.6;
    Serial.begin(115200);
    Serial.println(Add(x, y));
}

void loop()
{
}

I thought the purpose of using a template (in this case) was so you didn't have to (explicitly) name a type. Can someone help me understand why I'm getting an error and the author of the tutorial (obviously) is not.

Thanks for your time,
DJ
47  Using Arduino / Programming Questions / Re: A simple question about timers & pin usage. on: November 21, 2012, 09:39:05 pm
Thanks Nick. I guess it's time to learn all about timers.  smiley-eek-blue
I'll do some research and see if I can get all the parts to play nice with each other. If so, I'll post some code for others' in need.

Thanx,
DJ
48  Using Arduino / Programming Questions / Re: A simple question about timers & pin usage. on: November 21, 2012, 01:50:02 pm
Now that I've thought about it, I suppose I could set up software timers using micros() or millis() and poll them.

DJ
49  Using Arduino / Programming Questions / Re: A simple question about timers & pin usage. on: November 21, 2012, 01:46:09 pm
I've got a mega2560 and, believe it or not, I'm using almost every pin. I want to use a timer for timing events between some of the hardware I have attached. The thing is, all of the timer compare match pins are used by hardware devices. Is there any way to use a timer and not have it output on it's related compare match pins?

Thanks for your time,
DJ
50  Using Arduino / Programming Questions / A simple question about timers & pin usage. on: November 21, 2012, 12:56:06 pm
Is it possible to use a timer without affecting any pins?

Thanks for any replies,
DJ
51  Using Arduino / Installation & Troubleshooting / Re: Upload Timeout Error on Mega 2560 - Not Sure What Changed on: November 15, 2012, 12:04:22 pm
I'm having the same problem as Ragnar. Burn a new bootloader, upload one sketch. Then can't upload again (just hangs). Burn bootloader, upload one sketch... Has anyone found the problem or a fix. I'm using Mega2560 R1 and IDE1.0.2 on Windows 7 x64.

DJ
52  Community / Exhibition / Gallery / Re: How to configure the Atmel AVRISP MKii to work with Arduino IDE on: November 10, 2012, 03:10:13 pm
@retrolefty

As velocity101 said, it will not provide power. From reading the user guide
Quote
The Atmel AVRISP mkII supports target voltages from 1.8V up to 5.5V.

Note
VCC must be connected to the target board in order to get correct operation and voltages on the ISP/PDI lines. VCC does not draw any power from the target.
In fact, the AVRISP mkII will not detect the target until it (the target) is powered. Also (I can't find the quote right now), I read somewhere in the user manual that the programmer senses the target voltage and adjusts its self by level shifting to the correct voltage. I do know when you enter the programming dialog it displays the current target voltage.

Hope this info helps.

BTW I was here a few days ago and found a thread on how to get the Arduino core to work under Atmel Studio 6. I followed the instructions and it worked! For me anyway. But after messing around a bit, I'm having some minor troubles. So, I need to find that thread (that's what I was doing when I came upon this thread) and follow the steps again. It's really cool  smiley-cool having all those libraries playing nicely with a full featured IDE with debugging capabilities.  smiley-grin

So, I'm off to search...
DigitalJohnson
53  Development / Other Software Development / Re: New option for HardwareSerial library. on: October 02, 2012, 05:51:16 pm
Changes... Done. I was going to use RX_AND_TX, but then someone might mistake the AND to mean the logical (RX & TX). So, I used RX_TX as suggested.

Thanks for the tips Mike.
DJ
54  Development / Other Software Development / Re: New option for HardwareSerial library. on: October 01, 2012, 04:29:48 pm
Fair enough answer. Will do. smiley

By the way, any suggestions on name of the third choice? Trying to keep it short and simple, like the other two. I don't know why, but I'm having a massive brain fart right now, can't come up with a simple, short name. smiley-confuse

As a side note, to those that can, this seems like an easy change to the library that gives a very useful option. Maybe on the next build...?

Thanks,
 DJ
55  Development / Other Software Development / Re: New option for HardwareSerial library. on: October 01, 2012, 03:56:48 pm
@drjiohnsmith

Thanks, believe it or not, I was running low on available pins on my mega (big project). Need is the mother of...

@MichaelMeissner

I could do that. However, the way it is now, calling Serial.begin(baudrate) without the extra parameter behaves as it normally would. What would be the point of having a #define you don't need to use? I'm not saying it's a bad idea. Being a GOD member I'm sure you've been doing this far longer than I. I always like to learn. So, if it's not to much to ask, what is the benifit of the extra #define?
56  Development / Other Software Development / New option for HardwareSerial library. on: September 30, 2012, 10:40:35 pm
I made a small tweak to the HardwareSerial library (IDE 1.0.1) to have the ability to use only RX, only TX, or both RX and TX (normal operation). The modifications are very simple and easy to use. I've shown the modifications below. Make a copy of Arduino.h, HardwareSerial.h and HardwareSerial.cpp located in folder \arduino-1.0.1\hardware\arduino\cores\arduino\ and save them to a folder somewhere so if you screw up you can copy the old files back to the original folder.

Make the changes where indicated to the files below.

Arduino.h
Code:

// Place the three statements below somewhere around line 20
// with the other #define's that are listed there.

#define RX_TX 0
#define RX_ONLY 1
#define TX_ONLY 2


HardwareSerial.h
Code:

// Change the declaration below (at line 52)
  void begin(unsigned long);

// To this
  void begin(unsigned long, uint8_t mode = RX_TX);


HardwareSerial.cpp
Code:

// Change the definition below (at line 294)
void HardwareSerial::begin(unsigned long baud)

// To this
void HardwareSerial::begin(unsigned long baud, uint8_t mode)

// Located at the end of the same function (above)
// Replace the statements below (at lines 328, 329, 330)
  sbi(*_ucsrb, _rxen);
  sbi(*_ucsrb, _txen);
  sbi(*_ucsrb, _rxcie);

// With these
  switch (mode)
  {
  case 1:
    sbi(*_ucsrb, _rxen);
    cbi(*_ucsrb, _txen);
    sbi(*_ucsrb, _rxcie);
    break;
  case 2:
    cbi(*_ucsrb, _rxen);
    sbi(*_ucsrb, _txen);
    cbi(*_ucsrb, _rxcie);
    break;
  default:
    sbi(*_ucsrb, _rxen);
    sbi(*_ucsrb, _txen);
    sbi(*_ucsrb, _rxcie);
    break;
  }


If you want keyword highlighting for the new constants, you can add a few lines to \arduino-1.0.1\lib\keywords.txt file, though it is not neccesary.

keywords.txt
Code:

// Right after the line below (at line 1)
# LITERAL1 specifies constants

// Place these three lines (Use tabs here, NOT spaces)
RX_TX
RX_ONLY LITERAL1 Serial_begin
TX_ONLY LITERAL1 Serial_begin


To use the new changes, it's a simple addition to Serial.begin().

Example:
Code:

// Functions the same as it always has
// The receive pin (RXDn) and transmit pin (TXDn) are both controlled by HardwareSerial
Serial.begin(115200);

// Functions the same as above
Serial.begin(115200, RX_TX);

// Only the receive pin (RXDn) is controlled by HardwareSerial
// The transmit pin (TXDn) is free to use as digital I/O
Serial.begin(115200, RX_ONLY);

// Only the transmit pin (TXDn) is controlled by HardwareSerial
// The receive pin (RXDn) is free to use as digital I/O
Serial.begin(115200, TX_ONLY);


I've tested this succesfully using IDE 1.0.1 and the Mega1280/2560 on Serial ports 1, 2 and 3. I think I need to connect two arduinos to check port 0. If someone could test this out and let me know, maybe we could get this in the next build. smiley-wink

Thanks for your time,
DigitalJohnson
57  Using Arduino / Project Guidance / Re: Question about serial ports. on: September 30, 2012, 12:59:42 am
I'm using the three other serial ports to receive serial data on each of them. I'll have a look at the library and see if I can modify it for RX only as well as TX only. If I get the modification to work, maybe I'll submit for inclusion in standard libraries.

Thanks for the replies,
DJ
58  Using Arduino / Project Guidance / Question about serial ports. on: September 29, 2012, 04:10:48 pm
I am using an Arduino Mega. I was wondering if it is possible to use the RX on a serial port while not using the TX. In other words I'd like to use the TX pin for something else and I'm only using the serial port to receive and don't need to transmit. Is this possible?

Thanks for any replies,
DigitalJohnson
59  Using Arduino / Programming Questions / Re: Mega External Memory Interface Library on: September 28, 2012, 08:07:59 pm
These comments were in the .cpp file.

Code:
////////////////////////////////////////////////////////////////////////////////
// This Library is written for the Arduino Mega 1280/2560. See the ATmega1280/
// 2560 data sheet on how to connect your hardware to the External Memory
// Interface of the ATmega. I have successfully tested this library with a
// Mega1280 and the texas instramens bq3287EA Real-Time Clock. I used a 74ACH573
// transparent latch between the mega and the RTC as per the data sheet. I tied
// the AD7:0 pins from the mega(pins 22-29) to the AD7:0 pins of the RTC
// (pins 4-11). I also tied AD7 of the mega(pin 29) to D7 of the latch. Then I
// tied the EXTRAM pin of the RTC to the Q7 output of the latch to access the
// upper 128 bytes of ram on the RTC. Use the ExMem.enable() function to set up
// and turn on the External Memory Interface. I used enable(8, 0x0000, 1, 0)
// for my tests, (8 = 8 bit addressWidth, 0x0000 = only an upper sector,
// 1 = 1 wait-state(upper sector), 0 = 0 wait-state (lower sector)). If there's
// only an upper sector, you can omit the last parameter.
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
// You can have two different wait-state settings if needed. (eg. Two
// hardware devices each having different timing specs). If only one wait
// state setting is needed use the default(0x0000). Otherwise entering a
// valid value creates an upper and a lower sector, each having it's own
// wait-state set with the enable() function. If the default is used there
// is only an upper sector. However, both "Upper" and "Lower" functions can
// still be used, as they will have the same effect.
////////////////////////////////////////////////////////////////////////////


60  Using Arduino / Programming Questions / Re: Mega External Memory Interface Library on: September 28, 2012, 08:06:16 pm
Here's the .cpp file,

ExMem.cpp:
Code:
ExMem.cpp:
[code]

// ExMem.cpp created for project ExMem Library on 09/17/2012 05:49:06

#include "ExMem.h"

// Pointer to first External Memory address.
uint8_t volatile *pExtMemory = reinterpret_cast <uint8_t volatile *> (0x2200);

// Offset from start of ext. memory(*pExtMemory) to start of upper sector.
static uint16_t upperSectorOffset = 0x0000;

// Highest accessable address.
static uint16_t upperLimit = 0xFFFF;

// Sector size = Highest valid address + 1.
static uint16_t upperSize = 0xDE00;
static uint16_t lowerSize = 0xDE00;

exmem::exmem()
{
}

// Using enable() with no parameters selects the default parameters.
// Any invalid value results in the default value being set.

// Valid addressWidth values =
// 8, 10, 11, 12, 13, 14, 15, 16(default)

// Valid upperSectorBoundry values =
// NONE(default), 0x4000, 0x6000, 0x8000, 0xA000, 0xC000, 0xE000
//     *note    NONE(default) = NO lower sector

// Valid wait-state values for Upper and Lower sectors = 0(default), 1, 2, 3
// 0 = no wait-states
// 1 = 1 wait-state for read/write
// 2 = 2 wait-states for read/write
// 3 = 2 wait-states for read/write plus 1 wait-state after address to bus

void exmem::enable(uint8_t addressWidth, uint16_t upperSectorBoundry,
                               uint8_t upperSectorWaitState, uint8_t lowerSectorWaitState)
{
    // Release unused address pins from Port C
    switch (addressWidth)
    {
        // Clear External Memory High Mask register bits
        XMCRB &= 0xF8;
        case 8: // Releases all Port C pins (Mega pins 30-37)
            // Set highest accessable memory address
            upperLimit = 0x00FF;
            // Set External Memory High Mask register bits
            XMCRB = 0x07;        
            break;
        case 10: // Releases Port C7-C2 (Mega pins 30-35)
            upperLimit = 0x03FF;
            XMCRB = 0x06;
            break;
        case 11: // Releases Port C7-C3 (Mega pins 30-34)
            upperLimit = 0x07FF;
            XMCRB = 0x05;
            break;
        case 12: // Releases Port C7-C4 (Mega pins 30-33)
            upperLimit = 0x0FFF;
            XMCRB = 0x04;
            break;
        case 13: // Releases Port C7-C5 (Mega pins 30-32)
            upperLimit = 0x1FFF;
            XMCRB = 0x03;
            break;
        case 14: // Releases Port C7-C6 (Mega pins 30-31)
            upperLimit = 0x3FFF;
            XMCRB = 0x02;
            break;
        case 15: // Releases Port C7 (Mega pin 30)
            upperLimit = 0x7FFF;
            XMCRB = 0x01;
            break;
        default: // Use all Port C pins(default)
            upperLimit = 0xFFFF;
            break;
    }
    // Adjust upperSectorBoundry for addressWidth
    uint16_t boundry;
    if (addressWidth < 15)
    {
        boundry = 0x0000;
    }
    else if (addressWidth < 16)
    {
        boundry = constrain(upperSectorBoundry, 0x0000, 0x6000);
    }
    else
    {
        boundry = upperSectorBoundry;
    }
 
    // Clears External Memory Upper Sector Limit bits
    XMCRA &= 0x8F;
    // Sets the address boundry between lower and upper sectors
    switch (boundry)
    {
        case 0x4000: // Sets upper sector at 0x4000
            // Sets upper sector offset
            upperSectorOffset = 0x1E00;
            // Sets External Memory Upper Sector Limit bits
            XMCRA |= 0x20;
            break;
        case 0x6000: // Sets upper sector at 0x6000
            upperSectorOffset = 0x3E00;
            XMCRA |= 0x30;
            break;
        case 0x8000: // Sets upper sector at 0x8000
            upperSectorOffset = 0x5E00;
            XMCRA |= 0x40;
            break;
        case 0xA000: // Sets upper sector at 0xA000
            upperSectorOffset = 0x7E00;
            XMCRA |= 0x50;
            break;
        case 0xC000: // Sets upper sector at 0xC000
            upperSectorOffset = 0x9E00;
            XMCRA |= 0x60;
            break;
        case 0xE000: // Sets upper sector at 0xE000
            upperSectorOffset = 0xBE00;
            XMCRA |= 0x70;
            break;
        default: // Sets upper sector at 0x0000(default)
            upperSectorOffset = 0x0000;
            break;
    }
    // Set upper/lower sector sizes
    if (0 < upperSectorOffset)
    {
        lowerSize = upperSectorOffset;
        upperSize = ((1 + exp(2, addressWidth)) - (0x2200 + upperSectorOffset));
    }
    else
    {
        lowerSize = upperSize = ((1 + exp(2, addressWidth)) - 0x2200);
    }
    // Clears Upper Sector Wait State register bits
    XMCRA &= 0xF3;
    // Sets the upper sector wait-state
    switch (upperSectorWaitState)
    {
        case 1: // 1 wait-state for read/write
            XMCRA |= 0x04;
            break;
        case 2: // 2 wait-states for read/write
            XMCRA |= 0x08;
            break;
        case 3: // 2 wait-states for read/write and 1 wait-state after address
            XMCRA |= 0x0C;
            break;
        default: // No wait-states
            break;
    }
    // Clears the Lower Sector Wait State register bits
    XMCRA &= 0xFC;
    // Sets the lower sector wait-state
    switch (lowerSectorWaitState)
    {
        case 1: // 1 wait-state for read/write
            XMCRA |= 0x01;
            break;
        case 2: // 2 wait-states for read/write
            XMCRA |= 0x02;
            break;
        case 3: // 2 wait-states for read/write and 1 wait-state after address
            XMCRA |= 0x03;
            break;
        default: // No wait-states
            break;
    }
    // Enable External Memory Interface
    XMCRA |= 0x80;
}

void exmem::disable(void)
{
    // Disable External Memory Interface
    XMCRA &= 0x7F;
}

////////////////////////////////////////////////////////////////////////////////
// The following functions Read To or Write From the device(s) connected to the
// External Memory Interface. The functions read/write a byte value from/to an
// address in the upper or lower sector. Lower sector addresses start at 0x0000
// to upperSectorBoundry - 1. Upper sector addressess start at 0x0000 to the
// highest accessable address - upperSectorBoundry. The highest address is
// selected with the enable() function's addressWidth parameter. If there is
// only an upper sector then the lower sector's range will be the same as the
// upper sector's. Both upper and lower functions can be used if there is only
// an upper sector. They will have the same effect.
////////////////////////////////////////////////////////////////////////////////

uint8_t exmem::readLower(uint16_t address)
{
    // Create a variable to holds the data.
    uint8_t data;
    // Check if address is out of range.
    if (address >= lowerSize)
    {
        // Out of range returns NULL byte.
        data = 0x00;
    }
    else // Address is within range.
    {
        // Create a pointer to the lower sector address being read.
        volatile uint8_t *pMemory = (pExtMemory + address);
        // Load variable with data stored at the address.
        data = *pMemory;
    }
        return data; // Return with data.
}

uint8_t exmem::readUpper(uint16_t address)
// Create a variable to holds the data.
uint8_t data;
// Check if address is out of range.
if (address >= upperSize)
{
    // Out of range returns NULL byte.
    data = 0x00;
}
else // Address is within range.
{
    // Create a pointer to the upper seotor address being read.
volatile uint8_t *pMemory = (pExtMemory + upperSectorOffset + address);
// Load variable with the data stored at the address.
data = *pMemory;
}
return data; // Return with data;
}

void exmem::writeLower(uint16_t address, uint8_t data)
{
    // Only perform write if address is within range.
    if (address < lowerSize)
    {
        // Create a pointer
        volatile uint8_t *pMemory;
        // Assign the address being pointed to.
        pMemory = (volatile uint8_t *)(pExtMemory + address);
        // Put the data at the address being pointed to.
        *pMemory = (uint8_t)(data);
    }
}

void exmem::writeUpper(uint16_t address, uint8_t data)
// Only perform write if address is within range.
if (address < upperSize)
{
    // Create a pointer
    volatile uint8_t *pMemory;
    // Assign the address being pointed to.
    pMemory = (volatile uint8_t *)(pExtMemory + upperSectorOffset + address);
    // Put the data at the address being pointed to.
    *pMemory = (uint8_t)(data);

exmem ExMem = exmem(); // Create an instance named ExMem

Thanks again for your time,
DigitalJohnson
[/code]
Pages: 1 2 3 [4] 5 6 ... 10