I try to use the SPI for 3 or 4 days already and have read all your comments.
Yes, i looked at the samples and yes, i know the basics of AT-Programming, but i’ve still have a Problem.
I can write to the bus without Problems, but i can not read!
Here is my code. Please, tell my, what’s wrong?
#define SPI_SPEED 1
/**************************************************************/
void spiInit()
{
s32 returncode ;
u32 data ;
adl_busSPISettings_t spiSettings = {
SPI_SPEED ,
ADL_BUS_SPI_CLK_MODE_3 ,
ADL_BUS_SPI_ADDR_CS_GPIO ,
ADL_BUS_SPI_CS_POL_LOW ,
ADL_BUS_SPI_MSB_FIRST ,
ADL_IO_GPIO | 31 ,
ADL_BUS_SPI_LOAD_UNUSED, // LoadSignal
ADL_BUS_SPI_DATA_UNIDIR, // DataLinesConf
ADL_BUS_SPI_MASTER_MODE, // MasterMode
ADL_BUS_SPI_BUSY_UNUSED, // BusySignal
} ;
TRACE((TL_SPEICHER,"spiInit()"));
spiHandl = adl_busSubscribe(ADL_BUS_ID_SPI, 1, &spiSettings) ;
TRACE((TL_SPEICHER, "adl_busSubscribe(SPI) : %d", spiHandl)) ;
data = 8 ;
returncode = adl_busIOCtl( spiHandl, ADL_BUS_CMD_SET_DATA_SIZE, &data) ;
TRACE((TL_SPEICHER, "adl_busIOCtl( SPI, ADL_BUS_CMD_SET_DATA_SIZE, &data ) : %d", returncode )) ;
data = 0 ;
returncode = adl_busIOCtl( spiHandl, ADL_BUS_CMD_SET_ADD_SIZE, &data) ;
TRACE((TL_SPEICHER, "adl_busIOCtl( SPI, ADL_BUS_CMD_SET_ADD_SIZE, &data ) : %d", returncode )) ;
data = 0 ;
returncode = adl_busIOCtl( spiHandl, ADL_BUS_CMD_SET_OP_SIZE, &data) ;
TRACE((TL_SPEICHER, "adl_busIOCtl( SPI, ADL_BUS_CMD_SET_OP_SIZE, &data ) : %d", returncode )) ;
TRACE((TL_SPEICHER, "spi_Init() complete")) ;
}
/**************************************************************/
void m25pSendSPI(charStream* sendData, charStream* reciveData)
{
s32 returnwert;
int i;
adl_busAccess_t spiWriteMode = {0, 0} ;
TRACE((TL_SPEICHER,"m25pSendSPI() %d",sendData->length));
for(i=0;i<sendData->length;i++)
{
TRACE((TL_SPEICHER,"Data: %x",sendData->pChar[i]));
}
returnwert = adl_busWrite(spiHandl, &spiWriteMode, sendData->length, sendData->pChar) ;
TRACE((TL_SPEICHER,"adl_busWrite: %d",returnwert));
if(reciveData->length>0)
{
returnwert=adl_busRead(spiHandl,&spiWriteMode,reciveData->length,reciveData->pChar);
TRACE((TL_SPEICHER,"adl_busRead: %d",returnwert));
}
}
/**************************************************************/
bool readExFlash( u32 udAddr, charStream *data)
{
charStream sendStream;
u8 pIns_Addr[5];
// Step 1: Validate address input
if(!(udAddr+data->length < FLASH_SIZE))
{
errorLog("Flash-Read-Instruction for wrong Address",udAddr);
return FALSE;
}
// Step 2: Initialize the data (i.e. Instruction) packet to be sent serially
sendStream.length = 5;
sendStream.pChar = pIns_Addr;
pIns_Addr[0] = SPI_FLASH_INS_READ;
pIns_Addr[1] = udAddr>>16;
pIns_Addr[2] = udAddr>>8;
pIns_Addr[3] = udAddr;
pIns_Addr[4] = SPI_FLASH_INS_DUMMY;
// Step 3: Send the packet serially, and fill the buffer with the data being returned
m25pSendSPI(&sendStream, data);
return TRUE;
}
/**************************************************************/
void testFunction(void)
{
charStream stream;
stream.length=20;
stream.pChar=adl_memGet(stream.length);
//Initial SPI
spiInit();
stream.length=20;
for(i=0;i<stream.length;i++)
{
stream.pChar[i]=0;
}
readExFlash(0x100,&stream);
TRACE((1,"StreamerLenght: %d",stream.length));
for(i=0;i<stream.length;i++)
{
TRACE((1,"Resived Data: %x",stream.pChar[i]));
}
}
adl_busWrite without problems, adl_busRead doesn’t work
09/09/30,11:34:31:476 ADL 5 spiInit()
09/09/30,11:34:31:476 ADL 5 adl_busSubscribe(SPI) : 403456816
09/09/30,11:34:31:476 ADL 5 adl_busIOCtl( SPI, ADL_BUS_CMD_SET_DATA_SIZE, &data ) : 0
09/09/30,11:34:31:476 ADL 5 adl_busIOCtl( SPI, ADL_BUS_CMD_SET_ADD_SIZE, &data ) : 0
09/09/30,11:34:31:476 ADL 5 adl_busIOCtl( SPI, ADL_BUS_CMD_SET_OP_SIZE, &data ) : 0
09/09/30,11:34:31:476 ADL 5 spi_Init() complete
09/09/30,11:34:31:476 ADL 5 m25pSendSPI() 5
09/09/30,11:34:31:476 ADL 5 Data: 3
09/09/30,11:34:31:476 ADL 5 Data: 0
09/09/30,11:34:31:476 ADL 5 Data: 1
09/09/30,11:34:31:476 ADL 5 Data: 0
09/09/30,11:34:31:476 ADL 5 Data: aa
09/09/30,11:34:31:476 ADL 5 adl_busWrite: 0
09/09/30,11:34:31:476 ADL 5 adl_busRead: 0
09/09/30,11:34:31:476 ADL 1 StreamerLenght: 20
09/09/30,11:34:31:476 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
09/09/30,11:34:31:585 ADL 1 Resived Data: ff
I always read 0xFF
With the KO, i messure the most bytes 0x00 and some others, but not 0xFF
I’m going to be crasy