to an EEPROM on the SPI bus. I see the right number of data being written to
memory, but when I read it only reads 70-bytes.
EEPROMs have to be written by pages, and wait for the write-cycle to complete
between page writes. The page size is 256 for this EEPROM. But you can read the
entire EEPROM with a single read.
On a scope I can see each page being written (2.258 pages), but the single read
is only active for the first 70-bytes. Is there something with the setup that may
be causing the read to be short?
Here is the relevant SPI code:
Code: Select all
#define SPI_BUF_SIZE 1024
BYTE spiTxBuf[SPI_BUF_SIZE];
volatile BYTE spiRxBuf[SPI_BUF_SIZE];
OS_SEM DSPI_SEM;
DSPIModule SPIM( DEFAULT_DSPI_MODULE );
spiInit();
spiTxBuf[0] = 3; // Read Command
spiTxBuf[1] = 0; // Address bits 16-23
spiTxBuf[2] = 0; // Address bits 8-15
spiTxBuf[3] = 0; // Address bits 0-7
WORD transferCount = 582; // write 4-bytes + read 578-bytes;
SPIM.SetCS( 0x04 ); // First SPI Memory.
spiTransfer( spiTxBuf, spiRxBuf, transferCount );
BYTE spiTransfer( PBYTE transmitBufferPtr, volatile BYTE* receiveBufferPtr, WORD byteCount)
{
BYTE result = SPIM.Start( transmitBufferPtr, receiveBufferPtr, (DWORD)byteCount, DEASSERT_AFTER_LAST );
OSSemPend( &DSPI_SEM, 0 ); // Wait for DSPI to complete
return result;
}
void spiInit()
{
memset( spiTxBuf, 0, SPI_BUF_SIZE );
memset( (void *)spiRxBuf, 0, SPI_BUF_SIZE );
// Setup I/O pins for SPI bus.
Pins[SPI_CLK ].function( PIN_31_DSPI1_SCK ); // SPI Clock
Pins[SPI_SIN ].function( PIN_33_DSPI1_SIN ); // SPI Data In
Pins[SPI_SOUT ].function( PIN_35_DSPI1_SOUT ); // SPI Data Out
Pins[SPI_CS0 ].function( PIN_15_DSPI1_PCS0 ); // SPI Chip-Select 0
Pins[SPI_CS1 ].function( PIN_37_DSPI1_PCS1 ); // SPI Chip-Select 1
Pins[SPI_CS2 ].function( PIN_39_DSPI1_PCS2 ); // SPI Chip-Select 2
OSSemInit( &DSPI_SEM, 0 ); // Initialize Semiphore for SPI bus.
SPIM.Init( 2000000, // Baudrate
0x08, // BitSz
0x00, // CS
0x0F, // CSPol
0x01, // ClkPol
0x01, // ClkPhase
TRUE, // DoutHiz
0x00, // csToClockDelay
0x00 // delayAfterTransfer
);
SPIM.RegisterSem( &DSPI_SEM );
}