Tool/software: Code Composer Studio
Hi,
I have a problem with the McBSP used as SPI operation as Master.and I test the example in controlSUITE for McBSP in SPI loopback mode. It located at ..\controlSUITE\device_support\f2833x\v141\DSP2833x_examples_ccsv5\mcbsp_spi_loopback. It works well,when I change "McbspbRegs.RCR1.bit.RWDLEN1=5;" with 2(16bit ),or with 0(8bit) .it work well.
but when I set DLB=0, receive data is always 0xff.and I don't no way.
My configuration Hardware:
GP24,25,26 respectively as SIMO、MOSI、CLK signal connect Flash(IS25LP064) and MCP2515.Flash cs signal use GP59 pin that set in do mode, MCP2515 cs signal use gp27 pin that set in do mode.
My configuratuon Software:
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;
pMcbspReg->SPCR2.bit.FRST = 0;
pMcbspReg->PCR.all=0x0F08; //(CLKXM=CLKRM=FSXM=FSRM= 1, FSXP = 1)
pMcbspReg->SPCR1.bit.DLB =0;//0: not loopback mode,1:loopback mode
//step3 Program registers that affect SPI operation
pMcbspReg->SPCR1.bit.CLKSTP = 2;//>=2 spimode
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->XCR1.all =0;//XFRLEN1=0,发送帧中只有一个字,XWDLEN1 =0,8bit per word
pMcbspReg->RCR1.all =0;//RFRLEN1 =0,接收帧中只有一个字,RWDLEN1 =0,8bit per word
//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
//step4 Enable the sample rate generator
pMcbspReg->SPCR2.bit.GRST = 1;
clkg_delay_loop();
//step 5 Enable the transmitter and receiver
pMcbspReg->SPCR1.bit.RRST = 1;
pMcbspReg->SPCR2.bit.XRST = 1;
pMcbspReg->SPCR2.bit.FRST = 1;
clkg_delay_loop();
}
Ubyte SPI_WriteReadByte( Ubyte wri_data)
{
// Ubyte reData = 0;
McbspbRegs.DXR1.all = wri_data;
while(McbspbRegs.SPCR1.bit.RRDY == 0){}
return McbspbRegs.DRR1.all ;
// reData = McbspbRegs.DRR1.all ;
// return reData;
}
#define FLASH_CS_H Gpio_Write_TE(59, 1)
#define FLASH_CS_L Gpio_Write_TE(59, 0)
uint16_t Is25lp064_ReadREMS(void)
{
uint16_t Temp = 0;
FLASH_CS_L;
Temp = SPI_WriteReadByte(0x90);
Temp = SPI_WriteReadByte(0x00);
Temp = SPI_WriteReadByte(0x00);
Temp = SPI_WriteReadByte(0x00);
Temp|=SPI_WriteReadByte(0xFF)<<8; //Manufacturer ID =9dh
Temp|=SPI_WriteReadByte(0xFF); //Device ID ID =16h
FLASH_CS_H;
return Temp;
}
void Is25lp064_Init(void)
{
Gpio_Set_Do_TE(59, TI_DO_PP);//flash_cs
Gpio_Set_Do_TE(58, TI_DO_PP);//flash_wp
Gpio_Set_Do_TE(63, TI_DO_PP);//flash_hold
Gpio_Write_TE(58, 1);//0是写保护状态,1是不保护状态
Gpio_Write_TE(63, 1);//拉低可以使设备处于暂停状态,恢复会高,设备继续拉低之前的工作 ,set 1不暂停
FLASH_CS_H;//default not select
Mcbsp_gpio_init();
}
#define MCP2515_CS_H Gpio_Write_TE(27, 1)
#define MCP2515_CS_L Gpio_Write_TE(27, 0)
Ubyte SPI_TX[20], SPI_RX[20];
void Mcp1515_Init(void)
{
Gpio_Set_Do_TE(27, TI_DO_PP);//mcp2515_cs
MCP2515_CS_H;//cs=1
Gpio_Set_Di_TE(MCP2515_INT, TI_DI_NOPULL);//mcp2515_int
Gpio_Set_Do_TE(50, TI_DO_PP);//mcp2515_reset
Gpio_Write_TE(50, 0);//mcp2515_reset set 0 reset mode
// Sys_Delay(2);
Gpio_Write_TE(50, 1);//
/*MCp2515 和 Flash 共用 mcbsp接口 由于 Flash的初始化中调用了 Mcbsp_gpio_init 这里就不需要再次调用了。
*
*
* */
}
void SPI_WR(Ubyte len)
{
Ubyte i = 0;
uint32_t Time_out = 0x1000;
MCP2515_CS_L;//CS enable
for(i=0; i<len; i++)
{
SPI_RX[i] = SPI_WriteReadByte(SPI_TX[i]);
}
MCP2515_CS_H; //cs Disable
}
int main()
{
// //flash
Is25lp064_Init();//flash gpio init
// //mcp2515
Mcp1515_Init();//mcp2515 gpio init
Mcbsp_ModelFun_init(&McbspbRegs);
while(1)
{
sdata1= Is25lp064_ReadREMS();
}
}