/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Configuration two Prima2 board for SPI transfer

Username:     
Password:     
             

Forum

# 1   2010-03-30 09:34:21 Configuration two Prima2 board for SPI transfer

marco77
New member
Registered: 2010-03-08
Posts: 4

Configuration two Prima2 board for SPI transfer

Hi



I pretty new with this forum and plan to use two PRIMA2 boards for SPI transfer using the external JP2 connector.

On the schematic, there also the U2 audio codec on the SPI2 connected
to the STM32 and wondering is need to disable it because it can pissibly cause contention
on the SPI bus and if pull-up of pull-down resistor are necessary for CS.

If someone can point me on software template or example using the SPI bus
for the master and slave PRIMA2 it will be appreciate.

Thank you in advance for your help.

Jean-Marc

Offline

 

# 2   2010-03-31 07:07:05 Configuration two Prima2 board for SPI transfer

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Configuration two Prima2 board for SPI transfer

Hi,

Effectively the Audio codec is connected on SPI2 and SPI3 bus, But the SPI2 is only used in Voice mode.
If you keep this peripheral in Audio mode (see the CircleAPI to use the AUDIO_Init_audio_mode function), it runs in I2S slave mode, with his DX ouptput in high impedance (linked to SPI2_MOSI). It also does not use the SPI_MOSI pin. So, it should not cause contention on the bus.

There were some questions on SPI2 on this forum, but I don't know if anyone has developped some application using the Primer2 SPI2.

Yves

Offline

 

# 3   2010-04-01 07:59:03 Configuration two Prima2 board for SPI transfer

marco77
New member
Registered: 2010-03-08
Posts: 4

Re: Configuration two Prima2 board for SPI transfer

Thank Yves for your reply

In the message name, I misspelled the Primer2 name board (and not Prima2 board)

According to the Codec (STw5094A) datasheet
¨
When power is first applied, the “power on reset” circuitry initializes STw5094A and puts it into the power down state. All the Registers are initialized as indicated in the Control Register description section. All the functions are disabled.

I guest the DX output should be in HI-Z by default.

I've be able to test the following code on the Master Primer2 with valid signals
on SPI2_SCK(JP2.7) and SPI2_MOSI(JP2.6) but on the Slave Prima2, the SPI2_MISO(JP2.5) remain quiet.

I connect both Prima2 board with straight wires via the external JP2 connectors:

JP2 Primer2 Master           JP2 Primer2 Slave

              JP2.8        -->              JP2.8                 -->         (AUDIO_I2S2_WS)     
              JP2.7        -->              P2.7                  -->         (AUDIO_I2S2_SCK)   
              JP2.5        -->              JP2.5                 -->         (AUDIO_SPI_MISO)             
              JP2.6        -->              JP2.6                 -->         (AUDIO_I2S2_SD)   

Since both boards have the same 2.8 V level and i'm not sure is the WS pins
is necessary for chips select.
         
Here the soft on the SPI master Primer2, it sends the byte 0X55 at every delay:

  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  /* SPI_BaudRatePrescaler_8  -->  6.5 Mhz    default value    */
  /* SPI_BaudRatePrescaler_16 -->  3.25 Mhz  */
  /* SPI_BaudRatePrescaler_32 -->  1.6 Mhz  */
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI2, &SPI_InitStructure);
 
  /* Enable SPI2 */
  SPI_Cmd(SPI2, ENABLE);

  GPIO_InitTypeDef GPIO_InitStructure;

   /* Configure SPI2 pins: SCK, MISO and MOSI ---------------------------------*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Configure SPI1 pins: SCK, MISO and MOSI ---------------------------------*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);


}
 

  while (1)
  {   
         
         /* Wait for SPI2 Tx buffer empty */
         while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
   
         /* Send SPI2 data */
         SPI_I2S_SendData(SPI2, 0x55);
         Delay(DELAYVAR_SMALLCHANGE);
         
               
   }

}

and the soft on the SPI slave Primer2, it receive the byte 0x55 and resend it
to the masteer Primer2:

u8 ReturnData;

SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  /* SPI_BaudRatePrescaler_8  -->  6.5 Mhz    default value    */
  /* SPI_BaudRatePrescaler_16 -->  3.25 Mhz  */
  /* SPI_BaudRatePrescaler_32 -->  1.6 Mhz  */
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI2, &SPI_InitStructure);
 
  /* Enable SPI2 */
  SPI_Cmd(SPI2, ENABLE);

  GPIO_InitTypeDef GPIO_InitStructure;

   /* Configure SPI2 pins: SCK, MISO and MOSI ---------------------------------*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
 
    while (1)
  {   
 
         /* Wait for SPI2 Rx buffer empty */
         while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
             
         ReturnData = SPI_I2S_ReceiveData( SPI2 );
         
         /* Wait for SPI2 Tx buffer empty */
         while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
   
        /* Send SPI2 data */
         SPI_I2S_SendData(SPI2, ReturnData);
 

   }

}


I don't put the RCC_Configuration() and  NVIC_Configuration() functions.

There something wrong on the Slave side but I can't find the problem.

Best Regards
JM

Offline

 

# 4   2010-04-02 07:09:07 Configuration two Prima2 board for SPI transfer

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Configuration two Prima2 board for SPI transfer

Hi,

You should configure GPIO before enabling SPI.
Did you enabled the clock for both SPI anfd GPIOB peripherals ?
For the second Primer are some lines missing in the configuration of the GPIO  (GPIO_Mode) ?

Yves

Offline

 

Board footer