请问如何以查询的方式使用SPI收发数据?C6748
lbbook:
回复 noaming:
请问在接入ADC后测量SOMI引脚一直为高电平,为什么SPI读出来的结果是0x00。程序是基于LCDK6748开发板的例程修改的,ADS8331,
noaming:
回复 lbbook:
SPI的其他信号都测量一下,看看是什么情况
lbbook:
回复 noaming:
现在CLK SIMO信号都是有的,CS也是有的,就是SOMI不正常,一直是高电平,而且rx读出来都是0x00
初始化程序是改自开发板:
//** Configures SPI Controllerstatic void SetUpSPI(void){ unsigned char cs = 0x20;//0x04;****************** unsigned char dcs = 0x20;//0x04;****************** unsigned int val = SIMO_SOMI_CLK_CS5; SPIReset(SOC_SPI_0_REGS);
SPIOutOfReset(SOC_SPI_0_REGS);
SPIModeConfigure(SOC_SPI_0_REGS, SPI_MASTER_MODE);
SPIClkConfigure(SOC_SPI_0_REGS, 150000000, 1000000, SPI_DATA_FORMAT0);//SCLK原为1M
SPIPinControl(SOC_SPI_0_REGS, 0, 0, &val);
SPIDefaultCSSet(SOC_SPI_0_REGS, dcs);
/* Configures SPI Data Format Register */ SPIConfigDataFmtReg(SPI_DATA_FORMAT0);
/* Selects the SPI Data format register to used and Sets CSHOLD * to assert CS pin(line) */ SPIDat1Config(SOC_SPI_0_REGS, (SPI_CSHOLD | SPI_DATA_FORMAT0), cs);
/* map interrupts to interrupt line INT1 */ SPIIntLevelSet(SOC_SPI_0_REGS, SPI_RECV_INTLVL | SPI_TRANSMIT_INTLVL);
/* Enable SPI communication */ SPIEnable(SOC_SPI_0_REGS);}//** Configures Data Format register of SPIstatic void SPIConfigDataFmtReg(unsigned int dataFormat){ /* Configures the polarity and phase of SPI clock */ SPIConfigClkFormat(SOC_SPI_0_REGS,(SPI_CLK_POL_HIGH | SPI_CLK_INPHASE),dataFormat);//SPI_CLK_POL_HIGH SPI_CLK_OUTOFPHASE //SPIConfigClkFormat(SOC_SPI_0_REGS,(SPI_CLK_POL_LOW | SPI_CLK_INPHASE),dataFormat);
/* Configures SPI to transmit MSB bit First during data transfer */ SPIShiftMsbFirst(SOC_SPI_0_REGS, dataFormat);
/* Sets the Charcter length */ SPICharLengthSet(SOC_SPI_0_REGS, CHAR_LENGTH, dataFormat);}
//** Enables SPI Transmit and Receive interrupt.** Deasserts Chip Select line.static void SpiTransfer(void){ SPIIntEnable(SOC_SPI_0_REGS, (SPI_RECV_INT | SPI_TRANSMIT_INT)); while(flag); flag = 1; /* Deasserts the CS pin(line) */ SPIDat1Config(SOC_SPI_0_REGS, SPI_DATA_FORMAT0, 0x20);}
//** Data transmission and receiption SPIIsrvoid SPIIsr(void){ unsigned int intCode = 0;
IntEventClear(SYS_INT_SPI0_INT);
intCode = SPIInterruptVectorGet(SOC_SPI_0_REGS);
while (intCode) { if(intCode == SPI_TX_BUF_EMPTY) { SPITransmitData1(SOC_SPI_0_REGS, tx_data); SPIIntDisable(SOC_SPI_0_REGS, SPI_TRANSMIT_INT); }
if(intCode == SPI_RECV_FULL) { rx_data = (short)SPIDataReceive(SOC_SPI_0_REGS); flag = 0; SPIIntDisable(SOC_SPI_0_REGS, SPI_RECV_INT); }
intCode = SPIInterruptVectorGet(SOC_SPI_0_REGS); }}
noaming:
回复 lbbook:
你单步调试一下这个函数,看看是什么情况
while (intCode){if(intCode == SPI_TX_BUF_EMPTY){SPITransmitData1(SOC_SPI_0_REGS, tx_data);SPIIntDisable(SOC_SPI_0_REGS, SPI_TRANSMIT_INT);}
if(intCode == SPI_RECV_FULL){rx_data = (short)SPIDataReceive(SOC_SPI_0_REGS);flag = 0;SPIIntDisable(SOC_SPI_0_REGS, SPI_RECV_INT);}
intCode = SPIInterruptVectorGet(SOC_SPI_0_REGS);}}
noaming:
回复 noaming:
最好观察一下rx_data = (short)SPIDataReceive(SOC_SPI_0_REGS);这个函数的内部执行情况。。。
noaming:
回复 noaming:
以及对应测量一下SPIDataReceive(SOC_SPI_0_REGS);这个函数执行时的SPI管脚时序情况
lbbook:
回复 noaming:
已初步确定是时序问题,模拟SPI已经能够正常接收,谢谢Titan
另外请问要是想分时驱动一个SPI接口上的不同芯片,cs信号在编程的时候应该怎么设置,例程里面SPI发送前后都会有这么一句SPIDat1Config(SOC_SPI_0_REGS, SPI_DATA_FORMAT0, 0x20);,请问有多个CS信号怎么弄呢?
noaming:
回复 lbbook:
你好,要使用SPI接口的不同的spi设备,需要使能不同的cs信号。可以通过SPI Default Chip Select Register (SPIDEF)来使能不同的片选信号。