Before accessing one of the components, I call a function that sets the bus configuration. This has worked fine for several years. Now a new ADC device has been added that is different than the current one, and it requires the opposite clock polarity from all the other devices.
The problem I am having is that when I change the clock polarity, the polarity doesn't change until after I excersize the bus. So I set the polarity and then do a read of the ADC, but the clock polarity hasn't changed. But if I read it a second time, the polarity is now correct. That is not case when setting the other SPI parameters. They take affect immediately. Is there something I can do to change that?
Code: Select all
static DSPIModule SPIM( DEFAULT_DSPI_MODULE );
void SpiSetup( bool Bitsz16, BYTE clkPol, BYTE clkPh, BYTE csToClkDelay, BYTE afterTransferDelay, DWORD baud = 2000000 );
void SpiSetup( bool Bitsz16, BYTE clkPol, BYTE clkPh, BYTE csToClkDelay, BYTE afterTransferDelay, DWORD baud )
{
BYTE bsize = Bitsz16 ? 0x10:0x08; // 8-bit or 16-bit transfers.
SPIM.Init( baud, // Baudrate
bsize, // BitSz
0x00, // CS
0x0F, // CSPol
clkPol, // ClkPol
clkPh, // ClkPhase
0x01, // DoutHiz
csToClkDelay, // csToClockDelay
afterTransferDelay // delayAfterTransfer
);
}
void ReadAnalogs()
{
SpiSetup( true, 0x01, 0x00, 0x00, 0x00 );
ReadADC();
SpiSetup( false, 0x00, 0x01, 0x00, 0x01, 500000 );
ReadPowerSupplyADC();
}