Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 459
61  Using Arduino / Programming Questions / Re: Make an Array "On the Fly" on: August 07, 2014, 02:19:41 am
Heh.  I just posted this (untested) code on another forum.  It looks close to what you want.
(of course, it was an example of "ugly" code, sort of...)
Code:
uint8_t avrisp_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
   uint8_t outdatat[4];
   uint8_t indata[4];
   outdata[0] = a;
   outdata[1] = b;
   outdata[2] = c;
   outdata[3] = d;
   spiDRV->ARM_SPI_Transfer(outdata, indata, 4);
   while (spiDRV->ARM_SPI_GetDataCount() < 4)
     {  /* spin */ }
   return indata[3];  // Last byte input is result.
}
62  Using Arduino / Programming Questions / Re: Why does digitalWrite disable global interrupts before changing a pin state? on: August 06, 2014, 08:02:00 pm
out is pointer to an IO register, which is volatile.  It can change other than by program action.  If you output to it twice, you want to output to it twice, and not just with the last value.  (hopefully the "volatile" is in the right place and means "this is a pointer to a volatile value", rather than "this is a volatile pointer to a value."  You have to be careful with that...)

port, bit, and timer are just "constants" retrieved from the flash; not volatile at all.

Quote
digitalWrite could have been done as a macro
Yes.  And in fact people have done that, yielding "digitalWriteFast" and similar.  Teensy (even the AVR teensy) has a highly optimized digitalWrite implementation.  The Arduino teams seems to have decided that (1) the current implementation is fast enough.  (2) the fast versions obscure the functionality.  (3) Having digitalWrite have wildly varying execution speeds depending on arguments isn't really a good idea.
63  Using Arduino / Microcontrollers / Re: arm with ce / vga 5v ? on: August 06, 2014, 07:49:27 pm
Quote
devices only pull the bus to ground,
This is NOT generally true.  It would apply to I2C, mostly.
64  Using Arduino / Programming Questions / Re: Why does digitalWrite disable global interrupts before changing a pin state? on: August 06, 2014, 05:30:25 pm
Quote
and generate single sbi or cbi instructions.
But digitalWrite() doesn't DO  "PORTB |= 8;"
It does "*out |= bit;" where both out and bit are variables, and that's always going to be non-atomic on an AVR.
65  Using Arduino / Microcontrollers / Re: arm with ce / vga 5v ? on: August 06, 2014, 04:23:03 am
Quote
why can the pins not take 5v ?
Approximately: because the design rules that let you fit a processor of that complexity on a cheap chip also cause the individual transistors to become too small to handle higher voltages.
66  Using Arduino / Microcontrollers / Re: Downloading hex from the Atmega on: August 06, 2014, 01:08:54 am
Assuming that the protection bits have NOT been set, you should be able to get away with
avrdude   -p atmega328p -P /dev/tty.usbserial-FTD61T6Q -cstk500v1 -b19200 -U flash:r:dest.hex
Substitute port/programmer-type/speed and add config files as appropriate - basically you're just replacing the -U flash:w: (write to flash) with a -U flash:r: (read from flash)

If the protections bits HAVE been set or ISP programming has been disabled, or RESET has been changed to a GPIO pin, it will be significantly more difficult (up to "impossible" if they have protected it well.  Short of etching away the package and select areas of metalization and microprobing...)
67  Using Arduino / Microcontrollers / Re: arm with ce / vga 5v ? on: August 05, 2014, 11:25:51 pm
AFAIK, all of the linux-capable ARMs will be low-voltage chips, in order to interface to the high density RAM chips that you need for linux on a reasonable-sized board.  (DDR3 is 1.5V !)
68  Using Arduino / Programming Questions / Re: Low memory available on: August 03, 2014, 09:49:22 pm
Quote
128X64 OLED Screen.
Graphics screens use lots of memory.  I mean, that's 8K pixels right there...
Support for SD card is also relatively expensive.
69  Using Arduino / Installation & Troubleshooting / Re: MEGA 2560 serial problem on: August 03, 2014, 03:22:45 am
Can't you use one of the additional HWserial ports that are available on the MEGA?
70  Using Arduino / Programming Questions / Re: Atmega8 uploading Error on: August 03, 2014, 02:59:37 am
What hardware are you using to burn the bootloader?
71  Using Arduino / Programming Questions / Re: Atmega8 uploading Error on: August 03, 2014, 02:47:53 am
Quote
atmega8noxtal.upload.protocol=stk500
atmega8noxtal.upload.maximum_size=7168
atmega8noxtal.bootloader.file=ATmegaBOOT.hex
atmega8noxtal.upload.speed=38400
How confident are you that you have the correct bootloader loader and settings?  According to the official boards.txt, the older Atmega8 boards ("NG", for example) used 19200bps when running atmegaboot, and that was at 16MHz...  And with a modern avrdude, you should probably use "upload.protocol=arduino"

