Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Error programming ATTiny85 on: February 19, 2012, 12:10:28 am
I have the same issue... I have the capacitor to avoid reset... but nothing happen. I activated verbose and this showed me (attached)
2  Using Arduino / Storage / Re: 25LC256 issue on: January 22, 2012, 05:01:06 pm
This is the writting cycle:

Note: I added a led to digital pin 2 to show when the cycle is finished.

Code:
#include <SPI.h>
int variable = 56; //data to record
int resultado, registro=0;

void setup() {
  pinMode(10,OUTPUT);
  pinMode(2,OUTPUT);
  digitalWrite(10, HIGH);
  digitalWrite(2, HIGH);
  SPI.begin();  
  SPI.setDataMode(SPI_MODE3);  // set SPI protocol
  SPI.setClockDivider(SPI_CLOCK_DIV2); // 10 Mhz max for 25LC256
  SPI.setBitOrder(MSBFIRST);
  
  digitalWrite(10, LOW);
  SPI.transfer(6);  // write enable 6
  digitalWrite(10, HIGH);
  
  digitalWrite(10, LOW);
  SPI.transfer(1); // remove block protection 1,0
  SPI.transfer(0);
  digitalWrite(10, HIGH);
  delay(5);
  
  for(int j=0; j<9; j++)
  {
      digitalWrite(10, LOW);
      SPI.transfer(6); // write enabled 6
      digitalWrite(10, HIGH);
      
      digitalWrite(10, LOW);
      SPI.transfer(2); // write 2,0
      SPI.transfer(0);
      SPI.transfer(registro); // registry
      SPI.transfer(variable); // data to record
      digitalWrite(10, HIGH);
      delay(5);
      
      digitalWrite(10, LOW);
      SPI.transfer(6); // write enabled 6
      digitalWrite(10, HIGH);

      registro++;  // +1
      variable++;  // +1
  }
  digitalWrite(10, LOW);
  SPI.transfer(4); // write disabled 4
  digitalWrite(10, HIGH);
}

void loop() {
digitalWrite(2, LOW);
}

This is the reading cycle:

Note: I added a led to digital pin 2 to show when the cycle is finished.

Code:
#include <SPI.h>
int resultado, registro=0;

void setup() {
  pinMode(10,OUTPUT);
  pinMode(2,OUTPUT);
  digitalWrite(10, HIGH);
  digitalWrite(2, HIGH);
  Serial.begin(9600);
  SPI.begin();  
  SPI.setDataMode(SPI_MODE3);  //setup SPI protocol
  SPI.setClockDivider(SPI_CLOCK_DIV2); // 10 Mhz max for 25LC256
  SPI.setBitOrder(MSBFIRST);
  
  for(int j=0; j<9; j++)
  {
      digitalWrite(10, LOW);
      SPI.transfer(3); // read 3,0
      SPI.transfer(0);
      SPI.transfer(registro); // registry
      resultado = SPI.transfer(0x00);
      digitalWrite(10, HIGH);
      
      Serial.print("direccion"); //print on screen
      Serial.print(registro);
      Serial.print(" : ");
      Serial.println(resultado);
      registro++;
  }
}

void loop() {
digitalWrite(2, LOW);
}
3  Using Arduino / Storage / Re: 25LC256 issue on: January 22, 2012, 04:39:56 pm
I have to change some code to make it work, but now is working smiley

Thanks!  smiley-yell

Now I'll try to make a writing cycle, and a reading cycle.

Code:
#include <SPI.h>
int variable = 2; //data that you want to record
int resultado, registro=0; // variable to record from EEPROM, position of the registry

