Skip to main content
1040889
Associate
July 28, 2009
Question

spi master mode

  • July 28, 2009
  • 8 replies
  • 1589 views
Posted on July 28, 2009 at 04:42

spi master mode

    This topic has been closed for replies.

    8 replies

    patrickbuchbauer9
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:18

    Sorry,

    I mean the SPI2 clock of course for your case.

    Patrick

    patrickbuchbauer9
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:18

    Hello,

    I think you have to enable the SPI1 clock like

    >RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI1, ENABLE);

    without that it should not run.

    You can look in the example SPI\Simplex_Interrupt\main.c in UM0427.

    And you also take a look at the NVIC configuration, for enable the IRQ Channel for the SPI interrupt.

    Perhaps this can help you.

    Patrick

    1040889
    1040889Author
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 13:18

    Hi,

    I´m using an stm32f103ret6, and i´m trying to read a temperature(ad7814) sensor by spi, but i already lose some days to put this work but spi doesn't cooperating, i'm already use a scopmeter and the sclk isn't generating by the stm.

    Can any one help me? this is my code and I do not know what could be wrong, i'm using stm32 in master mode and i just want to read from the sensor!

    /* SPI2 configuration ------------------------------------------------------*/

    SPI_InitTypeDef SPI_InitStructure;

    /* Enable SPI2 */

    SPI_Cmd(SPI2, ENABLE);

    //SPI_I2S_DeInit(SPI2);

    SPI_InitStructure.SPI_Direction =SPI_Direction_1Line_Rx;

    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

    SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;

    SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;

    SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;

    SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;

    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;

    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

    SPI_InitStructure.SPI_CRCPolynomial = 7;

    SPI_Init(SPI2, &SPI_InitStructure);

    while(1)

    {

    GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_SET);

    delay( 1000000 );

    GPIO_WriteBit(GPIOB, GPIO_Pin_12 ,Bit_RESET);

    while(SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_RXNE) != SET);

    ReceivedData = SPI_I2S_ReceiveData(SPI2);

    GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_SET);

    //SPI_I2S_ClearFlag(SPI2, SPI_FLAG_CRCERR);

    temp_brut = ReceivedData;

    printf(''\r\n temp %d '',ReceivedData );

    }

    //************ Configure SPI2 pins: SCK and MISO******************/

    GPIOB_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 ;

    GPIOB_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIOB_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

    GPIO_Init(GPIOB, &GPIOB_InitStructure);

    //************ Configure SPI2 pins: ~CS ******************/

    GPIOB_InitStructure.GPIO_Pin = GPIO_Pin_12 ;

    GPIOB_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIOB_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

    GPIO_Init(GPIOB, &GPIOB_InitStructure);

    best regards

    icosta

    1040889
    1040889Author
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 13:18

    hi,

    But i read my sensor data sheet and it isn't necessary send anything to work, i already use this sensor in fpga and the only thing that i did was enable de cs line and do the sclk, and the sensor send values, in the stm its necessary send messages even if it is not necessary for the sensor?because i analyze the sclk line and don't have anything!

    best regards ivo costa

    1040889
    1040889Author
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 13:18

    hi,

    I don't post that part of code, but in the attach I have my main.c, and i enable the SPI2 clock like:

    /* Enable USART4 & SPI2 clocks */

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4 | RCC_APB1Periph_SPI2, ENABLE);

    Ivo Costa

    andreas2
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:18

    You have to send something on the SPI in order to receive anything.

    st3
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:18

    Quote:

    Lots ( most ) of the hardware SPI interfaces in uP's do not generate a clock if you don't send anything

    Agreed.

    Quote:

    You could then of course send zero's ...

    Or ones - depending on whether you expect the ''idle'' state of your MOSI line to be high or low...

    [ This message was edited by: st7 on 28-07-2009 08:14 ]

    tom16
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 13:18

    Lots ( most ) of the hardware SPI interfaces in uP's do not generate a clock if you don't send anything( write to the data register ). You could then of course send zero's .....