使用FatFs模块初始化spi时出错

时间:2017-04-21 12:00:59

标签: c microcontroller pic spi fatfs

所以我想为我的PIC18F46J50微控制器实现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可以帮助解决这个问题。感谢

0 个答案:

没有答案