cancel
Showing results for 
Search instead for 
Did you mean: 

(B)SPI -> how does it works...I don´t get an answer from a device

manuelsahm
Associate II
Posted on February 26, 2007 at 13:12

(B)SPI -> how does it works...I don´t get an answer from a device

6 REPLIES 6
manuelsahm
Associate II
Posted on February 21, 2007 at 14:08

Hello; I've got a STR711 IAR StarterKit with Embedded Workbench 4.41A.

I want to configure BSPI0 as Master an connect it to a flash EEPROM (ST M95256W). I connected the 3 lines (MOSI,MISO,CLK) and a line for SS. The SS on the masterside (str7) i configured as GPIO_IN_TRI_CMOS ans set it on ''1'' via BitWrite.

Then I want to send the request 0000 0101 to the EEPROM. This should be force a ReadStatusRegister and this byte should be send by the device. But the device doesn´t send anything; even there´s no clock. There is only a clock when I send Data (WordSend)...

please help me...thx very much...

/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************

* File Name : hw_config.c

* Author : MCD Application Team

* Date First Issued : 10/01/2006 : V1.0

* Description : Hardware Configuration & Setup

********************************************************************************

* History:

* 10/01/2006 : V1.0

********************************************************************************

* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS

* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.

* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,

* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE

* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING

* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.

*******************************************************************************/

/* Includes ------------------------------------------------------------------*/

#include ''71x_lib.h''

#include ''spi_config.h''

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables

/* External variables --------------------------------------------------------*/

extern u16 testvariable;

/* Private function prototypes -----------------------------------------------*/

/* Private functions ---------------------------------------------------------*/

/*******************************************************************************

* Function Name : Set_SPI

* Description : Configures SPI Bus (Master)

* Input : None.

* Output : None.

* Return : None.

*******************************************************************************/

void Set_SPI(void)

{

/* Configure GPI00 on mode Alternate function Push Pull */

GPIO_Config (GPIO0, 0x0006, GPIO_AF_PP);

/* Configure GPI00 Pin 1.3 on mode OUTPUT PUSH PULL */

GPIO_Config (GPIO1, 0x0008, GPIO_OUT_PP);

/* Configure GPI00 Pin 0.3 (SS) on mode INPUT TRSISTATE CMOS */

GPIO_Config (GPIO0, 0x0008, GPIO_IN_TRI_CMOS);

GPIO_BitWrite(GPIO0,3,0x01);

/* -------------------------------------------

Configure BSPI0 as a Master

------------------------------------------- */

/* Enable the BSPI0 interface */

BSPI_BSPI0Conf(ENABLE);

/* Initialize BSPI0 */

BSPI_Init(BSPI0);

/* Configure Baud rate Frequency: ---> APB1/6 */

BSPI_ClockDividerConfig ( BSPI0, 6);

/* Enable BSPI0 */

BSPI_Enable ( BSPI0 , ENABLE );

/* Configure BSPI0 as a Master */

BSPI_MasterEnable ( BSPI0,ENABLE);

/* Configure the clock to be active high */ //CPOL = ClockPolarity

BSPI_ClkActiveHigh(BSPI0,DISABLE);

/* Enable capturing the first Data sample on the first edge of SCK */ //CPHA = Clock Phase

BSPI_ClkFEdge(BSPI0,DISABLE);

/* Set the word length to 8 bit */

BSPI_8bLEn(BSPI0,ENABLE);

/* Configure the depth of transmit to 8 words */

BSPI_TrFifoDepth(BSPI0,1);

/* Configure the depth of receive to 8 word */

BSPI_RcFifoDepth(BSPI0,1);

/* Point on the word to transit */

}

/*******************************************************************************

* Function Name : SPI_ReadStatusRegister

* Description : SPI_ReadStatusRegister

* Input : None.

* Output : None.

* Return : None.

*******************************************************************************/

void SPI_ReadStatusRegister(void)

