I'm trying to have the McBSP2 on our C5409 do SPI as a master to a serial eeprom.
I'm getting pretty close, but I doesn't quite work. If I send only one byte it works, but when I try to send more than one bytes, all the bytes but the first one have only 7 bit in them!??! (Even though I wait for TEMPTY. I tried TRDY too, with no luck).
I do not use DMA or IRQ, and I have the same behavior from 400kbps all the way to 2Mbps. I haven`t tried any faster.
Anybody has seem something like that before? Any leads on what I might try or check?
void spiInit(void){ SPSA2 = SPCR2_SUB; SPCR22->raw = 0x0000; /* Erase SPCR2 */ SPCR22->bits.grst = 0; /* go into global reset */ SPCR22->bits.xrst = 0; /* put the tx into reset */ SPSA2 = SPCR1_SUB; SPCR12->raw = 0x000; SPCR12->bits.rrst = 0; /* Receiver in reset state */ SPCR12->bits.clkstp = 0x2; /* Set clock to be running only when we have transaction */ SPSA2 = PCR_SUB; PCR2->raw = 0x0000; PCR2->bits.fsxm = 1; /* frame synchro from the sample rate generator */ PCR2->bits.clkxm = 1; /* we are master so we transmit the tx clock */ PCR2->bits.clkrm = 1; /* we are master so we transmit the rx clock */ PCR2->bits.fsxp = 1; /* frame synchro is active low */ PCR2->bits.clkxp = 1; /* clock polarity is high*/ SPSA2 = SRGR1_SUB; SRGR12->raw = 0x0000; SRGR12->bits.clkgdv = 100; /* CPU internal clk is 100MHz /100 -> spi runs at 1MHz*/ SPSA2 = SRGR2_SUB; SRGR22->raw = 0x0000; SRGR22->bits.clksp = 0; /* clock polarity on raising edges edges */ SRGR22->bits.clksm = 1; /* sample rate generator derived from CPU clock */ SRGR22->bits.fsgm = 0; SPSA2 = XCR1_SUB; XCR12->raw = 0x0000; XCR12->bits.xfrlen1 = 0; /* 1 word per frame */ XCR12->bits.xwdlen1 = 0; /* 8 bits per words */ SPSA2 = XCR2_SUB; XCR22->raw = 0x0000; XCR22->bits.xdatdly = 1; /* one bit data delay on tx */ SPSA2 = RCR1_SUB; RCR12->raw = 0x0000; RCR12->bits.rfrlen1 = 0; /* 1 word per frame */ RCR12->bits.rwdlen1 = 0; /* 8 bits per words */ SPSA2 = RCR2_SUB; RCR22->raw = 0x0000; RCR22->bits.rdatdly = 1; /* one bit data delay on tx */ asm(" NOP"); SPSA2 = SPCR2_SUB; SPCR22->raw = 0x0000; SPCR22->bits.grst = 1; /* leaving global reset */ SPCR22->bits.xrst = 1; /* leaving TX reset */ asm(" NOP"); } void spiTxByte(unsigned char byte){ int empty = 1; /* wait for TX to be completed */ while(empty == 1){ SPSA2 = SPCR2_SUB; empty = SPCR22->bits.xempty; } /* transmit the actual data */ DXR12 = (unsigned int)byte; } void spiTxBytes(unsigned char* byte, int len) { int i; int ready = 0; /* wait for TX to be ready */ while(ready == 0){ SPSA2 = SPCR2_SUB; ready = SPCR22->bits.xrdy; } SPSA2 = XCR1_SUB; XCR12->bits.xfrlen1 = len-1; /* word per frame */ for (i=0; i<len;i++){ spiTxByte((unsigned int)(*byte)); byte++; } }