how to read and write with 3-wire SPI interface?


#1

Hi all,
could somebody tell me how to read and write with 3-wire SPI interface to external M25P16 serial flash on the Q2687 module application?
any idea please;
thanks,
Gokhan


#2

gokhan merhaba,

You can find my test code for SPI Serial memory access below. I test this code with Atmel AT45DB series serial flash memories on Q2687 6.63c firmware. Code simply initialize SPI bus and sends 0x9F command for reading memory identification data.

I hope it helps,

#include "adl_global.h"
const u16 wm_apmCustomStackSize = 1024;

#define _SELF_CS_


void tryRead(int opCode);

int intBusHandle = 0;
void* lpReceiveBuffer;
adl_busSPISettings_t sBusSettings;
adl_busAccess_t sBusAccess;

#ifdef _SELF_CS
adl_ioLabel_Q2687_e eIOLabel;
s32					intIOHandler = -1;
#endif

void adl_main ( adl_InitType_e InitType )
{
#ifdef _SELF_CS
	adl_ioConfig_t	sConfig;
	eIOLabel = ADL_IO_Q2687_GPIO_31;
	

	
	sConfig.eDirection = ADL_IO_OUTPUT;
	sConfig.eState = ADL_IO_HIGH;
	sConfig.eLabel.Q2687_Label = eIOLabel;
	sConfig.Pad = 0;
	
	intIOHandler = adl_ioSubscribe(1,&sConfig,ADL_TMR_TYPE_100MS,0,0);
#endif
	
	
	sBusSettings.Clk_Speed = 127;
	sBusSettings.Clk_Mode = ADL_BUS_SPI_CLK_MODE_0;
#ifdef _SELF_CS
	sBusSettings.ChipSelect = ADL_BUS_SPI_ADDR_CS_NONE;
	sBusSettings.GpioChipSelect = 0;
#else
	sBusSettings.ChipSelect = ADL_BUS_SPI_ADDR_CS_GPIO;
	sBusSettings.GpioChipSelect = ADL_IO_Q2687_GPIO_31 ;
#endif
	
	sBusSettings.ChipSelectPolarity = ADL_BUS_SPI_CS_POL_LOW;
	sBusSettings.LsbFirst = ADL_BUS_SPI_MSB_FIRST;
	sBusSettings.WriteHandling = ADL_BUS_SPI_FRAME_HANDLING;
	sBusSettings.DataLinesConf = ADL_BUS_SPI_DATA_UNIDIR;
	
		
	lpReceiveBuffer = adl_memGet(0x0F);
		
	intBusHandle = adl_busSubscribe(ADL_BUS_SPI1,(adl_busSettings_u*)&sBusSettings);
	sBusAccess.Address = 0;
	sBusAccess.AddressLength = 0;
	sBusAccess.OpcodeLength = 8;
	sBusAccess.Size = ADL_BUS_SIZE_BYTE ;
	tryRead(0x9F000000);
}
	

void tryRead(int opCode)
{
	int intReadResult = 0;

#ifdef _SELF_CS
	adl_ioWriteSingle(intIOHandler,eIOLabel,ADL_IO_LOW);
#endif 
	
	sBusAccess.Opcode = opCode;
	wm_memset(lpReceiveBuffer,0x00,0x0F);
	intReadResult = adl_busRead(intBusHandle,&sBusAccess,0x0F,lpReceiveBuffer);
#ifdef _SELF_CS
	adl_ioWriteSingle(intIOHandler,eIOLabel,ADL_IO_HIGH);
#endif
}

#3

Thanks a lot… this information is usefull for me.
Regards
Gokhan