Go Down

Topic: Arduino Due using the same language ? (Read 4 times) previous topic - next topic

matt238

Hi everyone ,

I was wondering if the new Arduino Due which is using an ARM chip is still using the same programming language and if everything we can read on the internet and in books regarding how to program the arduino uno is still right for the Due ... ?

Thanks for your help :)

retrolefty


Hi everyone ,

I was wondering if the new Arduino Due which is using an ARM chip is still using the same programming language and if everything we can read on the internet and in books regarding how to program the arduino uno is still right for the Due ... ?

Thanks for your help :)



Correct both arduino Due and AVR based arduino boards are programmed in the C/C++ language.

Lefty

MichaelMeissner

#2
Oct 23, 2012, 10:12 pm Last Edit: Oct 24, 2012, 05:15 pm by MichaelMeissner Reason: 1
It should be, given it uses GNU compiler underneath, just like the AVR based chips.  Now, there are some places where it will be subtly different, but over all, it should be the same.  Some things that will be different include:

  • The IDE uses an ancient (4.3.x released in 2008) based compiler for AVR and a slightly less ancient (4.4.x released in 2009) based compiler for ARM.  There may be fixes and enhancements in 4.4 that weren't in 4.3.  The current GCC release is 4.7.x and we are working on 4.8

  • Int variables are 16-bits in AVR, and 32-bits in ARM.  If you have code that depends on the overflow behavior when a 16-bit value wraps, it will have a different value in arm.  If you use unions to pull apart the bytes in an int (or worse, casts on pointers), you will likely have to adjust your code.

  • Double variables are 32-bits in AVR, and 64-bits in ARM.

  • Anything that uses assembly code will have to be rewritten.  I expect things like interrupt code also will need to be rewritten.


evmaker

Most all of my simple sketches seem to run on my due. However I have not found out how to go into a register and modify a single bit yet, I would dearly love to go to 0x40094000 and change bit# 19 to a zero.
I have been trying with word, bitWrite, and bitClear with no success. Bit read seems to work and the write protect register seems to be off for this byte. All I want to do is change one bit. Getting a little frustrated. Might have to box the due until there is more docks and stuff. The mega 2560 has no problem with simple stuff like this.

Nick Gammon

Quote
I have been trying with word, bitWrite, and bitClear with no success. Bit read seems to work and the write protect register seems to be off for this byte. All I want to do is change one bit.


Perhaps post what you tried?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

pico

#5
Nov 08, 2012, 08:06 am Last Edit: Nov 08, 2012, 08:22 am by pico Reason: 1

Most all of my simple sketches seem to run on my due. However I have not found out how to go into a register and modify a single bit yet, I would dearly love to go to 0x40094000 and change bit# 19 to a zero.
I have been trying with word, bitWrite, and bitClear with no success.


