SPI Bus Initialization
Posted: Mon Aug 29, 2016 12:53 pm
When I initialize the SPI bus, I configure the clock and data to be high when inactive. However,
after initialization the clock stays low until I write to a device. Then it stays high thereafter
when idle. The problem is that the first device I try to initialize on power-up never gets initialized
because the clock starts off with the wrong polarity. If I initialize twice it works, but that seems like
a kludge.
I tried setting the clock high during SPI initialization, but whether I set the clock high before or after
SPI initialization, it doesn't work. Is there something else I can do, or just do the 2-transfers at power-up?
This is for a Nano54415 using v2.8.1.
after initialization the clock stays low until I write to a device. Then it stays high thereafter
when idle. The problem is that the first device I try to initialize on power-up never gets initialized
because the clock starts off with the wrong polarity. If I initialize twice it works, but that seems like
a kludge.
I tried setting the clock high during SPI initialization, but whether I set the clock high before or after
SPI initialization, it doesn't work. Is there something else I can do, or just do the 2-transfers at power-up?
This is for a Nano54415 using v2.8.1.
Code: Select all
DSPIModule SPIM( DEFAULT_DSPI_MODULE );
void spiInit()
{
memset( spiTxBuf, 0, SPI_BUF_SIZE );
memset( (void *)spiRxBuf, 0, SPI_BUF_SIZE );
Pins[SPI_CLK] = 1;
// 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
Pins[SPI_CS_EN].function( PIN_20_GPIO ); // SPI Chip-Select Enable (Not Used)
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 );
Pins[SPI_CLK] = 1;
}