Hi everybody,
I have a project where I am using both McBSP-A and B for SPI communications. The McBSP-A SPI config is working perfectly fine but the B port is not! The code I am using for the B is very similar to A except for data rates and word sizes. This is the code:
void initB_GPIO()
{
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 3; // GPIO24 = MDXB
GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 3; // GPIO25 = MDRB
GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 3; // GPIO26 = MCLKXB
GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0; // Enable pull-up
GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0; // Enable pull-up
GpioCtrlRegs.GPAQSEL2.bit.GPIO25 = 3; // Asynch input GPIO25 (MDRB)
GpioCtrlRegs.GPAPUD.bit.GPIO26 = 0; // Enable pull-up
GpioCtrlRegs.GPAQSEL2.bit.GPIO26 = 3; // Asynch input GPIO26 (MCLKXB)
}
void initB_SPI(void) // (McBSP-B)
{
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 = 1;
McbspbRegs.SPCR1.bit.CLKSTP = 3;
McbspbRegs.PCR.bit.CLKXP = 0;
McbspbRegs.PCR.bit.CLKRP = 1;
McbspbRegs.RCR2.bit.RDATDLY = 1; // FSX setup time 1 in master mode. 0 for slave mode (Receive)
McbspbRegs.XCR2.bit.XDATDLY = 1; // FSX setup time 1 in master mode. 0 for slave mode (Transmit)
McbspbRegs.RCR1.bit.RWDLEN1 = 2; // 16-bit word
McbspbRegs.XCR1.bit.XWDLEN1 = 2; // 16-bit word
McbspbRegs.SRGR2.all = 0x2000; // CLKSM=1, FPER = 1 CLKG periods
McbspbRegs.SRGR1.bit.FWID = 0; // Frame Width = 1 CLKG period
McbspbRegs.SRGR1.bit.CLKGDV = 18; // CLKG frequency = LSPCLK/(CLKGDV+1)
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 */
}
...
then I just call it like this ->
while( McbspbRegs.SPCR2.bit.XRDY == 0 ) {} // wait for any previous SPI transactions to clear
McbspbRegs.DXR1.all = dat;
What I get is the data coming out correct but the clk goes high during the transmission (no toggle). It almost looks like the clk pin is acting like the frame sync pin.
Please help
Thanks,
HC