void Mcbsp_gpio_init(void)
{
EALLOW;
/* Configure McBSP-A pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be McBSP functional pins.
// Comment out other unwanted lines.
GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 3; // GPIO24 is MDXB pin (Comment as needed)
GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 3; // GPIO25 is MDRB pin (Comment as needed)
GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 3; // GPIO26 is MCLKXB pin (Comment as needed)
// GpioCtrlRegs.GPAMUX2.bit.GPIO27 = 3; // GPIO27 is MFSXB pin (Comment as needed)
/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.
GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0; // Enable pull-up on GPIO24 (MDXB) (Comment as needed)
GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0; // Enable pull-up on GPIO25 (MDRB) (Comment as needed)
GpioCtrlRegs.GPAPUD.bit.GPIO26 = 0; // Enable pull-up on GPIO26 (MCLKXB) (Comment as needed)
// GpioCtrlRegs.GPAPUD.bit.GPIO27 = 0; // Enable pull-up on GPIO27 (MFSXB) (Comment as needed)
/* Set qualification for selected input pins to asynch only */
// This will select asynch (no qualification) for the selected pins.
// Comment out other unwanted lines.
GpioCtrlRegs.GPAQSEL2.bit.GPIO25 = 3; // Asynch input GPIO25 (MDRB) (Comment as needed)
GpioCtrlRegs.GPAQSEL2.bit.GPIO26 = 3; // Asynch input GPIO26(MCLKXB) (Comment as needed)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO27 = 3; // Asynch input GPIO27 (MFSXB) (Comment as needed)
EDIS;
}
void Mcbsp_ModelFun_init(struct MCBSP_REGS *pMcbspReg )
{
//step1 reset tx rx Place the transmitter and receiver in reset.
pMcbspReg->SPCR2.bit.XRST = 0;
pMcbspReg->SPCR1.bit.RRST = 0;
//step2 Place the sample rate generator in reset
pMcbspReg->SPCR2.bit.GRST = 0;
//step3 Program registers that affect SPI operation
pMcbspReg->SPCR1.bit.CLKSTP = 2;//>=2 spimode
pMcbspReg->PCR.all=0x0F08; //(CLKXM=CLKRM=FSXM=FSRM= 1, FSXP = 1)
// pMcbspReg->PCR.bit.CLKXP =0;//bit1=0:Transmit data is sampled on the rising edge of CLKX.
// pMcbspReg->PCR.bit.CLKRP =0;//bit0:0:Receive data is sampled on the falling edge of MCLKR
pMcbspReg->PCR.bit.CLKXM =1;//master
pMcbspReg->XCR2.bit.XPHASE = 0;//帧中只有一个阶段
pMcbspReg->RCR2.bit.RPHASE = 0;//帧中只有一个阶段
pMcbspReg->RCR2.bit.RDATDLY = 1;//master set 1
pMcbspReg->XCR2.bit.XDATDLY = 1;//master set 1
pMcbspReg->SPCR1.bit.DLB =0;//0: not loopback mode,1:loopback mode
//clk set
pMcbspReg->PCR.bit.SCLKME =0;
pMcbspReg->SRGR2.bit.CLKSM = 1;//LSPCLK
pMcbspReg->SRGR1.bit.CLKGDV = 0xc7;// 0x4a:clkG=(150M/4)/(4A+1)=500Khz;0x7c clkG=(150M/4)/(7c+1)=300Khz;0xc7 :clkG=(150M/4)/(c7+1)=187.5Khz
// pMcbspReg->XCR1.bit.XFRLEN1 = 0;//发送帧中只有一个字
// pMcbspReg->RCR1.bit.RFRLEN1 = 0;//接收帧中只有一个字
// pMcbspReg->XCR1.bit.XWDLEN1 = 0;//8bit per word
// pMcbspReg->RCR1.bit.RWDLEN1 = 0;//8bit per word
pMcbspReg->XCR1.all =0;//XFRLEN1=0,发送帧中只有一个字,XWDLEN1 =0,8bit per word
pMcbspReg->RCR1.all =0;//RFRLEN1 =0,接收帧中只有一个字,RWDLEN1 =0,8bit per word
//step4 Enable the sample rate generator
pMcbspReg->SPCR2.bit.GRST = 1;
clkg_delay_loop();
//step 5 Enable the transmitter and receiver
pMcbspReg->SPCR2.bit.XRST = 1;
pMcbspReg->SPCR1.bit.RRST = 1;
clkg_delay_loop();
}
Ubyte SPI_WriteReadByte( Ubyte wri_data)
{
uint32_t Time_out = 0x1000;
Ubyte reData = 0;
while(McbspbRegs.SPCR2.bit.XRDY == 0)
{
Time_out –;
if(Time_out == 0)
break;
}
McbspbRegs.DXR1.all = wri_data;
while(McbspbRegs.SPCR1.bit.RRDY == 0)
{
Time_out –;
if(Time_out == 0)
break;
}
reData = McbspbRegs.DRR1.all ;
return reData;
}
uint16_t Is25lp064_ReadREMS(void)
{
uint16_t Temp = 0;
FLASH_CS_L;
SPI_WriteReadByte(0x90);
SPI_WriteReadByte(0x00);
SPI_WriteReadByte(0x00);
SPI_WriteReadByte(0x00);
Temp|=SPI_WriteReadByte(0xFF)<<8; //Manufacturer ID =9dh
Temp|=SPI_WriteReadByte(0xFF); //Device ID ID =16h
FLASH_CS_H;
return Temp;
}
Is25lp064_ReadREMS()函数读取的值一直是0xFFFF,不是正确的值0x9d16.
电路连接数据,GP24,25,26 分别作为SIMO、MOSI、CLK 信号连接Flash 和MCP2515。Flash 和MCP2515 的CS芯片用28335 的其它GPIO口控制,引脚设置成DO模式。用示波器可以看到CLK信号(频率是187.5,和设置的值一样)和CS信号的使能状态置bit了,但是接收的数据一直是0xFFFF,不清楚那里设置错了?
Annie Liu:
为更加有效地解决您的问题,我们建议您将问题发布在E2E英文技术论坛上https://e2e.ti.com/support/microcontrollers/c2000/f/171,将由资深的工程师为您提供帮助。我们的E2E英文社区有TI专家进行回复,并得到全球各地工程师的支持,分享他们的知识和经验。