void setup() {
  pinMode(10,OUTPUT);
  digitalWrite(10, HIGH);
  Serial.begin(9600);
  SPI.begin(); 
  SPI.setDataMode(SPI_MODE3);  //setup SPI protocol
  SPI.setClockDivider(SPI_CLOCK_DIV2); // 10 Mhz max for 25LC256
  SPI.setBitOrder(MSBFIRST);
 
  digitalWrite(10, LOW);
  SPI.transfer(6);  //write enable 6
  digitalWrite(10, HIGH);
 
  digitalWrite(10, LOW);
  SPI.transfer(1); //remove block protection 1,0
  SPI.transfer(0);
  digitalWrite(10, HIGH);
  delay(5);
 
  for(int j=0; j<9; j++)
  {
      digitalWrite(10, LOW);
      SPI.transfer(6); //write enable 6
      digitalWrite(10, HIGH);
     
      digitalWrite(10, LOW);
      SPI.transfer(2); // write 2,0
      SPI.transfer(0);
      SPI.transfer(registro); // registry
      SPI.transfer(variable); // data
      digitalWrite(10, HIGH);
      delay(5);
     
      digitalWrite(10, LOW);
      SPI.transfer(6); // write enable 6
      digitalWrite(10, HIGH);
     
      digitalWrite(10, LOW);
      SPI.transfer(3); // read 3,0
      SPI.transfer(0);
      SPI.transfer(registro); // registry
      resultado = SPI.transfer(0x00);
      digitalWrite(10, HIGH);
       
      Serial.print("direccion");
      Serial.print(registro);
      Serial.print(" : ");
      Serial.println(resultado);
      registro++;
      variable++;
  }
  digitalWrite(10, LOW);
  SPI.transfer(4); // write disabled 4
  digitalWrite(10, HIGH);
}

void loop() {}
4  Using Arduino / Storage / Re: 25LC256 issue on: January 22, 2012, 04:17:49 pm
Oh! I see ... I think .. SPI library that it automatically  smiley-roll-blue

I'll try that...
5  Using Arduino / Storage / Re: 25LC256 issue on: January 22, 2012, 01:25:03 pm
digital pin 10 Arduino - pin 1 25lc256
digital pin 11 - pin 5
digital pin 12 - pin 2
digital pin 13 - pin 6


pin 7, 3 and 8 of 25lc256 to 5v
pin 4 to gnd
6  Using Arduino / Storage / Re: 25LC256 issue on: January 22, 2012, 12:39:56 pm
yes, actually I saw an example with PIC, and they uses write enable several times, I viewed the datasheet before you gave me the link... and I make it work with pic and picaxe, but I don't know how to use it in Arduino, and the SPI library doesn't have enough explaination.  smiley-roll-blue
7  Using Arduino / Storage / 25LC256 issue on: January 22, 2012, 10:17:57 am
Hi, I'm trying to use a SPI EEPROM 25lc256 with Arduino, I'm using the SPI library but i don't know how to use it, so i wrote the code but it doesn't work  smiley-roll-sweat it returns me random data...

Here is my code... i think it's a mess :S

Code:
#include <SPI.h>
int variable = 4;
int resultado, registro=0;

void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE3);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setBitOrder(MSBFIRST);
 
  SPI.transfer(6);
  SPI.transfer(0x10);
  delay(5);
 
  for(int j=0; j<9; j++)
  {
      SPI.transfer(6);
      SPI.transfer(0x20);
      SPI.transfer(registro);
      SPI.transfer(variable);
      delay(5);
      SPI.transfer(6);
      SPI.transfer(0x30);
      SPI.transfer(registro);
      resultado = SPI.transfer(0x00);
      SPI.transfer(4);
      Serial.print("direccion :");
      Serial.println(registro);
      Serial.println(resultado);
      registro++;
      variable++;
  }

}

void loop() {}

thanks for your help
8  Using Arduino / Programming Questions / Re: Manage ports? on: September 19, 2011, 09:00:31 am
@WizenedEE

Yes you are right, direct hardware usage is always faster than prototype functions.  But most of Arduino users including me have not electronic background. For us really hard to understand MCU hardware basics. And the aim of Arduino platform is to make the usage of microcontroller easier to everyone. IMO with these port functions every Arduino user can easily use the ports.

