Hi,
I am testing SPI on the Colibri iMX7 SoM plugged into an Aster Carrier Board running a Win Embedded 7 image.
I am able to see the SPI_CLK signal being generated when I initiate the transfer on the Aster X20 (23 #pin) when I initiate a transfer, but the CS signal is always sitting low, X20 (pin# 26).
Initially I assumed that when I call the Imx7Spi_Open()
it would use the default pin numbers that are specified in the Aster’s manual and the Toradex’s spi library documentation. When this did not work, I used the Imx7Spi_SetConfigInt(hSpi, L"ioCS" ....
to set the ioCS to COLIBRIPIN(86), but that also didn’t do the job.
Below is the code that I am using to initialize and transfer 16 bit frames over the SPI Bus. Surprisingly the ioCS configuration doesn’t seem to change because when I print the ioCS values read back it is set to 16.107, I am not sure how to translate that to SODIMM pin number…
Do you find anything amiss?
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hSpi = NULL;
BOOL bReturn = FALSE;
tVersion ver = {0, 0, 0};
DWORD value = 0;
Spi_GetVersion(&ver);
printf("\nDemo Application for the SPI Library V%d.%d.%d", ver.Major, ver.Minor, ver.Build);
hSpi = Imx7Spi_Init( L"SPI1" );
if( hSpi == NULL )
printf("\nERROR, (%s, %d), Failed to initialize SPI1", __FUNCTION__, __LINE__ );
else
printf("\nOK, (%s, %d), Spi handle created", __FUNCTION__, __LINE__ );
/// Configuring the SPI Port
/// Set Mode
bReturn = Imx7Spi_SetConfigInt(hSpi, L"SpiMode", SpiMode0, StoreVolatile );
if( bReturn == FALSE )
printf("\nERROR, (%s, %d), Failed to set mode SPI", __FUNCTION__, __LINE__ );
/// Set frequency of operation, 1 MHz
bReturn = Imx7Spi_SetConfigInt(hSpi, L"BitRateHz", 1000000, StoreVolatile );
if( bReturn == FALSE )
printf("\nERROR, (%s, %d), Failed to set mode SPI", __FUNCTION__, __LINE__ );
/*************************************************************************
Trying to get the SPI CS to work
**************************************************************************/
/// Checking the current CS configuration
uIo ioCS_pin;
bReturn = Imx7Spi_GetConfigInt( hSpi, L"ioCS", (DWORD *)&ioCS_pin );
if( bReturn == FALSE )
printf("\nERROR, (%s, %d), Failed to get ioCS setting", __FUNCTION__, __LINE__ );
else
{
printf("\nOK, (%s, %d), ioCS ....%d.%d %d", __FUNCTION__, __LINE__, ioCS_pin.ColibriPin.Tp, ioCS_pin.ColibriPin.Nr, ioCS_pin.GenericDefinition );
}
/// Setting the new CS configuration, requesting the SPI library to use
/// COLIBRI SODIMM Pin #86 (Available on Aster's X20 pin # 26)
uIo newCS_Pin = COLIBRI_PIN(86);
bReturn = Imx7Spi_SetConfigInt(hSpi, L"ioCS", (DWORD)newCS_Pin.GenericDefinition, StoreVolatile);
if( bReturn == FALSE )
printf("\nERROR, (%s, %d), Failed to set ioCS setting", __FUNCTION__, __LINE__ );
/// Reading back to check whether the ioCS has been updated
bReturn = Imx7Spi_GetConfigInt( hSpi, L"ioCS", (DWORD *)&ioCS_pin );
if( bReturn == FALSE )
printf("\nERROR, (%s, %d), Failed to get ioCS setting", __FUNCTION__, __LINE__ );
else
{
printf("\nOK, (%s, %d), ioCS ....%d.%d %d", __FUNCTION__, __LINE__, ioCS_pin.ColibriPin.Tp, ioCS_pin.ColibriPin.Nr, ioCS_pin.GenericDefinition );
}
/*************************************************************************
Trying to get the SPI CS to work
**************************************************************************/
bReturn = Imx7Spi_GetConfigInt( hSpi, L"BitsPerWord", &value );
if( bReturn == FALSE )
printf("\nERROR, (%s, %d), Failed to get bits per word setting", __FUNCTION__, __LINE__ );
else
{
printf("\nOK, (%s, %d), Bits per word setting ....%d", __FUNCTION__, __LINE__, value );
if( value != 16 )
{
bReturn = Imx7Spi_SetConfigInt( hSpi, L"BitsPerWord", (DWORD)16, StoreVolatile );
if( bReturn == FALSE )
printf("\nERROR, (%s, %d), Failed to get bits per word setting", __FUNCTION__, __LINE__ );
}
}
bReturn = Imx7Spi_Open( hSpi );
if( bReturn == FALSE )
printf("\nERROR, (%s, %d), Failed to open the spi port", __FUNCTION__, __LINE__ );
while( 1 )
{
DWORD dataCount = 0;
DWORD rxBuffer[2] = { 0xFFFFFFFF, 0xFFFFFFFF };
DWORD spiData[2] = { 0 };
dataCount = Spi_ReadWrite( hSpi, rxBuffer, spiData, 1 );
printf("\nAmount of data received is %d, data (0x%08X)", dataCount, rxBuffer[0] );
Sleep(100);
}
return 0;
}