最近,我对微芯片通用DSP产品印象深刻,并决定让它成为DSP提供商。在使用上述芯片进行相当复杂的项目后,我假定标准SPI总线将是一种微不足道的设置。我错了。在尝试了数据表中的代码和提供的(经常是冲突的)代码示例之后,我似乎无法使spi在正确的时间正确地切换芯片选择行。WriteSPI3()外围库函数不能控制正常传输,因此在切换CS线路之前,检查相关标志是我的职责;故障似乎没什么作用,CS提前切换。以下是我的代码:SPI3配置:void Init_SPI3(void){IFS5)SPI3IF=0;//清除中断标志IEC5bits.SPI3IE=0;//禁用中断//SPI1CON1寄存器设置6位)SPI3CON1bits.SSEN=0;//No CSSPI3CON1bits.MSTEN=1;//主模式禁用SPI3CON1bits.PPRE=2;//Pre-scalerSPI3CON1bits.SPRE=8;//Pre-scaler 2SPI3CON1bits.SMP=1;//Input数据是在数据输出时间SPI3CON1bits.CKE=0;//在转换时串行输出数据更改SPI3CON1bits.CKP=0;//时钟的空闲状态是低电平;SPI3STATbits.SPIEN=1;//启用SPI模块//中断控制器设置IFS5bits.SPI3IF=0;//清除中断标志IEC5bits.SPI3IE=1;//启用中断}SPI 3 Pin配置:TRISBbits.TRISB10=0;//将SPI3CLK设置为oUTPutTrISBITS.
tiSISB11=0;//Sp3DATAOUT作为OutPurrPrime4位;R/P43CK OUTROPOR4BITS。RP43R=31;//SPI3X数据片外选择线引脚配置:TrISBITS.TISBB4=0;/SPI3 CS在引脚B4上,设置为输出简单主例程:(1=1){ PbBITB.RB4=0;//集CS线到L。WO WrrestPi3(0xAA);//这是来自外围图书馆的安全……同时(!)SPI3STATBITS。SpBBF)。BRB4。RB4=1;//设置CS线到高}以上代码不工作,CS通过传输一半到1。我很困惑,这就是他们在示例代码中也是如何做到的!
以上来自于百度翻译
以下为原文
Recently i was very impressed by microchips general DSP offerings and decided to make it my go to DSP provider. After using the above chip for fairly complicated projects i assumed the standard SPI bus would be a breeze to set up. Boy was i wrong.
After trying out code from the datasheet and the provided (and often conflicting) code examples i cannot seem to make the spi properly toggle the chip select line at the correct time.
The WriteSPI3() peripheral library function does not take control uptil transmission is complete so its my duty to check the relevent flags after, before i toggle the CS line; trouble is nothing seems work, the CS toggles premarturly.
Here is my code:
SPI 3 configuration:
void Init_SPI3 ( void )
{
IFS5bits.SPI3IF = 0; // Clear the Interrupt flag
IEC5bits.SPI3IE = 0; // Disable the interrupt
// SPI1CON1 Register Settings
SPI3CON1bits.DISSCK = 0; // Internal serial clock is enabled
SPI3CON1bits.DISSDO = 0; // SDOx pin is controlled by the module
SPI3CON1bits.MODE16 = 0; // Communication is word-wide (16 bits)
SPI3CON1bits.SSEN = 0; //No CS
SPI3CON1bits.MSTEN = 1; // Master mode disabled
SPI3CON1bits.PPRE = 2; //Pre-scaler
SPI3CON1bits.SPRE = 8;//Pre-scaler 2
SPI3CON1bits.SMP =1; // Input data is sampled at the middle of data output time
SPI3CON1bits.CKE =0; // Serial output data changes on transition from
SPI3CON1bits.CKP = 0; // Idle state for clock is a low level;
SPI3STATbits.SPIEN = 1; // Enable SPI module
// Interrupt Controller Settings
IFS5bits.SPI3IF = 0; // Clear the Interrupt flag
IEC5bits.SPI3IE = 1; // Enable the interrupt
}
SPI 3 Pin configuration:
TRISBbits.TRISB10 = 0; //Set SPI3CLK as output
TRISBbits.TRISB11 = 0; //Set SPI3DATAOUT as output
RPOR4bits.RP42R=32; //SPI3_CLK out
RPOR4bits.RP43R=31; //SPI3_DATA out
Chip select line pin configuration:
TRISBbits.TRISB4 = 0; //SPI3 CS is on Pin B4, set it to Output
Simple main routine:
while(1==1){
PORTBbits.RB4 = 0;//Set CS line to low
WriteSPI3(0xaa); //This is from the peripheral library to be safe....
while(!SPI3STATbits.SPIRBF)
PORTBbits.RB4 = 1; //Set CS line to high
}
The above code does not work, the CS goes to 1 half way through transmission. Im quite perplexed, this is how they do it in the example code too!
0