cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Slave to Master

hnrymao
Associate II
Posted on March 02, 2009 at 04:45

SPI Slave to Master

17 REPLIES 17
gilbert1
Associate
Posted on May 17, 2011 at 09:32

Hi,

got the same problem, when I use NSS to chipselect the SPI AD Converter I use there is just the send data in my receive buffer.

Now I tied NSS to Vcc like described in this thread and it works, but I have to generate the CS in software as it is needed by this AD Converter to work.

Looking at the NSS output with a scope and looking at a very nice generated CS signal I still think there is a way to use it. Anybody knows how?

thanks

Gilbert

my port init:

GPIO_DeInit(GPIO3);

/*Gonfigure SSP1_CLK, SSP1_MOSI, SSP1_nSS pins */

GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6 | GPIO_Pin_7;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;

GPIO_Init (GPIO3, &GPIO_InitStructure);

/*Gonfigure SSP1_MISO pin GPIO3.5*/

GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;

GPIO_Init (GPIO3, &GPIO_InitStructure);

mtraman
Associate II
Posted on May 17, 2011 at 09:32

hi

the problem can be solved by using the configuration as given by cofor

GPIO_DeInit(GPIO2);

GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;

GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2 ;

GPIO_Init (GPIO2, &GPIO_InitStructure);

GPIO_DeInit(GPIO3);

GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;

GPIO_Init (GPIO3, &GPIO_InitStructure);

The important thing here is to disable the IPConnected for the outputs - nss, mosi, clk

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;

and enable IPC for Miso

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;

Gilbert try the above code and reply when it works.

bye,

vik

mtraman
Associate II
Posted on May 17, 2011 at 09:32

Hi all,

I too face the same problem. The transmitted data goes correctly but the received data is the same as transmitted data.

People hav recommended that nss pin be pulled high. but there is no place to do that now in my board. can anyone help me out.

thanks in advance,

vik

(ST guys should actually include this in their errata) :|

gilbert1
Associate
Posted on May 17, 2011 at 09:32

Thanks a lot. I did like descibed and now it works very nice:)

[ This message was edited by: gilbertf on 31-03-2007 10:46 ]

rajendrask
Associate II
Posted on May 17, 2011 at 09:32

Hi

If anyone is having code for flash M25P64 communication STR910.

Please let me know.

Please find my attached code. I am not able to read or write into flash.

I can read Flash ID succesfully.

satnam
Associate II
Posted on May 17, 2011 at 09:32

hi!

I WAS FACING THE SAME ERROR, THANKS FOR THE HELP IN SOLVING BY WRITING THE SOLUTIONS.

I HAVE PULLED UP THE NSS PIN AND DISABLED THE IP FOR PINS OTHER THEN MISO.

THANKS....

//MISO

GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;//

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;

GPIO_Init (GPIO5, &GPIO_InitStructure);

//MOSI, SCLK & NSS

GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7;

GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;

GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;

GPIO_Init (GPIO5, &GPIO_InitStructure);

[ This message was edited by: satnam.singh on 01-05-2008 15:09 ]

davebelton9
Associate
Posted on May 17, 2011 at 09:32

It is possible to use SSP0 in Master mode without the need for external pull up on NSS and just using the four SSP pins MISO MOSI SCLK and NSS.

Configure the NSS pin to be a general purpose output and drive it through software to provide the chip select output.

e.g. For SSP0 on port 2

/* Gonfigure SSP0_CLK and SSP0_MOSI */

GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;

GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;

GPIO_Init(GPIO2, &GPIO_InitStructure);

/* Gonfigure SSP0_NSS pin as general purpose I/O */

GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;

GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;

GPIO_Init(GPIO2, &GPIO_InitStructure);

/* Gonfigure SSP0_MISO pin GPIO2.6 */

GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;

GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;

GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ;

GPIO_Init(GPIO2, &GPIO_InitStructure);

Simply set P2_6 low before any read/write and set it high when the data transfer is complete.

I hope this helps

milton
Associate II
Posted on May 17, 2011 at 09:32

Hi Dave, I am having a problem that is the MISO signal is not received and after checking with the oscilloscope I realize that the line is always ''1'', so I guess I have some king of problem with the MISO pin definition. Regarding your tip, what do you mean with your last line:

''Simply set P2_6 low before any read/write and set it high when the data transfer is complete.''

As far as I can see 2.6 is an input, how should I do that?

Thanks a lot.