用PIC32MX250F128D调spi遇到从模式发不出数据的问题
设为主模式时发送正常,设为从模式,另一块单片机模拟外部时钟,不选用片选信号线。往SPI1BUF写数据发现spi发送缓存器一直是满状态!用库函数也不成功,头大呀!
#include <xc.h>
void SPIInit(void)
{
unsigned int rData;
// TRISBbits.TRISB14 = 1;
// PORTBbits.RB14 = 1;
// RPA0Rbits.RPA0R = 0x03;//master ss
RPA1Rbits.RPA1R = 0x03;//data out port PA1
SDI1Rbits.SDI1R = 0x05;//data in port
SS1Rbits.SS1R = 0x00;//slaver ss
IEC1CLR = 0x70;
SPI1CON = 0;//clear
rData = SPI1BUF;
/* IFS1CLR = 0x70;
IPC7CLR = 0x1f000000;
IPC7SET = 0x04000000;
IEC1SET = 0x70;*/
// SPI1BRG = SPI_BRG; //use for clk
SPI1STATCLR = 0x40;
//master
// SPI1CON = 0x8320; //mode 0
// SPI1CON = 0x8220; //mode1
// SPI1CON = 0x8360; //mode 2
// SPI1CON = 0x8260;//mode 3
//slaver
// SPI1CON = 0x8100; //mode 0
// SPI1CON = 0x8000; //mode1
// SPI1CON = 0x8140; //mode 2
// SPI1CON = 0x8040;//mode 3
SPI1CON = 0x8040;
}
unsigned int SPI_SendReadByte(unsigned int dat)
{
while(SPI1STATbits.SPIBUSY);
SPI1BUF = dat;
while(!SPI1STATbits.SPIRBF);
return SPI1BUF;
}
void main(void)
{
//PortInit();
SPIInit();
while(OSCCONbits.SLOCK==0);
while(1)
{
SPI_SendReadByte(0xaa);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>