Loading...
  Show Posts
Pages: 1 2 [3] 4 5 ... 10
31  Using Arduino / Programming Questions / Re: spi 9bit eeprom address can only see addr 0x00? on: May 07, 2013, 12:22:18 pm
thank you for your reply pylon, im still not getting anything, any reads/writes still shows up as '0'.
32  Using Arduino / Programming Questions / spi 9bit eeprom address can only see addr 0x00? on: May 07, 2013, 08:07:02 am
greetings all,
im having trouble getting this eeprom to work correctly - x5045 http://www.intersil.com/content/dam/Intersil/documents/fn81/fn8126.pdf - it takes a 9 bit address i think "datasheet - page 8, table 1 instruction set. i was able to write a value to addr 0 and read it, but thats the only address i can see, i used the following sketch because of the 9 bits, but this is the only way it works for that one address, cant see any others, obviously i have no idea what im doing wrong, any advice please?



Code:
#include <SPI.h>
#define WRITE 2
#define READ  3
#define WREN  6
#define RDSR  5
#define WRSR  1



unsigned int address = 0x00;
byte outval = 243;
byte invalue;

void setup(){
  Serial.begin(9600);


 
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV4); // max clock is 20MHz, so can set high speed
  SPI.begin(); // sets up pin modes etc.
  // Enable writing

  digitalWrite(SS, LOW);
  SPI.transfer(WREN);
  digitalWrite(SS, HIGH);
 
  digitalWrite(SS, LOW);
  SPI.transfer(READ); // read instruction

  SPI.transfer(address >> 16) ;
  SPI.transfer(address >> 8 );
  SPI.transfer(address );
  invalue = SPI.transfer(0);        // Clock out the data
  digitalWrite(SS, HIGH);
  Serial.print(F("Read Data = "));
  Serial.println(invalue,DEC);

}

void loop(){}
33  Using Arduino / Programming Questions / Re: Counter program on: May 03, 2013, 06:49:09 pm
Quote
I'm not an arduino/C# programmer
even someone as new as myself may be able to code that in C++ to do all that, at my stage it would be impossible without the hall switch or whatever kind of switch your counting with.

Code:
if (switch==10){
digitalWrite(motorRelay,LOW)}

but this sounds like it wouldnt be too hard to do, start with the examples and work your way through.
34  Using Arduino / Programming Questions / Re: [Solved] using a mask bit dallas rtc on: May 03, 2013, 11:05:47 am
finally figured this out, all the posts were correct, clearing the mask bits when reading was the key. sorry this stuff was hard for me but i learned alot.
setting the clock for 8pm

Code:
writeRegister(HOURS_REG,B01101000);
lowbyte 1000 is bcd for 8, bits 6 is 12 hour mode, bit 5 is am/pm..
to read..
Code:
byte hours = readRegister(HOURS_REG);
  byte ampm=bitRead(hours,5);
  if (ampm==1){
    meridian=1;
  }
  else{
    meridian=0;
  }
  hours=hours &B10011111; // CLEAR THE MASK BITS HERE
  byte days = readRegister(0x10);
  Serial.print(bcdToDec(hours),DEC);

still working on it, alarm registers etc, there is a library for this particular clock (ds1305) but i wont learn how to deal with the chip directly by using it all the time. and ill never be able to write my own libraries without being able to talk to the chip. next up when im done with 1305 is ds1615 and ds2404. thanks again to all the posters here who helped me.

entire sloppy test code, im just testing and its not optimized, just fyi.
Code:
#include <avr/interrupt.h>
#include <SPI.h>
#define DATAOUT 11//MOSI
#define DATAIN  12//MISO
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss
#define control 240 //READ
#define CONTROL_REG 0x0F
#define DS1305_ADDRESS_OFFSET 0x80
#define SECONDS_REG 0x00
#define MINUTES_REG 0x01
#define HOURS_REG 0x02
#define DAY_REG 0x03
#define DAY_ALARM 0x0A
#define SECONDS_ALARM 0x07
#define MINUTES_ALARM 0x08
#define HOURS_ALARM 0x09
#define DS1305_SR 0x10
#define DS1305_SR_IRQF1 1
#define DS1305_SR_IRQF0 0
boolean meridian;
void setup() {
  // set the slaveSelectPin as an output:

  unsigned int data;
  unsigned int address = 0xF0;
  SPI.begin();
  digitalWrite(SLAVESELECT,LOW);
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE1);
  // initialize SPI:
  pinMode(2, INPUT);
  digitalWrite(2,HIGH);
  attachInterrupt(0, alarmTriggered, FALLING);
  interrupts();
  Serial.begin(9600);
  digitalWrite(SLAVESELECT, HIGH);
  writeRegister(CONTROL_REG,0x03);
  //  unsigned int r = readRegister(CONTROL_REG);
  //  Serial.println("CONTROL = ");
  //  Serial.println(r,BIN);
  //  writeRegister(SECONDS_REG,decToBcd(30));
  //  writeRegister(MINUTES_REG,decToBcd(40));
  // 
  //   
  //   
  //writeRegister(HOURS_REG,B01101000);

  writeRegister(DAY_REG,1);
  writeRegister(HOURS_ALARM,B10010010);
  writeRegister(MINUTES_ALARM,B10010010);
  writeRegister(DAY_ALARM,B10010010);
  writeRegister(SECONDS_ALARM,B1110000);

}

void loop(){

  delay(1000);



  byte seconds = bcdToDec(readRegister(SECONDS_REG));
  byte minutes = bcdToDec(readRegister(MINUTES_REG));
  //  byte hours = bcdToDec(readRegister(HOURS_REG));
  byte hours = readRegister(HOURS_REG);
  byte ampm=bitRead(hours,5);
  if (ampm==1){
    meridian=1;
  }
  else{
    meridian=0;
  }
  hours=hours &B10011111;
  byte days = readRegister(0x10);
  Serial.print(bcdToDec(hours),DEC);
  Serial.print(":");
  Serial.print(minutes,DEC);
  Serial.print(":");
  Serial.print(seconds);
  if (meridian==1){
    Serial.println(" PM");
  }
  else{
    Serial.println(" AM");
  }


  //  writeRegister(0x20,0x30);
  //  r = readRegister(0x20);
  //  Serial.println("0x20 = ");
  //  Serial.println(r,HEX);
}

unsigned int readRegister(byte thisRegister)
{
  byte inByte = 0;
  unsigned int result = 0;

  digitalWrite(SLAVESELECT, HIGH);
  SPI.transfer(thisRegister);
  result = SPI.transfer(0x00);
  digitalWrite(SLAVESELECT, LOW);
  return(result);
}

void writeRegister(byte thisRegister, char thisValue)
{
  digitalWrite(SLAVESELECT, HIGH);
  SPI.transfer(thisRegister+DS1305_ADDRESS_OFFSET);
  SPI.transfer(thisValue);
  digitalWrite(SLAVESELECT, LOW);
}
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

void alarmTriggered()
{
  Serial.println("** ALARM WENT OFF! **");
  writeRegister(DS1305_SR,0);
}
35  Using Arduino / Programming Questions / Re: using a mask bit on: April 25, 2013, 10:35:17 am
wow great replies, i thank you all, awol & crossroads also, thanks so much great information. i have a feeling from my simple lesson im going to learn much more than i anticipated, this is great, good stuff to work with. cheers all

and dont let crossroads fool ya lol, some awesome boards the man has
36  Using Arduino / Programming Questions / Re: using a mask bit on: April 25, 2013, 09:12:44 am
I like using a more direct approach:

value = value | B01000000;  // set bit 6
value = vaue & B10111111; // clear bit 6

I often do this to clear/set a PORTx pin for SPI transfers, vs doing a digitalWrite of a pin.
PORTD = PORTD & B11111011; // using PD2 for SS pin
SPI.transfer(someValue);        // transfer the data
PORTD = PORTD | B00000100;  // SS pin high