With all my respect @Nadir, but I think that if you don't have an electronic backgroud you should started with some simplier MCU. I think Arduino is a quite more complex and even if its designed for hobbyist... you should learn about MCU hardware.
9  Using Arduino / Programming Questions / Re: Manage ports? on: September 19, 2011, 08:34:06 am
Code:
[code][quote author=WizenedEE link=topic=72540.msg545786#msg545786 date=1316411005]
How is [code]
value = portRead(PB);
different from 
Code:
value = PINB;

besides being a lot slower to execute? Pretty much the same thing for the other two.[/code][/code]
[/quote]

mmm letme see this...

10  Using Arduino / Programming Questions / Re: Manage ports? on: September 18, 2011, 09:06:15 pm
The example was given back reply #11

void setup() {
  portMode(PD, OUTPUT);  // sets the pins in Port D to be outputs
}

void loop() {
  portWrite(PD, B0001000);  //sets the Port D outputs to B00001000
  delay(500);
  portWrite(PD, B0000000);  //sets the Port D outputs to B00000000
  delay(500);
}
and I imagine that
byte variablePort = portRead (PD);
would read the port bit states into variablePort


yes, I copied that and added the functions but it sends me a lot of errors.

I copied into the c progrman under the void loop function

also I copied into the wiring_digital.c but it still sending me errors...
11  Using Arduino / Programming Questions / Re: Manage ports? on: September 18, 2011, 08:47:16 pm
My Wiring_digital.c have this:

Code:
/*
  wiring_digital.c - digital input and output functions
  Part of Arduino - http://www.arduino.cc/

  Copyright (c) 2005-2006 David A. Mellis

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA

  Modified 28 September 2010 by Mark Sproul

  $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/

#include "wiring_private.h"
#include "pins_arduino.h"

void pinMode(uint8_t pin, uint8_t mode)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg;

if (port == NOT_A_PIN) return;

// JWS: can I let the optimizer do this?
reg = portModeRegister(port);

if (mode == INPUT) {
uint8_t oldSREG = SREG;
                cli();
*reg &= ~bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
                cli();
*reg |= bit;
SREG = oldSREG;
}
}

// Forcing this inline keeps the callers from having to push their own stuff
// on the stack. It is a good performance win and only takes 1 more byte per
// user than calling. (It will take more bytes on the 168.)
//
// But shouldn't this be moved into pinMode? Seems silly to check and do on
// each digitalread or write.
//
// Mark Sproul:
// - Removed inline. Save 170 bytes on atmega1280
// - changed to a switch statment; added 32 bytes but much easier to read and maintain.
// - Added more #ifdefs, now compiles for atmega645
//
//static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
//static inline void turnOffPWM(uint8_t timer)
static void turnOffPWM(uint8_t timer)
{
switch (timer)
{
#if defined(TCCR1A) && defined(COM1A1)
case TIMER1A:   cbi(TCCR1A, COM1A1);    break;
#endif
#if defined(TCCR1A) && defined(COM1B1)
case TIMER1B:   cbi(TCCR1A, COM1B1);    break;
#endif

#if defined(TCCR2) && defined(COM21)
case  TIMER2:   cbi(TCCR2, COM21);      break;
#endif

#if defined(TCCR0A) && defined(COM0A1)
case  TIMER0A:  cbi(TCCR0A, COM0A1);    break;
#endif

#if defined(TIMER0B) && defined(COM0B1)
case  TIMER0B:  cbi(TCCR0A, COM0B1);    break;
#endif
#if defined(TCCR2A) && defined(COM2A1)
case  TIMER2A:  cbi(TCCR2A, COM2A1);    break;
#endif
#if defined(TCCR2A) && defined(COM2B1)
case  TIMER2B:  cbi(TCCR2A, COM2B1);    break;
#endif

#if defined(TCCR3A) && defined(COM3A1)
case  TIMER3A:  cbi(TCCR3A, COM3A1);    break;
#endif
#if defined(TCCR3A) && defined(COM3B1)
case  TIMER3B:  cbi(TCCR3A, COM3B1);    break;
#endif
#if defined(TCCR3A) && defined(COM3C1)
case  TIMER3C:  cbi(TCCR3A, COM3C1);    break;
#endif

#if defined(TCCR4A) && defined(COM4A1)
case  TIMER4A:  cbi(TCCR4A, COM4A1);    break;
#endif
#if defined(TCCR4A) && defined(COM4B1)
case  TIMER4B:  cbi(TCCR4A, COM4B1);    break;
#endif
#if defined(TCCR4A) && defined(COM4C1)
case  TIMER4C:  cbi(TCCR4A, COM4C1);    break;
#endif
#if defined(TCCR5A)
case  TIMER5A:  cbi(TCCR5A, COM5A1);    break;
case  TIMER5B:  cbi(TCCR5A, COM5B1);    break;
case  TIMER5C:  cbi(TCCR5A, COM5C1);    break;
#endif
}
}

void digitalWrite(uint8_t pin, uint8_t val)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out;

if (port == NOT_A_PIN) return;

// If the pin that support PWM output, we need to turn it off
// before doing a digital write.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);

out = portOutputRegister(port);

if (val == LOW) {
uint8_t oldSREG = SREG;
                cli();
*out &= ~bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
                cli();
*out |= bit;
SREG = oldSREG;
}
}

int digitalRead(uint8_t pin)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);

if (port == NOT_A_PIN) return LOW;

// If the pin that support PWM output, we need to turn it off
// before getting a digital reading.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);

if (*portInputRegister(port) & bit) return HIGH;
return LOW;
}

void portMode(uint8_t port, uint8_t mode)
{
volatile uint8_t *moderegister;

moderegister = portModeRegister(port);

if (moderegister == NOT_A_PORT) return;

uint8_t oldSREG = SREG;
cli();

//*moderegister = mode;
if (mode == OUTPUT)
*moderegister = 0xff;
else
*moderegister = 0x00;

SREG = oldSREG;
}

uint8_t portRead(uint8_t port)
{
volatile uint8_t *inputregister;

inputregister = portInputRegister(port);

if (inputregister == NOT_A_PORT) return;

uint8_t oldSREG = SREG;
cli();
uint8_t portValue = *inputregister;
SREG = oldSREG;
return portValue;
}

void portWrite(uint8_t port, uint8_t val)
{
volatile uint8_t *portregister;

portregister = portOutputRegister(port);

if (portregister == NOT_A_PORT) return;

uint8_t oldSREG = SREG;
cli();
*portregister = val;
SREG = oldSREG;
}

now how to use it? :S

Well I tried to add it to regular code and it doesn't work... sends me a lot of errors :/ even if I put the functions on the C program...
12  Using Arduino / Programming Questions / Re: Manage ports? on: September 18, 2011, 08:16:42 pm
I have mooched the port manipulation functions from wiring platform. Copy them into "wiring_digital.c" to have built-in port manipulation.

Functions
Code:
void portMode(uint8_t port, uint8_t mode)
{
volatile uint8_t *moderegister;

moderegister = portModeRegister(port);

if (moderegister == NOT_A_PORT) return;

uint8_t oldSREG = SREG;
cli();

//*moderegister = mode;
if (mode == OUTPUT)
*moderegister = 0xff;
else
*moderegister = 0x00;

SREG = oldSREG;
}

uint8_t portRead(uint8_t port)
{
volatile uint8_t *inputregister;

inputregister = portInputRegister(port);

if (inputregister == NOT_A_PORT) return;

uint8_t oldSREG = SREG;
cli();
uint8_t portValue = *inputregister;
SREG = oldSREG;
return portValue;
}

void portWrite(uint8_t port, uint8_t val)
{
volatile uint8_t *portregister;

portregister = portOutputRegister(port);

if (portregister == NOT_A_PORT) return;

uint8_t oldSREG = SREG;
cli();
*portregister = val;
SREG = oldSREG;
}

Example
Code:
void setup() {
  portMode(PD, OUTPUT);
}

void loop() {
  portWrite(PD, B0001000);
  delay(500);
  portWrite(PD, B0000000);
  delay(500);
}

Well... I can't understand this code smiley-eek
13  Using Arduino / Programming Questions / Re: Manage ports? on: September 17, 2011, 12:22:50 pm
Thanks to all of you! It's working, I thought that arduino had the same hardware limitations than PICAXE but it doesn't its really cool program this staff  smiley-lol smiley-lol

Code:
unsigned int del = 100;

void setup() {                
  pinMode(2, OUTPUT);    
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}

void loop() {
  PORTD |= 0X04;
  delay(del);  
  PORTD &= ~0X04;
  PORTD |= 0X08;
  delay(del);
  PORTD &= ~0X08;
  PORTD |= 0X10;
  delay(del);
  PORTD &= ~0X10;
  PORTD |= 0X20;
  delay(del);
  PORTD &= ~0X20;  
    del=del-10;
  if (del < 20)
  {
    delay(1000);
    PORTD |= 0X3C;
    delay(2000);
    del = 100;
    PORTD &= ~0X3C;
   }
}

NOW I ADDED AN 7 SEGMENTS DISPLAY

Code:
unsigned int del = 100;
unsigned int cuen = 0;

void setup() {               
  pinMode(2, OUTPUT);     
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(8, OUTPUT);     
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);   
}

void loop() {
  switch (cuen){
    case 0: PORTB &= ~0X09; PORTB |=0x00; break;
    case 1: PORTB &= ~0X00; PORTB |=0x01; break;
    case 2: PORTB &= ~0X01; PORTB |=0x02; break;
    case 3: PORTB &= ~0X02; PORTB |=0x03; break;
    case 4: PORTB &= ~0X03; PORTB |=0x04; break;
    case 5: PORTB &= ~0X04; PORTB |=0x05; break;
    case 6: PORTB &= ~0X05; PORTB |=0x06; break;
    case 7: PORTB &= ~0X06; PORTB |=0x07; break;
    case 8: PORTB &= ~0X07; PORTB |=0x08; break;
    case 9: PORTB &= ~0X08; PORTB |=0x09; break;
  }
  PORTD |= 0X04;
  delay(del); 
  PORTD &= ~0X04;
  PORTD |= 0X08;
  delay(del);
  PORTD &= ~0X08;
  PORTD |= 0X10;
  delay(del);
  PORTD &= ~0X10;
  PORTD |= 0X20;
  delay(del);
  PORTD &= ~0X20; 
    del=del-10;
  if (del < 20)
  {
    delay(1000);
    PORTD |= 0X3C;
    delay(2000);
    del = 100;
    PORTD &= ~0X3C;
    cuen = cuen +1;
   }
  if (cuen >9 )
  {
    cuen = 0;
   }
}

It's kind of odd inverse the port to change it to another value, but works great!
14  Using Arduino / Programming Questions / Re: Manage ports? on: September 16, 2011, 02:42:57 pm
pinMode(0x0F, OUTPUT) will set Pin 15 (a.k.a.  Analog input 1) as an output.
digitalWrite(0x0F, HIGH) will then set Pin 15 (a.k.a. Analog input 1) to +5v.


You should avoid using Pin 0 and Pin 1 for I/O because those are the hardware serial I/O pins and you won't be able to use Serial.print() debugging messages if you use those pins for other purposes.

You can do direct port manipulation such as PORTD |= 0x3C; to turn on Pins 2,3,4 and 5.  PORTD &= ~0x3C; will trurn those four pins off again.

Yes I noticed that...  thank you for you explaining me how manage directly those ports...
15  Using Arduino / Programming Questions / Re: Manage ports? on: September 16, 2011, 02:39:36 pm
Exactly! now I have another doubt respected this ports, now that I have this commands can I use for example the ADC inputs as digital inputs?
Pages: [1] 2