你好,我是微芯片,这个论坛,我已经真正陷入困境。我使用PIC24FJ128GA202试图写数据到一个微SD卡。我使用的是MPLAB X V3.3和ICD3。我正在将微芯片应用程序库(MLA)用于文件系统,现在我正试图修改fileio代码中的示例来处理我的图片。使用调试器逐步检查代码,我发现它正在等待SPIRBE位来指示接收缓冲区中存在信息,但是该位永远不会被设置。我还试着继续调试,让它运行5分钟左右,但是它仍然停留在while循环中。调用堆栈isSPI1_ExchangeBuffer(uint16_t len=0x0200,void*pRecieveData=0,void*pTransmitData=30)DRV_SPI_GetBuffer()FILEIO_SD_AsyncReadTasks()FILEIO_SD_SectorRead()FILEIO_LoadMBR()FILEIO_DriveMount()main()我的设置已经连接了SPI、SDO、SDO、以及D SCK线从MICROSD卡插座到可编程外围引脚与一个47 K电阻拉到地上对我的PCB。后来,我注意到,MLA代码切换芯片选择关闭,并在SD卡上,所以我焊接线连接RPB13到CS。如果没有CS连接,程序中的DRIVEMUnt函数将在调试时返回FieloEyErrOrthInITHOLL错误。在示意图中,R5、R6、R7 I已经放置0欧姆电阻,而R8、R9、R10是47 K下拉。VDD是3V。我检查了焊接,所有SD卡线路都连接到PIC,它们没有短路在一起。我已经在MLA中为MIC24FJ128GA202中的FLIIO代码修改了这个例子。除了用户实现的功能和LED的调试外,大部分都保持不变。我试图在SD卡SPI 6012A故障排除帖子中进行更改。http://www..hip.com/for./FindPost/842460A。缓冲模式,设置系统频率。我使用drv_spi_16bit_v2.c,因为它具有正确的SFR名称(例如SPIxCON1L、SPIxSTATH、SPIxSTATL而不是SPIxCON1、SPIxSTAT)。我没有做出他的改变或类似的改变,因为据我所知,他的改变是不必要的,因为。看起来和原始代码一样,#i#是一个宏,用括号中的数字i替换##i####,这是他所做的全部更改,将其替换为通道1。我还尝试过启用软件MediaDetect,但是插入时它没有检测到驱动器。sd_spi_config.hI中的SOFT_DETECT也使用通道1I,注意到它说MLA库使用HC振荡器,并且我正在使用FRC振荡器,并且我想知道代码是否只与HC振荡器一起工作?我的相关振荡器配置是初始振荡器是FRC,PLL禁用PLL输入是FRCPrimary振荡器禁用I设置define SYS_CLK_FrequencySystemGet()和所有其他定义频率都为8000000,我试过7370000,没有任何改变。我试过使用PLL(4x),更新系统频率,并将其设置为FRCDIV,但是DriveMount函数返回FILEIO_ERROR_INIT_ERROR。我已将其格式化为FAT32,配置大小为8192字节。我已经尝试重新格式化它,并且具有不同的分配大小。根据数据表,它应该支持SPI模式,工作电压是2.7-3.6V。我不知道我是否包括了调试所需的所有代码,所以如果您需要的话,我可以发布更多的代码,我认为在这里粘贴整个main.c不是个好主意。提前感谢。
以上来自于百度翻译
以下为原文
Hi I am new to microchip, and this forum, and I have gotten really stuck. I am using PIC24FJ128GA202 to try to write data to an microSD card. I am using MPLAB X v3.3, and ICD3. I am using the Microchip Libraries for Applications (MLA) for the filesystem, and right now I am trying to adapt the example in the fileio code to work on my pic. Using the debugger to step through the code, I found that it is waiting for the SPIRBE bit to indicate that there is information in the recieve buffer, but the bit never gets set. I have also tried continuing in debug and letting it run for 5 min or so, but it still stuck in the while loop. This is in the FILEIO_DriveMount function.
while (count) { if (SPI1STATLbits.SPIRBE == false) { *pReceived = SPI1BUFL; pReceived += receiveAddressIncrement; count--; } }
The call stack is SPI1_ExchangeBuffer(uint16_t len = 0x0200, void* pRecieveData =0, void * pTransmitData =30) DRV_SPI_GetBuffer() FILEIO_SD_AsyncReadTasks() FILEIO_SD_SectorRead() FILEIO_LoadMBR() FILEIO_DriveMount() main()
My setup I have connected the SPI, SDO, and SCK lines from the microSD card socket to programmable peripheral pins with a 47k resistor pull down to ground on my PCB. Later, I noticed that the MLA code toggles the Chip select to turn off and on the SD card so I soldered a wire connecting RPB13 to CS. Without the CS connected, the DriveMount function in the program will return FILEIO_ERROR_INIT_ERROR when debugging. In the schematic, R5, R6, R7 I have put 0 ohm resistors, and R8, R9, R10 are the 47k Pull down. VDD is 3V. I checked the soldering and all the SD card lines are connected to the PIC, and none of them are shorted together.
I have adapted the example from the fileio code in the MLA for my PIC24FJ128GA202. Most of it is unchanged except for the user implemented functions and debugging LED. I have tried making the changes in SD card SPI 6012A troubleshooting post. http://www.microchip.com/forums/FindPost/842460 As stated in that post, I set CD to return true always, WP to return false, disabled enhanced buffer mode, and set my system frequency. I am using the drv_spi_16bit_v2.c since this has the right SFR names (such as SPIxCON1L, SPIxSTATH, SPIxSTATL instead of SPIxCON1, SPIxSTAT). I did not make the changes he made or similar to it since, as far as I can tell, his changes were unnecessary because. It seems like the in original code, the ##i## is a macro that replaces the ##i## with the number i in parenthesis, which is all he his change was, replacing it to channel 1.
#define DRV_SPI_STATL(i) SPI##i##STATL #define DRV_SPI_STATLbits(i) SPI##i##STATLbits #define DRV_SPI_STATH(i) SPI##i##STATH //etc
I have also tried enabling software MediaDetect but it does not detect the drive when inserted. #define FILEIO_SD_CONFIG_MEDIA_SOFT_DETECT in sd_spi_config.h I am also using channel 1
I notice that it says the MLA library uses HC oscillator, and I am using the FRC oscillator, and I wonder if the code will only work with HC oscillator? My relevant oscillator configurations are
- initial oscillator is FRC,
- PLL disabled
- PLL input is FRC
- Primary oscillator is disabled
I set #define SYS_CLK_FrequencySystemGet() and all other define frequencies to both 8000000 and I tried 7370000 without any change. I have tried using PLL (4x ), update the system frequency, and setting it to FRCDIV, but then the DriveMount function returns FILEIO_ERROR_INIT_ERROR.
I configured the PPS as shown below
void USER_SdSpiConfigurePins (void) { //TODO configure pins with PPS for spi //RPINR0 = 7; //set INT0 interupt input to pin RP7 __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS
RPINR20bits.SDI1R = 4; //set SPI input to RP4 RPOR2bits.RP5R = 7 ; //set RP5 as SDO RPOR3bits.RP6R = 8 ; //set RP6 to SCK output
__builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS
TRISBbits.TRISB13 = 0; //configure CS pin as output
}
I am using a SanDisk 4Gb MicroSDHC card. I have formatted it to FAT32 with allocation size 8192 bytes. I have tried reformatting it, and with different allocation sizes. According the the datasheet, it should support SPI mode, and operating voltage is 2.7-3.6V.
I don't know if I have included all the necessary code for debugging, so I can post more code if you need it, I didn't think it was a good idea to paste my entire main.c in here. Thanks in advance.
0
|