I am trying to get my SPI working but I got into several problems.
Here is the functions I am using to get the revision number of my SPI peripheral.
// Structure used in SPI registration
static NASpiDeviceConfigType SPI_CP2120 [] =
{
{
1, /Serial Port, 0 based/
NULL, /Callback function to select the SEEPROM Chip/
NULL, /Callback function to deselect the SEEPROM Chip/
NA_SPI_MODE0, /SPI mode, only mode 0 is supported in NS7520/
NA_SPI_MSB, /most significant bit first/
100000, /speed/
40, /deselect time/
“NWC_CP2120”/unique name for this device/
},
};
void TestSPI (void)
{
NaStatus ccode;
char Revision[2];
ccode = NASpiRegisterDevice(&SPI_CP2120[0]);
if (ccode != NASTATUS_SUCCESS)
{
printf("NASpiRegisterDevice() failed 0x%X
", (unsigned int)ccode);
}
else
{
//Get version from chip
GetCP2120Revision(Revision);
//Deregister the SPI Port
NASpiDeregisterDevice(SPI_CP2120[0].name);
if (ccode != NASTATUS_SUCCESS)
{
printf("NASpiDeregisterDevice() failed 0x%X!
", (unsigned int)ccode);
}
else
{
printf("NASpiDeregisterDevice() success!
");
}
}
return;
}
//Command template is out:[command][don’t care]
// in: [Rev Byte 1] [Rev Byte 2]
void GetCP2120Revision (char* Revision)
{
NaStatus Status;
char Buffer[128];
char Response[128];
memset(Buffer, 0xFF, 128);
memset(Response, 0xFF, 128);
Buffer[0] = 0x40;
//use bufferlength of 4 to include 2 bytes out and 2 bytes in from what I have read on the forum
Status = NASpiReadWrite(SPI_CP2120[0].name, Buffer, Response, 4);
if(NA_IS_SUCCESS(Status))
{
Revision[0] = Response[0];
Revision[1] = Response[1];
printf("SPI Success
");
}
}
With this code I am using getting the error NASTATUS_SPI_MASTER_INVALID_BUFFER.
Anyone has any idea why this is happening? Am I wrong to assume that if my buffer has a length of 128 bytes that it should be 32-bits aligned?
Regards