SPI write

Hi every body,
I want to tranfer data by using SPI bus But i am getting probem at time of using bus write function. What is meaning of bus access mode.Pl’z tell me what shoud i have to do to use SPI driver.


hi Rahul i am facing lots of problem while implementing spi can u guide me … if u have code please copy … plz…

Are you just ignoring all the help you’ve had already?!


once check this code is there any errors let me know please.
finally i wrote this code.this code just writing data into slave …

 * gfgfg.c
 *  Created on: Sep 15, 2009
 *      Author: Kiran
#define RX_SIZE 6
#define TX_SIZE 6
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 1024;
//static u8 RXBuffer[RX_SIZE], TXBuffer[TX_SIZE];
static s32 EuclaseSPIHandle; //Bus handle
adl_busAccess_t   SpiBus_Access={0,0};
 adl_busSPISettings_t EuclaseSPIConfig =
112, // 112 - 115200bps, 127 - 101 kbps
ADL_BUS_SPI_CLK_MODE_0, // Mode 0 clock, rest state 0, data valid on rising edge
ADL_BUS_SPI_CS_POL_LOW, // Chip Select signal is activated in low edge
ADL_IO_GPIO | 31 , // SPI1-CS
ADL_BUS_SPI_WORD_HANDLING, // R/W by word size
ADL_BUS_SPI_DATA_UNIDIR, // 2 pins are used to handle separately I/O data signals


void MyTimerHandler ( u8 ID, void *context )

adl_busWrite(EuclaseSPIHandle, &SpiBus_Access,6, "123456");
adl_atSendResponse ( ADL_AT_UNS, "\r\n SPI1 Write every second \r\n" );

void adl_main ( adl_InitType_e InitType )

  TRACE (( 2, "External Storage sample init" ));
  TRACE (( 2, __DATE__ ));
  TRACE (( 2, __TIME__ ));
/* Set 1s cyclic timer =10*100ms=1second */
adl_tmrSubscribe ( TRUE, 10, ADL_TMR_TYPE_100MS, MyTimerHandler );
EuclaseSPIHandle = adl_busSubscribe(ADL_BUS_SPI1, 1,&EuclaseSPIConfig); // Initiate SPI1
adl_atSendResponse(ADL_AT_UNS, "\r\n SPI Bus Initiate Fail\r\n");

by using this i am able to write the only 4 bytes of data …what is the problem
help in advance …
any suggestions welcome

One doubt … in sdk examples they used as AT+READ,AT+write… this at commands is necessary for developing basic spi communications …?

They simply provide a way for the user to trigger a read and a write.

No, of course they are not necessary- but I find it a very useful aid during development.

If I had some push-buttons available that could be used to trigger the functions, I might use them instead (and that might be more convenient than typing AT commands); but samples provided for general consumption have to use something that will be available to all users - and I think that AT Commands is the only thing that can be assumed to be generally available…

Your code would be a lot easier to read & understand if you took the time to lay it out clearly & neatly, and remove (not just comment-out) unused lines, etc.

Never use TABs to lay-out your code; use only spaces!
The interpretation of TABs is entirely undefined; no two applications can be guaranteed to give the same result - even different users with the same application may have different settings and, therefore, see different results!

Web forums in general are particularly poor at handling TABs

Thanks for u r early response and u r suggestions…
did u check that code?
do u think this code will work ? any errors…
by using this code i am going to develop application sd card interface with Q2686.
i did atmega 16 interface with sd card. by using the same concept i am going to implement on Q2686.
and One thing what is the opcode and address in bussettings how its useful ?
can u explain clear what is the role of opcode and address in spi communication?
i studied adl user guide 6 , but still i am in confusion…

No - as I said, you need to tidy it up to make it legible.

You should also comment it clearly to show what you are trying to achieve, and how you think that the code achieves i; eg,

/* Set 1s cyclic timer =10*100ms=1second */

is not a very useful comment - everything that is in the comment is self-evident form the code itself.

Your comment needs to describe why you are starting a cyclic timer at that point; what is its purpose?


purpose of timer is every 0.1sec i am writing data into slave.
and One thing what is the opcode and address in bussettings how its useful ?
can u explain clear what is the role of opcode and address in spi communication?
i studied adl user guide 6 , but still i am in confusion…

So that needs to be stated in the comment!

Another thing about comments is that they need to be correct - is it really 1s or 0.1s :question:

Think about it!
Take the SPI-connected memory as an example:

To write some data to the memory, 3 things are required:

  1. The Address at which the data is to be written;
  2. Something to tell the slave that a Write operation is required (as opposed to, say, a read or erase);
  3. The actual data.

Looking at the above, where do you think that an “OpCode” (or perhaps you could call it a “command”) and an “Address” could be used… :question:

That got me puzzeled for a while as well :slight_smile:
the Address and OpCode are a structure provided by wavecom to give you a means to set the register address/command once and that write many times without having to include the correct register address in the write-command every time.

it just sends , , on the bus in case of a write.

So the contents of address and opcode depend entirely on the chip you’re writing to.

The one thing the ADL User Guide doesn’t tell is the order of Address and OpCode when both are specified! :angry:

In fact, the OpCode is sent first:

, ,

Of course, “OpCode” and “Address” are just names given arbitrarily by Wavecom - you can use them for whatever purpose you like!

It might have been better if they had chosen more generic names - eg, Prefix1 and Prefix2 - so as not to imply any specific meaning or function… :question: