Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] SPI Communication: ld returned 1 exit status

Status
Not open for further replies.

eebhoi01

Advanced Member level 4
Joined
Feb 22, 2012
Messages
116
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,347
Hi,

I am a newbie to SPI programming and this is my first attempt in learning and coding SPI protocol, I am using Atmel Studio 7 (w/ Atmel 644). My friend gave me a code, for my reference, regarding SPI. I modified the code so that it will work as how I needed it to be. Unfortunately, I got this error "ld returned 1 exit status".

for my SPI.h file

Code:
#ifndef _SPI_H
#define _SPI_H

#include <avr/io.h>

#define LSB = 0;
#define MSB = 1;

//Defining SPI pins configuration ATMEGA 644P
#define SPI_SS 0x10;
#define SPI_MOSI 0x20;
#define SPI_MISO 0x00;
#define SPI_SCK 0x80;
#define SPI_PORT  PORTB
#define PIN_SPI  PINB
#define BIT_SPI_MISO  3

//Defining SPI function configuration
#define SPI_CLCK_Div4 0x00;
#define SPI_CLCK_Div16 0x01;
#define SPI_ClCK_Div64 0x02;
#define SPI_CLCK_Div128 0x03;
#define SPI_CLCK_Div2 0x04;
#define SPI_CLCK_Div8 0x05;
#define SPI_CLCK_Div32 0x06;

#define SPI_Mode0 0x00;
#define SPI_Mode1 0x04;
#define SPI_Mode2 0x08;
#define SPI_Mode3 0x0C;

#define	SPI_MODE_MASK 0x0C;
#define SPI_CLOCK_MASK 0x03;
#define SPI_2XCLOCK_MASK 0X01;

#define WAIT_SPI() while(!(SPSR & _BV(SPIF)))

class SPI
{
  public:

    void init();

    uint8_t send(uint8_t value);

    inline static uint8_t transfer(uint8_t _data, uint8_t mode);

    // SPI Configuration methods

    inline static void attachInterrupt();
    inline static void detachInterrupt(); // Default
    static void end();

    static void setBitOrder(uint8_t);
    static void setDataMode(uint8_t);
    static uint8_t getDataMode();
    static void setClockDivider(uint8_t);
};

extern SPI objSPI;

uint8_t SPI::transfer(uint8_t _data, uint8_t mode)
{
	uint8_t ret,prevmode;
	prevmode = getDataMode();
	setDataMode(mode);
	SPDR = _data;
	while (!(SPSR & _BV(SPIF)))
	;
	ret = SPDR;
	setDataMode(prevmode);
	return ret;	
}
#endif

for my SPI.cpp File

Code:
#include "SPI.h"

void SPI::init() 
{

  SPI_PORT |= _BV(SPI_SS);
  // Configure SPI pins
  DDR(SPI_PORT) &= ~_BV(SPI_MISO);
  
  DDR(SPI_PORT) |= _BV(SPI_SS);
  
  SPI_PORT &= ~_BV(SPI_MOSI);
  SPI_PORT |= _BV(SPI_SS);
   
  // SPI speed = clk/4
  SPCR |= _BV(MSTR);
  SPCR |= _BV(SPE);
  DDR(SPI_PORT) |= _BV(SPI_MOSI);
  DDR(SPI_PORT) |= _BV(SPI_SCK);
}

uint8_t SPI::send(uint8_t value) 
{
  SPDR = value;                          // Transfer uint8_t via SPI
  WAIT_SPI();                            // Wait until SPI operation is terminated

  return SPDR;
}

void SPI::setBitOrder(uint8_t bitOrder)
{
  if(bitOrder == LSB) {
    SPCR |= _BV(DORD);
  } else {
    SPCR &= ~(_BV(DORD));
  }
}

void SPI::setDataMode(uint8_t mode)
{
  SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
  if (mode == SPI_Mode3 || mode==SPI_Mode2)
  {
	  SPI_PORT |= _BV(SPI_SCK);
  }
  else
  {
	  SPI_PORT &= ~_BV(SPI_SCK);
  }
}

uint8_t SPI::getDataMode()
{
  return (SPCR & SPI_MODE_MASK);
}

void SPI::setClockDivider(uint8_t rate)
{
  SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK);
  SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((rate >> 2) & SPI_2XCLOCK_MASK);
}

void SPI::attachInterrupt() {
  SPCR |= _BV(SPIE);
}

void SPI::detachInterrupt() {
  SPCR &= ~_BV(SPIE);
}

SPI objSPI;

Can anyone enlighten me please, why I get such error? I reviewed everything I learned so far, but I can't seem to comprehend this particular error. Thank you for your help and time.

Regards,

eebhoi01
 

check whether the libraries are available in the lib directory/folder.
To test write a small program and compile to see the error messages.
 

I got this error "ld returned 1 exit status"
You did not clearly mention what compiler are using, anyway most of them has an option for a verbose mode for the compilation output, so that you can inspect more exactly the reason for that.
 

I was able to solve the issue, I deleted all of my existing files and, created a new project and pasted all of my codes. Anyhow thank you for your help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top