Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Abstract base class on: March 14, 2012, 06:06:56 am
Ok so i think the way i should implement this is with a templated function.
i probably should of explained a bit more of what i was doing but anyway.

this is part of my original code, for reading from an eeprom chip.
byte at93c::readbyte(int address){
  byte datain;
  int _address = (address << (16 - _addresslength));
  digitalWrite(_cspin, HIGH);
  _shiftOut(_dopin, _skpin, B110, 3);
  _shiftOut(_dopin, _skpin, _address, _addresslength);
  datain = _shiftIn(_dipin, _skpin, MSBFIRST, _datalength);
  digitalWrite(_cspin, LOW);
  return datain;
word at93c::readword(int address){
  word datain;
  int _address = (address << (16 - _addresslength));
  digitalWrite(_cspin, HIGH);
  _shiftOut(_dopin, _skpin, B110, 3);
  _shiftOut(_dopin, _skpin, _address, _addresslength);
  datain = _shiftIn(_dipin, _skpin, _datalength);
  digitalWrite(_cspin, LOW);
  return datain;

Based either on the setting of an organisation pin or the design of the part each address stores/reads either 8 bits or 16bits.
What I want to get rid of is duplicating function read for bytes or words.
for writing to the chip, the data type (byte/word) can be inferred from the data passed to the writing function.
as in the example given by Nick
template<typename T> T add (const T x, const T y)
  return x + y;
  }  // end of add

the problem i face is for reading the data the returned type cannot be inferred from the arguments but must come from a the organisation variable (org) given in the contructor.

if org = 8 read(int address) returns byte
if org = 16 read(int address) returns word

2  Using Arduino / Programming Questions / Abstract base class on: March 13, 2012, 06:41:27 am

i have written a library that currently has different functions for different versions of a family of parts but which essentially do the same thing.
I was recommended to use an abstract base class and then different subclasses but i do not know how to implement this.

The point would be that the functions would be the of the same name, but pass and return different data types depending on the version of the part passed by the constructor.

Does anyone have any examples for this kind of coding


3  Using Arduino / Storage / Re: serial eeprom on: February 20, 2012, 06:45:43 am
G'day raees

i have already had experience with using a similar chip, the at93c56. This one includes an active org pin so you can set it to either 8 or 16 bit organisation. I think yours is manufactured as an 8 bit organisation.

I have written a library to interface with these chips, you can have a look at it here,89658.0.html
Anything discussed below will refer to the library, so i suggest you read the header comments first which will help you make sense of what i say below.

the library utilises five pins one of which is for the org pin. since yours is set i think you will be able to set pin variable to an arbitrary pin, it will set it to either a high or low state but you will be able to use it afterwards i think. But you still must be give a variable for the organisation. 

It will handle all the opp codes and timing. since it can handle both 8 and sixteen bit organisation some commands are divided into either byte or word commands.The comments in the library should explain that better. It is messy code but it was my first real foray into writing a library. 

4  Using Arduino / Storage / Re: Atmel 93c series serial eeprom library on: February 20, 2012, 06:15:38 am
thanks jgoulder for your reply

thanks for the good feedback,
ok so
1. these magic numbers are a start bit and then an opcode, some of the opcodes extend into the address frame (writeall) of the instruction so that is why some are longer than others. numbers that come after this are written to cycle the clock for the correct number of cycles.

2. I don't get really what you mean by this. I have used a private function as the standard shiftin/ shiftout function in the Arduino does 8 clock cycles at a time for a byte. So instead these private functions can be set to any length.

3. The shiftin/shiftout functions can be set to either most significant bit first or least significant bit first. I have used this as the function will then read any variable from basically left to right.

4. For certain functions ie reading and writing bytes from the chip only a byte variable is needed for the data. Depending on the organisation and size of the chip the address is either 8 or 9 bits long, so that is why a word variable is used instead, this in theory i think will also save on ram by using the smallest usable variable needed. the uint types are left over from code i used out of another library which i forget, i think for a pic based program, but is the shift out and shift in functions with a variable length. Which if i could have been bothered and came up with the idea been taken from the arduino code library.

5. i tested it on the chip i got and it seemed to work, so it must not be a problem and also the digital writes come at the start and end of the functions, so i think it won't effect any max frequency.

6. I did think of that but the tutorials i read didn't explain what i needed to do well enough for me to understand. Especially how to set it up to pass any initiating variables.

7. I get what you mean, especially explaining stuff like the magic numbers. 

I don't think many people would be using these chips as it was out of a very old sound card and there are other more commonly used chips preferred by the microcontroller community, i think something along the lines or 27 something.

Ah i didn't relies you could edit the playground section to include your own stuff.

I was thinking something like that.

Thanks for your help. I might get round to posting an updates version sometime soon.

ps. if you're really interested i have included the data sheet
5  Using Arduino / Storage / Atmel 93c series serial eeprom library on: January 31, 2012, 07:06:50 am
G'day everyone.

I have been just getting into arduino and programming in general but that hasn't stopped me from trying to write a library.

Amongst some components i pulled out of motherboards and sounds cards was an Atmel at93c66 Serial eeprom chip.

Working from the datasheet and tutorials i have written this library to work with the three different chips 46, 56, 66 and the two organisations 8 or 16 bit.

I have included the code as a zip.

I would really like some feedback on my code, if i'm lucky someone to test it on the other 2 chips.

If i was to distribute this code what would be the best way to do this? ( licence, location etc)
Pages: [1]