0

所以我想为我的 PIC18F46J50 microctontroller 实现 FatFs 模块,但我在构建我的项目时遇到错误,我无法提前。我对低级磁盘 Io 模块进行了必要的更改,但我似乎仍然无法使其正常工作。所以这里是初始化我的 SPI 模块的代码:

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 

我得到的错误是 spi.c:59:错误:(1098)变量“_SPI2_Exchange8bit”的声明冲突(diskio.c:78)(908)退出状态 = 1

据我所知,此错误来自缺少原型函数或缺少头文件的包含。但这里都不是这样。希望 some1 可以帮助解决这个问题。谢谢

4

0 回答 0