You could put optiboot on your mega8.  At 8MHz you should only run 57600, but it'll still be faster, save you 512 bytes of sketch space and be "under maintenance"...


72  Using Arduino / Programming Questions / Re: Atmega8 uploading Error on: August 03, 2014, 12:57:28 am
Make the modifications shown in red in the boards.txt file where you added the new atmega8 board.

atmega8noxtal.name=ATmega8-noxtal @8MHz

atmega8noxtal.upload.protocol=stk500
atmega8noxtal.upload.maximum_size=7168
atmega8noxtal.upload.speed=38400

atmega8noxtal.bootloader.low_fuses=0xe4
atmega8noxtal.bootloader.high_fuses=0xc4
atmega8noxtal.bootloader.path=atmega8_noxtal
atmega8noxtal.bootloader.file=ATmegaBOOT.hex
atmega8noxtal.bootloader.unlock_bits=0x3F
atmega8noxtal.bootloader.lock_bits=0x0F

atmega8noxtal.build.mcu=atmega8
atmega8noxtal.build.f_cpu=8000000L
atmega8noxtal.build.core=arduino:arduino
atmega8noxtal.build.variant=arduino:standard

This is required of later (post-leonardo) IDE versions (when "variants" were introduced.)
73  Using Arduino / Programming Questions / Re: Pointer problems on: August 02, 2014, 06:07:41 pm
Quote
The fact that it is preceded by "PARAMETERS *"  creates another instance of my pointer.

Heh.  In any case, thanks for the update; it's always nice to know the resolution of such problems.
And I found this particular wild goose chase to be relatively educational...
74  Using Arduino / Programming Questions / Re: Translate code to arduino code on: August 02, 2014, 06:05:40 pm
Quote
i want to understand the following code and how i can use it to my arduino

Code:
rs = (5000./g_vol-1.)*10000.;/*Calc Rs*/
rs = (rs/5000.);/*0.1 * 10=1*/ //Calculate Rs/Ro
abc = rs;
g_logalc = log(abc);
g_alcohol = 169*(g_logalc*g_logalc*g_logalc*g_logalc)-
147*(g_logalc*g_logalc*g_logalc)+207*(g_logalc*g_logalc)-496*g_logalc+332; //Put
That first part is Math. Presumably it's based on the documentation of the alcohol sensor, and converts the Analog reading into a meaningful number (Blood alcohol PPM, or something.)  You can probably leave it as is.  It may have some problems because Arduino doesn't have "double" (higher precision math), and it's possible that that precision is needed for the calculations to some out right...

Code:
g_dis_buf[0] =g_alcohol/1000%10 + 0x30; // Display the result
g_dis_buf[1] =g_alcohol/100%10 + 0x30;

g_dis_buf[2] =g_alcohol/10%10 + 0x30;
g_dis_buf[3] =g_alcohol %10 + 0x30;
g_dis_buf[4] = '\0';
LCD_str(0,1,"Alcohol:");
LCD_str(8,1,g_dis_buf);
LCD_str(13,1,"PPM");
This part is display code that could be replaced with Serial.print() calls.  Or LCD.print() if you end up using an LCD on your Arduino and the standard LCD library.

What you have is 'complete' code for a PIC alcohol analyzer.  It initializes and reads the PIC's internal A2D converter (which is replaceable with the arduino core and a call to analogRead()), does some math on it (which you still need), and displays the result on an LCD using relatively bare LCD-writing code (which is replaceable by the Serial or LCD and Print arduino libraries.)  So an arduino sketch that does the same thing as this program will be much shorter.

The original code is somewhat interesting as a "bad example" of how to partition code.  Ideally there would be "high level" functions that you wouldn't have to change at all.   But this is very common in the microcontroller world, and it's partially because the code frequently gets smaller and faster if you don't have a lot of depth in you function call graph...
75  Using Arduino / Microcontrollers / Re: Burn BootLoader......... on: August 02, 2014, 05:46:03 pm
Quote
I found this sketch [optiLoader],  it is A BootLoader sketch,  on github.

OptiLoader is not a Bootloader sketch.   It's a Bootloader LOADER sketch.  It will run on an Arduino, and let you program bootloaders (which are stored internally to OptiLoader) onto OTHER Arduinos, given a suitable cable.  Reread the documentation, and perhaps this video will help:  https://www.youtube.com/watch?v=YBFUGre0hY4&list=UUBEMAycMY7u3rf5IsJvltIw

Adafruit and Nick Gammon both have improved versions that do similar things.
Pages: 1 ... 3 4 [5] 6 7 ... 459