hmm, interesting. very. im gonna toy around with this especially since ive seen your work before and like it alot. thx crossroads.
37  Using Arduino / Programming Questions / Re: using a mask bit on: April 25, 2013, 09:10:07 am
Quote
(or whatever 83 converts to from bcd).
Woah!
Don't confuse hex with BCD or decimal.

0b10000011 is 0x83 and BCD 83, but 131 decimal.


yes, and it is confusing for someone just learning (my lesson is getting an spi device to work from reading the datasheet and not using a library) but im careful with the numbers and constantly using the debug window to see whats coming out. also mike, im gonna post the full code, but at this point its just writing and reading a couple registers. the bcd conversion function is by someone else i cant take credit for that, and some of the code is by others also.

Code:
#include <SPI.h>
#define DATAOUT 11//MOSI
#define DATAIN  12//MISO
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss

#define CONTROL_REG 0x0F
#define DS1305_ADDRESS_OFFSET 0x80
#define SECONDS_REG 0x00
#define MINUTES_REG 0x01
#define HOURS_REG 0x02

SPI.begin();
digitalWrite(SLAVESELECT,LOW);
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE1);
  // initialize SPI:

Serial.begin(9600);
  digitalWrite(SLAVESELECT, HIGH);
   writeRegister(CONTROL_REG,0x07);
  unsigned int r = readRegister(CONTROL_REG);
  Serial.println("CONTROL = ");
  Serial.println(r,BIN);
  writeRegister(SECONDS_REG,0);
  writeRegister(MINUTES_REG,decToBcd(17));
  char hn = B00010001;                                    //next few lines is me experimenting, this didnt work so needs to be rewritten
  char mask = B01010001;
writeRegister(HOURS_REG,decToBcd(hn));
  hn|=mask;
  writeRegister(HOURS_REG,decToBcd(hn));
}

void loop(){
  
  delay(1000);

  

  byte seconds = bcdToDec(readRegister(SECONDS_REG));
  byte minutes = bcdToDec(readRegister(MINUTES_REG));
  byte hours = bcdToDec(readRegister(HOURS_REG));
  Serial.print(hours,DEC);
  Serial.print(":");
  Serial.print(minutes,DEC);
  Serial.print(":");
  Serial.println(seconds,DEC);

  
}

unsigned int readRegister(byte thisRegister)
{
  byte inByte = 0;
  unsigned int result = 0;

  digitalWrite(SLAVESELECT, HIGH);
  SPI.transfer(thisRegister);
  result = SPI.transfer(0x00);
  digitalWrite(SLAVESELECT, LOW);
  return(result);
}

void writeRegister(byte thisRegister, char thisValue)
{
  digitalWrite(SLAVESELECT, HIGH);
  SPI.transfer(thisRegister+DS1305_ADDRESS_OFFSET);
  SPI.transfer(thisValue);
  digitalWrite(SLAVESELECT, LOW);
}
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}



38  Using Arduino / Programming Questions / Re: using a mask bit on: April 25, 2013, 08:53:56 am
Quote
but bit 6 is a mask bit so if i set bit6 high i get B01010001(dec83), which totally changes my original 17.
Yes it will. The number 17 is only one way of interpreting what is after all only a pattern of bits. But if you set bit 6 then all the other bits remain the same and that is what matters if I understand your context correctly.

ya but the clock then runs with "83" (or whatever 83 converts to from bcd).

Untested but something along the line of -

Code:
#define setBit(VALUE, BIT)       ((VALUE) |=  (1 << BIT))
#define clearBit(VALUE, BIT)     ((VALUE) &= ~(1 << BIT))