Have you tried something direct and simple like this? (I haven't got a Due, but this compiles for Maple, which also uses gcc for an ARM Cortex-M3 target:)

Code: [Select]

#include <stdint.h>

void setup()
{
 uint32_t *p = (uint32_t *)0x40094000; // set up int pointer to address
 *p &= ~(1 << 19);  // clear bit 19  
}

void loop()
{
}


BTW, what is clearing bit 19 at address 0x40094000 supposed to do?
WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

Markus_L811


Most all of my simple sketches seem to run on my due. However I have not found out how to go into a register and modify a single bit yet, I would dearly love to go to 0x40094000 and change bit# 19 to a zero.
I have been trying with word, bitWrite, and bitClear with no success. Bit read seems to work and the write protect register seems to be off for this byte. All I want to do is change one bit. Getting a little frustrated. Might have to box the due until there is more docks and stuff. The mega 2560 has no problem with simple stuff like this.


From the Techpaper you http://www.atmel.com/Images/doc11057.pdf Page 1020
Quote
This register can only be written if the bits WPSWS0 and WPHWS0 are cleared


Forward to Page 1053...

If I understud it right the Register 0x400940E8 (PWM_WPSR) needs only be read to set bits on Register 0x40094000


evmaker

I seem to  be able to use bitRead to read the bits in 0x400940E8 bit 0 and bit 8 are both already set to 0.
This means that WPSWS0 and WPHWS0 are bot set to write protect off. It would seem that I should be able to do a simple bitWrite(0x40094000, 0x13, 0), However it seems that I have to define a long =x and use the x as the IDE thinks that it is a stinking 16 bit joe he is talking to. This becomes;

long x = 0x40094000;
bitWrite(x, 0x13, 0);

and later i do

int y =  bitRead(x, 0x13);
Serial.print(y);

and darn if it still ain't a 1

Tried several other things like above mentioned and the compiler wont complie, guess the due was just a waste of money I will continue the project with a leaf labs maple. Already have working code for that, just wanted to make my new pcb compatible with avr and sam3. The maple pins out a little different but the IDE can call a register by name timer_suchandsuch = timer_suchandsuch & 0xshit=0 | 0xnewvalue and presto pwm is set, Real similar to the old mega2650.

Could be that I just was not supposed to be building my own inverters, but my homemade grid  tie  worked hard all summer long and saved me $200 or so. It only runs at the frequency of the power co. Now in the fall it is only doing 3 kwh on a good  day Jul and Aug it was giving 8 to 9. Think I just need more sun and panels to catch it. Longer days would be nice too. It runs an UNO with a very short sketch.

Guess I'll just modify the pcb for maple and role on that. Just seemed that due would have been a more capable kind of guy.

Thank you all for the advice and interest,
James

Nick Gammon

Yes, but if you look at the defines:

Code: [Select]

#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))


Your bitRead (and bitWrite) are working on 0x40094000, not what it is pointing to.

And the 0x13 bit of the number 0x40094000 is indeed 1.

I suggest something like:

Code: [Select]

  long* x = (long*) 0x40094000;
  bitWrite(*x, 0x13, 0); 


Can't test it because I don't have a Due, but I'm sure the macro does what I said.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

Which is what pico (above) had:

Code: [Select]

  uint32_t *p = (uint32_t *)0x40094000; // set up int pointer to address


He was using the pointer, not just the number.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Massimo Banzi

@evmaker

the Due is a new products and there might be bugs, but as you can see from this forum they get fixed pretty quickly.

If you keep reporting issues and paste the releavant parts of code you can get  a lot of help.


m

evmaker

Thank you Nick,

I will hook up the due one more time and try before he hits the street as you suggest;

I suggest something like:

Code:

  long* x = (long*) 0x40094000;
  bitWrite(*x, 0x13, 0); 


Can't test it because I don't have a Due, but I'm sure the macro does what I said.

Been modifying my pcb layout to fit maple got to change the tags on my blog as he will no  longer be an arduino ev. so I hope it works that will be a pain.

evmaker

Nick,

Here is the code;

Code: [Select]
int x=0;
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
int f=0;
int g=0;
int h=0;
int i=0;
int j=0;

long* reg =(long*) 0x40094000;
int regb =0x400940E8;
int z=0;
int led=2;
int pot=A7;
int ground=3;

void setup() {
  Serial.begin(9600);
  analogReadResolution(12);
  analogWriteResolution(12);
  pinMode(led, OUTPUT);
  pinMode(ground, OUTPUT);
  digitalWrite(ground, LOW);
//  bitClear(regb, 0);
//  bitClear(regb, 8);
  bitWrite(*reg, 0x13, 0);
}

void loop() {
  z = (analogRead(pot));
  Serial.print(z);
  Serial.print("  ");
  analogWrite(led, z);
  delay(10);
  a = (bitRead(0x40094200, x));
b = (bitRead(0x40094220, x));
c = (bitRead(0x40094240, x));
d = (bitRead(0x40094260, x));
e = (bitRead(0x40094280, x));
f = (bitRead(0x400942A0, x));
g = (bitRead(0x400942C0, x));
h = (bitRead(0x400942E0, x));
i = (bitRead(0x40094000, x));
j = (bitRead(0x400940E8, x));
Serial.print(x);
Serial.print("  ");
Serial.print(a);
Serial.print("  ");
Serial.print(b);
Serial.print("  ");
Serial.print(c);
Serial.print("  ");
Serial.print(d);
Serial.print("  ");
Serial.print(e);
Serial.print("  ");
Serial.print(f);
Serial.print("  ");
Serial.print(g);
Serial.print("  ");
Serial.print(h);
Serial.print("  ");
Serial.print(i);
Serial.print("  ");
Serial.print(j);
Serial.println(" ");
x = x + 1 ;
if (x > 31) { x=0;  }
 
}
 

This is what it returns;

Pot     x  a  b  c  d  e  f   g   h  I   j
1113  0  0  0  0  0  0  0  0  0  0  0
1113  1  0  0  0  0  0  0  0  0  0  0
1113  2  0  0  0  0  0  0  0  0  0  0
1113  3  0  0  0  0  0  0  0  0  0  1
1113  4  0  0  0  0  0  0  0  0  0  0
1113  5  0  1  0  1  0  1  0  1  0  1
1113  6  0  0  1  1  0  0  1  1  0  1
1113  7  0  0  0  0  1  1  1  1  0  1
1113  8  0  0  0  0  0  0  0  0  0  0
1113  9  1  1  1  1  1  1  1  1  0  0
1113  10  0  0  0  0  0  0  0  0  0  0
1113  11  0  0  0  0  0  0  0  0  0  0
1113  12  0  0  0  0  0  0  0  0  0  0
1114  13  0  0  0  0  0  0  0  0  0  0
1114  14  1  1  1  1  1  1  1  1  1  1
1113  15  0  0  0  0  0  0  0  0  0  0
1113  16  1  1  1  1  1  1  1  1  1  1
1113  17  0  0  0  0  0  0  0  0  0  0
1113  18  0  0  0  0  0  0  0  0  0  0
1113  19  1  1  1  1  1  1  1  1  1  1
1112  20  0  0  0  0  0  0  0  0  0  0
1114  21  0  0  0  0  0  0  0  0  0  0
1113  22  0  0  0  0  0  0  0  0  0  0
1113  23  0  0  0  0  0  0  0  0  0  0
1113  24  0  0  0  0  0  0  0  0  0  0
1113  25  0  0  0  0  0  0  0  0  0  0
1112  26  0  0  0  0  0  0  0  0  0  0
1114  27  0  0  0  0  0  0  0  0  0  0
1113  28  0  0  0  0  0  0  0  0  0  0
1114  29  0  0  0  0  0  0  0  0  0  0
1113  30  1  1  1  1  1  1  1  1  1  1
1113  31  0  0  0  0  0  0  0  0  0  0
pot     x   a  b  c   d  e   f  g  h  I   j

sorry guess i messed up somehow

James

Go Up