{

/* ---------------------------------------------

Receive ten words from BSPI0

--------------------------------------------- */

GPIO_BitWrite(GPIO1, 3, 0x00); // set SS to low

BSPI_WordSend(BSPI0,0x05);//''Write'' to memory to realize SPI_ReadStatusRegister

while(!(BSPI0->CSR2 & BSPI_TFE));

NOP();

//check if there are data in Buffer of SPI

if (BSPI0->CSR2 & BSPI_RFNE)

{

testvariable = BSPI_WordReceive(BSPI0);

}

GPIO_BitWrite(GPIO1, 3, 0x01); // set SS to high

}

/*******************************************************************************

* Function Name : SPI_ReadStatusRegister

* Description : SPI_ReadStatusRegister

* Input : None.

* Output : None.

* Return : None.

*******************************************************************************/

void NOP(void)

{

}

/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/

manuelsahm
Associate II
Posted on February 22, 2007 at 12:51

I use another GPIO Port for CS:

/* Configure GPI00 Pin 1.3 on mode OUTPUT PUSH PULL */

GPIO_Config (GPIO1, 0x0008, GPIO_OUT_PP);

but I have to set the SS Pin 0.3 to high (VCC) to select the STR as a master...

General Question:

When is the clock activated ? only when i send bytes ? BSPI0->TRX = data ?

Everytime I activate the clock, are the data from MISO is saved in the buffer, even when i send data ?

Example: When i send 0x02 so at the same time I send the data the Data 0x00 from the MISO line is saved in buffer ? If I make a WordReceive, the the 0x00 comes...????

Right???????

I want to read from a flash memory (ST M95256W). 3 Bytes I want to read...startaddress 0x0000

So I have to send the followed Data:

senddata =

0x03 = Instruction ReadfromMemory

0x00 = Memory address MSB

0x00 = Memory Address LSB

0x00 = DummyByte for Data1

0x00 = DummyByte for Data2

0x00 = DummyByte for Data3

So I send: BSPI_BufferSend(BSPI0,senddata,6);

Now the M95xxx should have send the 3 DataBytes to the ARM7 when I sent the 3 dumy Bytes...? or not ???

When I want to ReadOut the buffer I call:

u8 RecData[10];

BSPI_BufferReceive(BSPI0,RecData,6);

My Data should be in RecData[3], RecData[4],RecData[5]...

Right ???? or NOT???

Thnx for your help

manuelsahm
Associate II
Posted on February 23, 2007 at 13:14

OK ; I Use another GPIO Pin for SS...and pull the Pin 0.3 to high...

A further question:

What is the advantage of a Fifo Depth of 10 words ??? I don´t understand ?

If you mak a BufferSend of 10 Bytes every Byte is send via WordSend cause BufferSend uses WordSend...

So why should the FifoDepth be higher than 1 ????

Can somebody explain me why... thx :-[

luca239955_stm1
Associate II
Posted on February 24, 2007 at 08:36

The advantage il that the new word is put into the fifo anc your CPU has not to wait for the previous word to be transmitted. If you turn off the SPI FIFO and have a look to the signal with an oscilloscope you can see 8 clock cycles coming out for each word an a little pause between a word and the following, if you turn the fifo ON you don't see the pause.

In other words: FIFO makes the communication faster and takes less CPU time.

BUT it's a little more complicate if you have both to receive and transmit!

manuelsahm
Associate II
Posted on February 25, 2007 at 15:05

...and how do I have to use the FIFO buffer... do I have to DISABLE the BSPI first, then copy the Data in the Fifo Buffer and then activate the BSPI to send the Data which is in the FIFO...?

Example(Fifo Depth = 10):

DISABLE_BSPI();

for(i=0;i

BSPI0->TXR = (0x0F>>8);

//Wait until Transmit FIFO Full

ENABLE_BSPI();

please explain me how to use the FIFO Depth...?

Thnx a lot

manuelsahm
Associate II
Posted on February 26, 2007 at 13:12

please...explain me how to use the BUFFERED SPI...

anyone who could print a C Code for receiving 64 Bytes with the buffered SPI...

I don´t know how to use it...

please please help me...

Thnx