Tool/software: Code Composer Studio
I want to use the McBSP,and config it as SPI,and now,the SPI can work in correct timing sequence,but I cannot transmit what I want to.
This is I want:one frame has 6 words,each words has 8-bit.
I do not know how to transmit my data(for example:0x123456789ABC). And the wave should like figure 1(I missed one word in the fig ).
But now, what I can see in the logic analyzer is like :
this is my transmit part code:
char x[6]={0x12,0x34,0x56,0x78,0x9a,0xbc}; for(i=0;i<6;i++) { while( McbspbRegs.SPCR2.bit.XRDY == 1 ) {McbspbRegs.DXR1.all=x[i];} DELAY_US(15); }
if I do not use the DELAY_US function,the wave shape is:
it is 7 words,but all words are same.
if I write transmit once,it will send 6 words but but all words are same.
I dont know how to transmit and config the register or is there wrong with my config?
My code like this:
McbspbRegs.SPCR2.all=0x0000; // Reset FS generator, sample rate generator & transmitter McbspbRegs.SPCR1.all=0x0000; // Reset Receiver, Right justify word, Digital loopback dis. McbspbRegs.PCR.all=0x0F08; //(CLKXM=CLKRM=FSXM=FSRM= 1, FSXP = 1) McbspbRegs.SPCR1.bit.DLB = 0; McbspbRegs.SPCR1.bit.CLKSTP = 3; // Together with CLKXP/CLKRP determines clocking scheme McbspbRegs.PCR.bit.CLKXP = 0; // CPOL = 0, CPHA = 0 rising edge no delay McbspbRegs.PCR.bit.CLKRP = 0; McbspbRegs.RCR2.bit.RDATDLY=0; McbspbRegs.XCR2.bit.XDATDLY=0; McbspbRegs.RCR2.bit.RFIG=1; McbspbRegs.XCR2.bit.XFIG=1; McbspbRegs.RCR1.bit.RWDLEN1=0; // 8-bit word McbspbRegs.XCR1.bit.XWDLEN1=0; // 8-bit word McbspbRegs.RCR1.bit.RFRLEN1=6; // 6 word McbspbRegs.XCR1.bit.XFRLEN1=6; // 6 word McbspbRegs.SRGR2.all=0x2000; // CLKSM=1, FPER = 1 CLKG periods McbspbRegs.SRGR1.all= 0x0063; // Frame Width = 1 CLKG period, CLKGDV= McbspbRegs.SPCR2.bit.GRST=1; // Enable the sample rate generator delay_loop(); // Wait at least 2 SRG clock cycles McbspbRegs.SPCR2.bit.XRST=1; // Release TX from Reset McbspbRegs.SPCR1.bit.RRST=1; // Release RX from Reset McbspbRegs.SPCR2.bit.FRST=1; // Frame Sync Generator reset
Is there anyone can give me some advice or some example code I can refer to?? thank you!!