unexpected compilation error message


dear all,

i try use 23lc1024 ram software spi (using digitalio library).

i have modified spiram library :

header :
code: [select]

#define softspiram_lib_version "0.1.4"
//    file: softspiram.h
//  author: k. tyler
// version: 0.1.4
// purpose: arduino library 23a1024/23lc1024 sram memory chip
//     url:
//
// history:
// see softspiram.cpp file

#ifndef softspiram_h
#define softspiram_h

// support old ide's
#if arduino < 100
  #include <wprogram.h>
#else
  #include <arduino.h>
#endif

// #include <spi.h>
#include "digitalio.h"
const uint8_t soft_spi_miso_pin =  7;
const uint8_t soft_spi_mosi_pin =  8;
const uint8_t soft_spi_sck_pin  =  9;
const uint8_t soft_spi_mode = 0;
softspi<soft_spi_miso_pin, soft_spi_mosi_pin, soft_spi_sck_pin, soft_spi_mode> mysoftspi;

// sram instructions
#define rdmr  5
#define wrmr  1
#define write 2
#define read  3

// sram modes
#define byte_mode       0x00
#define page_mode       0x80
#define sequential_mode 0x40

class softspiram {
  public:
    // initialize , specify ss pin
    softspiram      (byte ss_pin);
    
    // change ss pin (used in multi sram chip)
    byte changess   (byte ss_pin);
    
    // read single byte address
    byte readbyte   (uint32_t address);
    
    // write single byte address
    void writebyte  (uint32_t address, byte data_byte);
    
    // read several bytes starting @ address , of length char buffer
    void readbuffer (uint32_t address, char *buffer, uint32_t length);
    
    // write several bytes starting @ address , of length char buffer
    void writebuffer(uint32_t address, char *buffer, uint32_t length);
    
    // write several bytes of value, starting @ address , of length
    void fillbytes  (uint32_t address, byte value, uint32_t length);
    
  private:
    byte _ss_pin;
    void setaddressmode(uint32_t address, byte mode);
};

#endif
// end of file


.cpp file :
code: [select]

// file: spiram.cpp
// author: k. tyler
// version: 0.1.4
// purpose: arduino library 23a1024/23lc1024 sram memory chip
//
// history:
// 0.1.00 - 2013-12-15  initial version.
// 0.1.01 - 2013-12-15  refactored rob tillaart.
// 0.1.02 - 2013-12-17  changed readbytes & writebytes name readbuffer & writebuffer respectfully.
//                      added spi_clock_div8 improve readbuffer reliability.
// 0.1.03 - 2013-12-20  removed spi_clock_div8 added in version 0.1.02 user needs decide if clock needs decreasing.
//                      added code in spiram setup ss pin output use of non standard ss pins.
// 0.1.4  - 2013-12-28  changed readbuffer, writebuffer & fillbytes length uint16_t uint32_t.
//                      added changess function allow multiple sram chips.
//
// released public domain
//

#include <softspiram.h>

softspiram::softspiram(byte ss_pin){
  _ss_pin = ss_pin;                     // store slave select pin
  digitalwrite(_ss_pin,high);           // set ss pin high
  pinmode(_ss_pin,output);              // set output
  mysoftspi.begin();                    // start spi
}

byte softspiram::changess(byte ss_pin){
  byte temp = _ss_pin;                  // current ss pin
  _ss_pin = ss_pin;                     // store slave select pin
  digitalwrite(_ss_pin,high);           // set ss pin high
  pinmode(_ss_pin,output);              // set output
  return temp;                          // return previous ss pin
}

byte softspiram::readbyte(uint32_t address) {
  byte data_byte;
  readbuffer(address, (char*) &data_byte, 1);
  return data_byte;
}

void softspiram::writebyte(uint32_t address, byte data_byte) {
  writebuffer(address, (char*) &data_byte, 1);
}

void softspiram::readbuffer(uint32_t address, char *buffer, uint32_t length) {
  digitalwrite(_ss_pin, low);
  setaddressmode(address, read);
  for (uint32_t = 0; < length; i++) buffer[i] = mysoftspi.transfer(0x00);
  digitalwrite(_ss_pin, high);
}

void softspiram::writebuffer(uint32_t address, char *buffer, uint32_t length) {
  digitalwrite(_ss_pin, low);
  setaddressmode(address, write);
  for (uint32_t = 0; < length; i++) mysoftspi.transfer(buffer[i]);
  digitalwrite(_ss_pin, high);
}

void softspiram::fillbytes(uint32_t address, byte value, uint32_t length) {
  digitalwrite(_ss_pin, low);
  setaddressmode(address, write);
  for (uint32_t = 0; < length; i++) mysoftspi.transfer(value);
  digitalwrite(_ss_pin, high);
}

void softspiram::setaddressmode(uint32_t address, byte mode) {
  mysoftspi.transfer(mode);
  mysoftspi.transfer((byte)(address >> 16));
  mysoftspi.transfer((byte)(address >> 8));
  mysoftspi.transfer((byte)address);
}
// end of file


when compiling test file
code: [select]

#include <softspiram.h>

const uint8_t sram1_pin         = 10;

softspiram spiram(sram1_pin);

unsigned long address = 0x0;
byte data = 0, readdata;

//------------------------------------------------------------------------------

void setup() {
  serial.begin(115200);
}

//------------------------------------------------------------------------------

void loop() {
  spiram.writebyte(address, data);
  readdata = spiram.readbyte(address);

  serial.print("reading @ 0x"); serial.print(address, hex);
  serial.print(": 0x"); serial.println(readdata, hex);

  delay(500);

  data = data + 1 % 0x100 ; address = (address + 1) % 0x20000 ;
}


i have following error message :

c:\users\utilis~1\appdata\local\temp\arduino_build_915073\libraries\softspiram\softspiram.cpp.o (symbol plugin): in function `softspiram::changess(unsigned char)':

(.text+0x0): multiple definition of `mysoftspi'

c:\users\utilis~1\appdata\local\temp\arduino_build_915073\sketch\ourtestsoftspi_20170603.ino.cpp.o (symbol plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

utilisation de la bibliothèque softspiram prise dans le dossier : c:\program files (x86)\arduino-1.8.2\libraries\softspiram (legacy)
utilisation de la bibliothèque digitalio-master version 1.0.0 dans le dossier: c:\program files (x86)\arduino-1.8.2\libraries\digitalio-master
exit status 1
erreur de compilation pour la carte arduino nano

i don't understand: mysoftspi not used in softspiram::changess(unsigned char) !!!
any advice ?

thanks lot help,
kindest regards,

code: [select]
softspi<soft_spi_miso_pin, soft_spi_mosi_pin, soft_spi_sck_pin, soft_spi_mode> mysoftspi;


the definition of mysoftspi must in source , not header file. otherwise gets included in sketch , in code compiled library, that's why linker sees twice.


Arduino Forum > Using Arduino > Programming Questions > unexpected compilation error message


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts