0

So i want to implement the FatFs module for my PIC18F46J50 microctontroller and i get an error building my project which i cant get ahead of. I did my necessary changes on the low level disk Io modules but i still cant seem to get it working. So here is the code of initializing my SPI module:

spi.c

#include <xc.h>
#include "spi.h"

/**
Section: Macro Declarations
*/

#define SPI_RX_IN_PROGRESS 0x0

/**
Section: Module APIs
*/

 void SPI2_Initialize(void) {
// Set the SPI2 module to the options selected in the User Interface

// R_nW write_noTX; P stopbit_notdetected; S startbit_notdetected; BF RCinprocess_TXcomplete; SMP Sample At Middle; UA dontupdate; CKE Active to Idle; D_nA lastbyte_address; 
SSP2STATbits.CKE = 1;

// SSPEN enabled; WCOL no_collision; CKP Idle:Low, Active:High; SSPM FOSC/64; SSPOV no_overflow; 
SSP2CON1bits.WCOL = 1;


// SSP2ADD 0; 
       SSP2ADD = 0x00;
}

void SPI2_Open(void) {
// Set the SPI2 module to the options selected in the User Interface

// R_nW write_noTX; P stopbit_notdetected; S startbit_notdetected; BF RCinprocess_TXcomplete; SMP Sample At Middle; UA dontupdate; CKE Active to Idle; D_nA lastbyte_address; 
SSP2STATbits.CKE = 1;

// SSPEN enabled; WCOL no_collision; CKP Idle:Low, Active:High; SSPM FOSC/4; SSPOV no_overflow; 
SSP2CON1bits.WCOL = 1;
SSP2CON1bits.SSPM = 0b0010;

// SSP2ADD 0; 
SSP2ADD = 0;
}

uint8_t SPI2_Exchange8bit(uint8_t data) {
// Clear the Write Collision flag, to allow writing
SSP2CON1bits.WCOL = 0;

SSP2BUF = data;

while (SSP2STATbits.BF == SPI_RX_IN_PROGRESS) {
}

return (SSP2BUF);
}

 uint8_t SPI2_Exchange8bitBuffer(uint8_t *dataIn, uint8_t bufLen, uint8_t *dataOut) {
uint8_t bytesWritten = 0;

if (bufLen != 0) {
    if (dataIn != NULL) {
        while (bytesWritten < bufLen) {
            if (dataOut == NULL) {
                SPI2_Exchange8bit(dataIn[bytesWritten]);
            } else {
                dataOut[bytesWritten] = SPI2_Exchange8bit(dataIn[bytesWritten]);
            }

            bytesWritten++;
        }
    } else {
        if (dataOut != NULL) {
            while (bytesWritten < bufLen) {
                dataOut[bytesWritten] = SPI2_Exchange8bit(DUMMY_DATA);

                bytesWritten++;
            }
        }
    }
}

return bytesWritten;
}

 bool SPI2_IsBufferFull(void) {
 return (SSP2STATbits.BF);
 }

 bool SPI2_HasWriteCollisionOccured(void) {
return (SSP2CON1bits.WCOL);
}

void SPI2_ClearWriteCollisionStatus(void) {
SSP2CON1bits.WCOL = 0;
}

spi.h

#ifndef _SPI_H
#define _SPI_H

/**
Section: Included Files
*/

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#define DUMMY_DATA 0x0

void SPI2_Initialize(void);
void SPI2_Open(void);
uint8_t SPI2_Exchange8bit(uint8_t data);
uint8_t SPI2_Exchange8bitBuffer(uint8_t *dataIn, uint8_t bufLen, uint8_t *dataOut);
bool SPI2_IsBufferFull(void);
bool SPI2_HasWriteCollisionOccured(void);
void SPI2_ClearWriteCollisionStatus(void);

#endif 

Error i get is spi.c:59: error: (1098) conflicting declarations for variable "_SPI2_Exchange8bit" (diskio.c:78) (908) exit status = 1

as far as i know this error comes from a missing prototype function or an missing include of a header file. but none of that is the case here. hope some1 can help out on this. thanks

keko
  • 37
  • 10
  • 1
    OK, well, what's in diskio.h/c? – ThingyWotsit Apr 21 '17 at 12:50
  • There is no variable called `_SPI2_Exchange8bit` in any of the code posted. Possibly some sort of name mangling? It probably won't be possible for anyone to recreate this problem without the seeing file that caused the error. Note: you shouldn't write identifiers that begin with underscore, these are reserved. It may very well be that `_SPI_H` collides with something in the compiler. – Lundin Apr 21 '17 at 13:46

0 Answers0