im gonna give this a shot. thank you.
39  Using Arduino / Project Guidance / Re: CASIO calculator and Arduino; joining circuits of different Voltage on: April 24, 2013, 09:41:11 pm
using the 125? i really dont think you can,  a very good detailed explanation http://www.gammon.com.au/forum/?id=10990
40  Using Arduino / Programming Questions / [Solved] using a mask bit dallas rtc on: April 24, 2013, 09:33:18 pm
Hello all,
if i have a byte, say dec17 , B00010001, but bit 6 is a mask bit so if i set bit6 high i get B01010001(dec83), which totally changes my original 17. im thinking im to use |= to change bit 6, but im not having any luck doing it. this is for an rtc which uses bcd. i have my bcd code in place
Code:
writeRegister(MINUTES_REG,decToBcd(17));
void writeRegister(byte thisRegister, char thisValue)
{
  digitalWrite(SLAVESELECT, HIGH);
  SPI.transfer(thisRegister+DS1305_ADDRESS_OFFSET);
  SPI.transfer(thisValue);
  digitalWrite(SLAVESELECT, LOW);
}
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}
and the clock is set and running fine, to enable alarms bit 6 in hours,days, and minutes register has to be "1". im not using a library for the device (ds1305)http://datasheets.maximintegrated.com/en/ds/DS1305.pdf but am looking at the ds1302 library to see how the bits are handled but im not understanding it. thank you.
41  Using Arduino / Project Guidance / Re: CASIO calculator and Arduino; joining circuits of different Voltage on: April 23, 2013, 01:18:43 pm
it means you can use this chip to have 2 different components that use different voltage talk to eachother, ie 3.3v to 5v. its a buffer between the 2.
42  Using Arduino / Project Guidance / Re: CASIO calculator and Arduino; joining circuits of different Voltage on: April 22, 2013, 11:54:43 am
http://www.nxp.com/documents/data_sheet/74HC_HCT125.pdf

not sure if this helps
43  Using Arduino / Project Guidance / Re: Attiny85 and 24lc256 on i2c taking temperature. how to read it? on: April 22, 2013, 11:09:16 am
wait i see, i forgot tinywire.begin, let me revise and retry.

SUCCESS!

thank you C.B.
i just got to put it all together now. revised read/reset/send sketch that works. i use putty, can save it to putty log and import to excel, as long as i know when readings started, i can add the times to excel afterwards, eliminating an rtc for this project. (which i may add anyway later on) thanks again.

Code:
#include <TinyWireM.h>
#define IO_ADDR 0x50
byte data;
unsigned int pointer=0;

void setup(){
  TinyWireM.begin();
  Serial.begin(9600);
  Serial.println("test");
 
  
  for (int i=0;i<20;i++){

    TinyWireM.beginTransmission(IO_ADDR);
    TinyWireM.send(pointer>>8);
    TinyWireM.send(pointer & 0xFF);
    TinyWireM.endTransmission();
    TinyWireM.requestFrom(IO_ADDR,1);
    data=TinyWireM.receive();
    pointer++;
    Serial.println(data,DEC);
    
  }
}

void loop(){
  
}
44  Using Arduino / Project Guidance / Re: Attiny85 and 24lc256 on i2c taking temperature. how to read it? on: April 22, 2013, 10:27:30 am
here is the code, the "test" comes through fine, everything else just blank lines. am i reading the 24lc256 correctly with tinywirem? core is attiny85 @8 internal, bod disabled.

Code:
#include <TinyWireM.h>
#define IO_ADDR 0x50
byte data;
unsigned int pointer=0;

void setup(){
  Serial.begin(9600);
  Serial.println("test");
 
 
//  for (int i=0;i<20;i++){

    TinyWireM.beginTransmission(IO_ADDR);
    TinyWireM.send(pointer>>8);
    TinyWireM.send(pointer & 0xFF);
    TinyWireM.endTransmission();
    TinyWireM.requestFrom(IO_ADDR,1);
    data=TinyWireM.receive();
//    pointer++;
    Serial.println(data);
   
//  }
}

void loop(){
 
}
45  Using Arduino / Project Guidance / Re: Mister pumps on: April 21, 2013, 05:44:10 pm
i dont think house pressure goes that high, but just to run misters? sounds off, i used to build boiler rooms and we had to figure out pump sizes for industrial uses where water would travel 100's of feet, but i havent done the math in years. i think house pressure is 30-36psi, but google i could be wrong. but i wouldnt think you would need much more than that for misters. go to the supermarket and ask to see their setup, im sure they will show you, so what pressure their pushing.
Pages: 1 2 [3] 4 5 ... 10