Show Posts
Pages: 1 2 [3]
31  Using Arduino / Project Guidance / Re: What is Mega 2560 power source preference on: September 07, 2011, 12:41:38 pm
How do I disable the Mega2560 from powering up via USB? I am supplying external power VIN and only want to use that, as the current drain is too high for USB. The voltages are too low when USB is connected.
32  Using Arduino / Programming Questions / Re: How to convert 4 bytes into a long? (SOLVED) on: September 02, 2011, 06:50:35 pm
byte d[4];
long adc_value;

<.... stuff deleted>

adc_value  =  (long)d[0] << 24;
adc_value += (long)d[1] << 16;
adc_value += (long)d[2] << 8;
adc_value += (long)d[3];

This code works fine now. (Without proper casting to a long, I get swapped nibbles i.e. 21346587)
Thanks to everyone, esp. jraskell for the help.
33  Using Arduino / Programming Questions / Re: How to convert 4 bytes into a long? on: September 01, 2011, 11:54:45 am
Yes it should be: unsigned long adc_value; but I get the same results.
34  Using Arduino / Networking, Protocols, and Devices / Re: SPI.transfer hangs up on: September 01, 2011, 11:30:12 am
It is the missing brackets on SPI.begin() that cause it to hang at run time.
Thanks everyone for your help.
35  Using Arduino / Programming Questions / Re: How to convert 4 bytes into a long? on: September 01, 2011, 11:17:14 am
I do get interesting results and am still looking for a solution. It looks like the shift operator is only 16 bit. The cast to a long swaps nibbles on some of the bytes, which is strange. Thanks everyone for your help so far.

  byte d[4];
  long adc_value;

  d[0]=0x87; 
  d[1]=0x65; 
  d[2]=0x43; 
  d[3]=0x21; 

  adc_value=0;
  adc_value += d[0] << 24;
  adc_value += d[1] << 16;
  adc_value += d[2] << 8;
  adc_value += d[3];
  Serial.println(adc_value,HEX); //--> prints 4321 (expected 87654321)

  adc_value = *((long *)d);
  Serial.println(adc_value,HEX); // --> prints 21346587 (expected 21436587)

  d[0]=0x12; 
  d[1]=0x34; 
  d[2]=0x56; 
  d[3]=0x78; 

  adc_value=0;
  adc_value += d[0] << 24;
  adc_value += d[1] << 16;
  adc_value += d[2] << 8;
  adc_value += d[3];
  Serial.println(adc_value,HEX); //--> prints 5678 (expected 12345678)

  adc_value = *((long *)d);
  Serial.println(adc_value,HEX); // --> prints 78563412 (expected 87654321)
36  Using Arduino / Networking, Protocols, and Devices / Re: SPI.transfer hangs up on: August 31, 2011, 09:22:19 pm
I have an LED blink in the main (loop) that works fine until I add SPI.transfer- moving the LED on instruction, I traced it down to that.
If I instead use shiftout, everything works. But I need SPI to access other peripherals. I also tried reading data instead of writes  data=SPI.transfer(0x00) and it hangs too.
Not sure what else to try smiley-sad
37  Using Arduino / Networking, Protocols, and Devices / SPI.transfer hangs up on: August 31, 2011, 06:02:25 pm
I can't get SPI.transfer to work on my Arduino Mega 2560. Sketch hangs up on the function call. I understand SS pin on port needs to be set as an output, even though I am using other pins for chip select.

#include <SPI.h> // include the SPI library
#define SPI_MISO 50 // PB3 SPI MISO
#define SPI_MOSI 51 // PB2 SPI MOSI
#define SPI_CLK 52  // PB1 SPI CLK
#define SPI_SS 53   // PB0 SPI SS (not used but port needs this)
#define DAC_CS 11   // PB5 DAC CS
#define LED1GRN 13  // PB7 LED


void setup() {               
   pinMode(SPI_SS,OUTPUT); // SPI I/O port
   pinMode(SPI_MISO,INPUT);
   pinMode(SPI_MOSI,OUTPUT);
   pinMode(SPI_CLK,OUTPUT);
   pinMode(DAC_CS,OUTPUT);
   pinMode(LED1GRN,OUTPUT);
   digitalWrite(SPI_SS,HIGH);
   digitalWrite(DAC_CS,HIGH);
   digitalWrite(SPI_MISO,HIGH); 
}
//--------------------------------------------------------------------------
void loop() {
 
  word DAC_value = 0x8FFF;
 
  // initialize SPI:
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV32);
  SPI.setDataMode(SPI_MODE0); //SCK idle low, latch data rising edge
  SPI.begin;

  digitalWrite(DAC_CS,LOW);   

  SPI.transfer(0x20); // DAC Command byte <--- code seems to hang here!
  digitalWrite(LED1GRN, HIGH);   // set the LED on  <--- we never make it here, LED stays off

  SPI.transfer(highByte(DAC_value));
  SPI.transfer(lowByte(DAC_value));
  digitalWrite(DAC_CS,HIGH);
}
38  Using Arduino / Programming Questions / How to convert 4 bytes into a long? on: August 31, 2011, 05:28:23 pm
I have a 24-bit A/D and put four 8-bit reads into a byte array:

long adc_value;
byte d[4];

 digitalWrite(ADC_CS,LOW);
 d[0]=shiftIn(SPI_MISO,SPI_CLK,MSBFIRST);
 d[1]=shiftIn(SPI_MISO,SPI_CLK,MSBFIRST);
 d[2]=shiftIn(SPI_MISO,SPI_CLK,MSBFIRST);
 d[3]=shiftIn(SPI_MISO,SPI_CLK,MSBFIRST);
 digitalWrite(ADC_CS,HIGH);

 adc_value=long(d[]);  // <-- sketch does not compile
 adc_value=long(d[0]);  // <-- sketch compiles
 Serial.println(adc_value); // I get FF

So the conversion function "long" does not seem to accept arrays smiley-sad and I wonder how to use it?
39  Using Arduino / Installation & Troubleshooting / Re: Mega 2560 and Win7/64 USB driver: "This device cannot start. (Code 10)" on: August 25, 2011, 10:54:45 am
I uninstalled and reinstalled the USB driver with reboots to the PC and having Mega 2560 disconnected.
That got the driver to start and Win7/x64 to report "This device is working properly".

But in Arduino software, it reported "The COM port is already in use".

Found the problem is the USB hub in my LCD monitor, plugging Arduino right into the PC works now.
40  Using Arduino / Installation & Troubleshooting / Re: Mega 2560 and Win7/64 USB driver: "This device cannot start. (Code 10)" on: August 24, 2011, 11:36:44 am
I uninstalled and then went through the install process again... and no luck  smiley-sad
Driver details shows C:\windows\system32\DRIVERS\usbser.sys (Ver. 6.1) which is up to date.
I'm not sure what else I can try.
41  Using Arduino / Installation & Troubleshooting / Re: Installing MEGA 2560 on: August 23, 2011, 03:29:53 pm
What I found with the Mega 2560 is you need the "Arduino Mega 2560.inf" driver located in arduino-0022\drivers\ folder. Why are you using the  Uno driver? Also, do not use the FTDI drivers with the Mega 2560.

I cannot get it to work on Win7/x64 though.
42  Using Arduino / Installation & Troubleshooting / Mega 2560 and Win7/64 USB driver: "This device cannot start. (Code 10)" on: August 23, 2011, 11:51:09 am
Having troubles with Windows 7/64bit USB driver and the Mega 2560.
I connect the Mega 2560 and navigate to arduino-0022\drivers\Arduino MEGA 2560.inf
Windows 7 loads the driver and it shows up as Arduino Mega 2560 (COM7) and reports Device Status: This device cannot start. (Code 10)
If I run arduino-0022.exe->tools->serial port, COM7 does not appear on the picklist. Tried rebooting everything, no luck.
I notice no Windows 7 definitions in this file, it looks like the driver is old?
Pages: 1 2 [3]